account-manage.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. <template>
  2. <div class="account" v-loading="loading">
  3. <Header :title="title"></Header>
  4. <div class="container">
  5. <div class="content">
  6. <div class="tip-father">
  7. <el-button
  8. type="primary"
  9. size="small"
  10. class="btn"
  11. @click.native="addAccount()"
  12. >添加成员</el-button
  13. >
  14. <span class="tip"
  15. >一号用户(即ID为1的用户)和所属组为“管理员”的组,不需要分配权限即拥有所有菜单权限!</span
  16. >
  17. </div>
  18. <div class="screen">
  19. <p>状态:</p>
  20. <el-select v-model="filter.status" placeholder="全部" size="mini">
  21. <el-option label="启用" value="0"></el-option>
  22. <el-option label="禁用" value="1"></el-option>
  23. </el-select>
  24. <el-button type="primary" class="btn" size="mini" @click="search()"
  25. >筛选</el-button
  26. >
  27. <el-button
  28. type="primary"
  29. class="btn"
  30. size="mini"
  31. @click.native="clearFilter()"
  32. >重置</el-button
  33. >
  34. </div>
  35. <el-table
  36. :data="accountList"
  37. class="order-table table no-border-table"
  38. ref="orderTable"
  39. :header-cell-style="{
  40. border: 'none',
  41. color: '#333',
  42. background: '#f6f6f6',
  43. borderBottom: '1px solid #E8E8E8',
  44. height: '54px',
  45. }"
  46. :row-style="{
  47. height: '54px',
  48. }"
  49. >
  50. <!-- <el-table-column type="selection" width="40"> </el-table-column> -->
  51. <el-table-column prop="nickname" label="昵称"> </el-table-column>
  52. <el-table-column prop="username" label="账号"> </el-table-column>
  53. <el-table-column prop="uid" label="用户ID"> </el-table-column>
  54. <el-table-column prop="phone" label="手机号"> </el-table-column>
  55. <el-table-column
  56. prop="method"
  57. label="操作"
  58. width="350px"
  59. align="center"
  60. >
  61. <template slot-scope="scope">
  62. <el-button size="mini" @click="editpassword(scope.row)"
  63. >修改密码
  64. </el-button>
  65. <el-button size="mini" @click="powerGroup(scope.row.uid)"
  66. >权限组
  67. </el-button>
  68. <el-button size="mini" @click="editAccount(scope.row)"
  69. >编辑
  70. </el-button>
  71. <el-button size="mini" @click="banAccount(scope.row)"
  72. >{{ scope.row.status | isBan }}
  73. </el-button>
  74. </template>
  75. </el-table-column>
  76. </el-table>
  77. <div class="footer">
  78. <div></div>
  79. <el-pagination
  80. @current-change="PageChange"
  81. :current-page.sync="currentPage"
  82. layout="total, prev, pager, next, jumper"
  83. :page-size="size"
  84. :total="totalSize"
  85. background
  86. >
  87. </el-pagination>
  88. </div>
  89. </div>
  90. </div>
  91. <el-dialog
  92. title="管理员信息"
  93. width="400px"
  94. class="addAccount"
  95. :visible.sync="addShow"
  96. >
  97. <el-form :model="addForm" ref="addForm" size="mini" :rules="userRules">
  98. <el-form-item
  99. label="昵称"
  100. prop="nickname"
  101. :label-width="formLabelWidth"
  102. >
  103. <el-input v-model="addForm.nickname" />
  104. </el-form-item>
  105. <el-form-item
  106. label="账号"
  107. prop="username"
  108. :label-width="formLabelWidth"
  109. >
  110. <el-input v-model="addForm.username" />
  111. </el-form-item>
  112. <el-form-item label="手机号" prop="phone" :label-width="formLabelWidth">
  113. <el-input v-model="addForm.phone" type="number" />
  114. </el-form-item>
  115. <el-form-item
  116. label="密码"
  117. prop="password"
  118. :label-width="formLabelWidth"
  119. v-if="this.flag == 'add'"
  120. >
  121. <el-input v-model="addForm.password" type="password" />
  122. </el-form-item>
  123. <el-form-item label="描述" :label-width="formLabelWidth">
  124. <el-input v-model="addForm.description" />
  125. </el-form-item>
  126. </el-form>
  127. <div slot="footer" class="dialog-footer">
  128. <el-button @click="addShow = false" class="cancel-btn">取 消</el-button>
  129. <el-button type="primary" @click.native="submitManager()" class="confirm-btn"
  130. >确 定</el-button
  131. >
  132. </div>
  133. </el-dialog>
  134. <el-dialog title="选择权限组" width="800px" :visible.sync="powerShow">
  135. <template>新增权限组:</template>
  136. <el-input placeholder="请输入权限组名称" v-model="addPower" size="mini" />
  137. <el-checkbox-group v-model="powerSelect">
  138. <el-checkbox
  139. v-for="(item, index) in powerList"
  140. :key="index"
  141. :label="item"
  142. >{{ item }}
  143. </el-checkbox>
  144. </el-checkbox-group>
  145. <div slot="footer" class="dialog-footer">
  146. <el-button class="cancel-btn" @click="powerShow = false">取 消</el-button>
  147. <el-button class="confirm-btn" type="primary" @click="submitPower()">确 定</el-button>
  148. </div>
  149. </el-dialog>
  150. <el-dialog title="修改密码" width="400px" :visible.sync="passwordShow">
  151. <el-form :model="addFather" :rules="rules" ref="addFather">
  152. <el-form-item
  153. label="新密码:"
  154. prop="password"
  155. :label-width="formLabelWidth"
  156. >
  157. <el-input
  158. v-model="addFather.password"
  159. placeholder="请输入新密码"
  160. type="password"
  161. />
  162. </el-form-item>
  163. </el-form>
  164. <div slot="footer" class="dialog-footer">
  165. <el-button class="cancel-btn" @click="passwordShow = false">取 消</el-button>
  166. <el-button class="confirm-btn" type="primary" @click="submitPassword()">确 定</el-button>
  167. </div>
  168. </el-dialog>
  169. </div>
  170. </template>
  171. <script type="text/ecmascript-6">
  172. import Header from '../../components/common/header';
  173. export default {
  174. components: {
  175. Header
  176. },
  177. name: 'account',
  178. data: function () {
  179. return {
  180. title: {
  181. // 页面标题
  182. firstTitile: '基础设置',
  183. secondTitle: '账号管理'
  184. },
  185. accountList: [], // 管理员账号列表
  186. editId: '', // 编辑的哪个管理员账号
  187. addShow: false, // 添加成员弹窗显示
  188. powerShow: false, // 选择权限弹窗显示
  189. passwordShow: false, // 修改密码弹窗显示
  190. flag: '', // 编辑还是添加管理员
  191. addForm: {
  192. nickname: '',
  193. username: '',
  194. phone: '',
  195. password: '',
  196. description: ''
  197. }, // 添加成员
  198. addFather: {
  199. password: ''
  200. }, // 修改密码
  201. powerSelect: [], // 权限组选择项
  202. addPower: '', // 新增权限组的名称
  203. powerSelectCopy: [], // 权限组选择项(用于判断新增、删除数据)
  204. powerList: [], // 权限组列表
  205. loading: false, // 加载
  206. filter: {
  207. status: ''
  208. }, // 搜索筛选
  209. rules: {
  210. password: [
  211. { required: true, message: '请输入新密码', trigger: 'blur' }
  212. ]
  213. },
  214. userRules: {
  215. phone: [
  216. { required: true, message: '请输入手机号', trigger: 'blur' },
  217. { min: 11, max: 11, message: '手机号长度错误', trigger: 'blur' }
  218. ],
  219. username: [
  220. { required: true, message: '请输入账号', trigger: 'blur' }
  221. // { min: 5, max: 20, message: '请输入5~20位字母数字组合', trigger: 'blur' }
  222. ],
  223. nickname: [
  224. { required: true, message: '请输入姓名', trigger: 'blur' },
  225. { min: 6, message: '昵称最少6位', trigger: 'blur' }
  226. ],
  227. password: [{ required: true, message: '请输入密码', trigger: 'blur' }]
  228. }, // 管理员信息校验
  229. currentPage: 1, // 当前页
  230. size: 20, // 一页多少数据
  231. totalSize: 0, // 共多少条数据
  232. formLabelWidth: '80px'
  233. };
  234. },
  235. filters: {
  236. isBan(val) {
  237. if (val === 1) {
  238. return '启用';
  239. } else {
  240. return '禁止';
  241. }
  242. }
  243. },
  244. mounted() {
  245. this.getManagerList();
  246. },
  247. methods: {
  248. // 筛选
  249. search() {
  250. this.currentPage = 1;
  251. this.getManagerList();
  252. },
  253. getManagerList() {
  254. let data = {
  255. page_size: this.size,
  256. page: this.currentPage,
  257. status: +this.filter.status
  258. };
  259. // status数据类型为num,为空的话传0 ,影响数据所以删掉
  260. if (this.filter.status === '') {
  261. delete data.status;
  262. }
  263. this.httpGet(this.$root.managerList, data).then(
  264. (res) => {
  265. this.accountList = res.list;
  266. this.totalSize = res.total;
  267. this.loading = false;
  268. },
  269. (res) => {
  270. this.$message.error(res);
  271. this.loading = false;
  272. }
  273. );
  274. },
  275. // 添加成员
  276. addAccount() {
  277. this.flag = 'add';
  278. this.addForm = {
  279. nickname: '',
  280. username: '',
  281. phone: '',
  282. password: '',
  283. description: ''
  284. };
  285. this.addShow = true;
  286. // 第二次之后点击清空弹窗校验信息
  287. // setTimeout(() => {
  288. // this.$refs.addForm.clearValidate();
  289. // }, 10);
  290. },
  291. // 提交管理员信息
  292. submitManager() {
  293. this.$refs.addForm.validate((valid) => {
  294. if (!valid) {
  295. this.$message.error('请输入必填信息!');
  296. return false;
  297. } else {
  298. // 新增管理员信息
  299. if (this.flag === 'add') {
  300. let data = {
  301. ...this.addForm
  302. };
  303. this.httpPost(this.$root.addManager, data).then(
  304. (res) => {
  305. this.$message.success('添加成功!');
  306. this.addShow = false;
  307. this.getManagerList();
  308. },
  309. (res) => {
  310. this.$message.error(res);
  311. this.loading = false;
  312. }
  313. );
  314. } else {
  315. // 编辑管理员信息 flag == 'edit'
  316. let data = {
  317. uid: +this.editId,
  318. ...this.addForm
  319. };
  320. this.httpPost(this.$root.editManager, data).then(
  321. (res) => {
  322. this.$message.success('操作成功!');
  323. this.addShow = false;
  324. this.getManagerList();
  325. },
  326. (res) => {
  327. this.$message.error(res);
  328. this.loading = false;
  329. }
  330. );
  331. }
  332. }
  333. });
  334. },
  335. // 编辑密码弹窗
  336. editpassword(scope) {
  337. this.passwordShow = true;
  338. this.addFather.password = '';
  339. this.editId = scope.uid;
  340. },
  341. // 提交修改密码信息
  342. submitPassword() {
  343. this.$refs.addFather.validate((valid) => {
  344. if (!valid) {
  345. this.$message.error('请输入必填信息!');
  346. return false;
  347. } else {
  348. let data = {
  349. uid: +this.editId,
  350. password: this.addFather.password
  351. };
  352. this.httpPost(this.$root.editPassword, data).then(
  353. (res) => {
  354. this.$message.success('操作成功!');
  355. this.passwordShow = false;
  356. },
  357. (res) => {
  358. this.$message.error(res);
  359. this.loading = false;
  360. }
  361. );
  362. }
  363. });
  364. },
  365. // 编辑管理员信息弹窗
  366. editAccount(scope) {
  367. this.flag = 'edit';
  368. this.editId = scope.uid;
  369. this.addForm = {
  370. nickname: scope.nickname,
  371. username: scope.username,
  372. phone: scope.phone,
  373. description: scope.description
  374. };
  375. this.addShow = true;
  376. },
  377. // 编辑权限组信息弹窗
  378. powerGroup(scope) {
  379. this.powerShow = true;
  380. this.editId = scope;
  381. // 获取权限组列表
  382. this.httpGet(this.$root.powerGroupList).then(
  383. (res) => {
  384. this.powerList = res.list;
  385. console.log(123, this.powerSelect);
  386. },
  387. (res) => {
  388. this.$message.error(res);
  389. this.loading = false;
  390. }
  391. );
  392. // 获得已选权限组
  393. this.httpGet(this.$root.choiceManagerGroup, { uid: +scope }).then(
  394. (res) => {
  395. this.powerSelect = res.list;
  396. this.powerSelectCopy = res.list;
  397. },
  398. (res) => {
  399. this.$message.error(res);
  400. this.loading = false;
  401. }
  402. );
  403. },
  404. // 提交权限组信息
  405. submitPower(scope) {
  406. // 创建set对象
  407. let olderArr = new Set(this.powerSelectCopy);
  408. let newArr = new Set(this.powerSelect);
  409. // 合并老数组与新数组 并去重
  410. let countArr = [...new Set([...olderArr, ...newArr])];
  411. // 新数组与总数组差集=>删除的数组
  412. let deleteArr = countArr.filter((x) => !newArr.has(x));
  413. // 老数组与总数组差集=>新增的数组
  414. let addArr = countArr.filter((x) => !olderArr.has(x));
  415. let data = {
  416. uid: +this.editId,
  417. add: addArr,
  418. delete: deleteArr
  419. };
  420. // 新增权限组
  421. if (this.addPower !== '') {
  422. data.add.push(this.addPower);
  423. }
  424. this.httpPost(this.$root.editManagerGroup, data).then(
  425. (res) => {
  426. this.$message.success('操作成功!');
  427. this.powerShow = false;
  428. this.getManagerList();
  429. },
  430. (res) => {
  431. this.$message.error(res);
  432. this.loading = false;
  433. }
  434. );
  435. },
  436. // 禁用、启用管理员账号
  437. banAccount(scope) {
  438. console.log(scope);
  439. let data = {
  440. uid: +scope.uid,
  441. status: scope.status === 1 ? 0 : 1
  442. };
  443. this.httpPost(this.$root.editManagerStatus, data).then(
  444. (res) => {
  445. this.$message.success('操作成功!');
  446. this.getManagerList();
  447. // 处理先筛选状态,再修改账号状态列表与状态筛选框不一致的情况
  448. this.filter = {
  449. status: ''
  450. };
  451. },
  452. (res) => {
  453. this.$message.error(res);
  454. }
  455. );
  456. },
  457. // 清空筛选条件,重新拉list接口
  458. clearFilter() {
  459. this.filter = {
  460. status: ''
  461. }; // 筛选条件
  462. this.currentPage = 1;
  463. this.getManagerList();
  464. },
  465. // 分页
  466. PageChange(val) {
  467. // 获取当页数据
  468. this.currentPage = val;
  469. this.getManagerList();
  470. }
  471. }
  472. };
  473. </script>
  474. <style lang="stylus" rel="stylesheet/stylus">
  475. @import '~assets/public.styl';
  476. </style>
  477. <style lang="stylus" rel="stylesheet/stylus" scoped>
  478. @import '~assets/main.styl';
  479. .el-dialog__wrapper .el-input {
  480. width: 240px !important;
  481. }
  482. // >>>.el-form-item__error{
  483. // margin-left :75px;
  484. // }
  485. .account {
  486. height: 100%;
  487. width: 100%;
  488. flex-y(flex-start, flex-start);
  489. overflow-y: hidden;
  490. background: bg-color;
  491. }
  492. .container {
  493. box-sizing: border-box;
  494. height: 100%;
  495. width: 100%;
  496. overflow-y: auto;
  497. flex-y(flex-start, flex-start);
  498. padding: 0 24px 24px;
  499. // content 表格
  500. .content {
  501. flex: 1;
  502. width: 100%;
  503. font-size: 14px;
  504. background: white;
  505. box-sizing: border-box;
  506. padding: 24px;
  507. border-radius: 2px;
  508. .screen {
  509. width: calc(100% - 30px);
  510. background: bk;
  511. padding: margin10;
  512. flex-x(flex-start);
  513. margin-top: margin10;
  514. .el-select {
  515. margin-right: 10px;
  516. width: input100;
  517. }
  518. .el-input {
  519. width: input150;
  520. margin: 0 margin10;
  521. }
  522. p {
  523. word(14px, gray6);
  524. }
  525. }
  526. .el-table {
  527. width: calc(100% - 10px) !important;
  528. margin-top: 10px;
  529. font-size: 12px;
  530. border();
  531. p {
  532. float: left;
  533. }
  534. img {
  535. width: 60px;
  536. height: 60px;
  537. }
  538. .el-icon-star-on {
  539. color: yellow;
  540. }
  541. .highLight {
  542. color: blue;
  543. font-size: 14px;
  544. cursor: pointer;
  545. }
  546. }
  547. .footer {
  548. width: calc(100% - 30px);
  549. min-width: 600px;
  550. padding: 10px 0 0 15px;
  551. flex-x();
  552. .el-button {
  553. margin-left: 10px;
  554. }
  555. }
  556. }
  557. .btn {
  558. confirm-btn();
  559. }
  560. }
  561. .account >>>.addAccount .el-dialog .el-checkbox {
  562. width: 20px;
  563. }
  564. .tip {
  565. margin: 8px 0 0 20px;
  566. font-size: 12px;
  567. color: red;
  568. }
  569. .confirm-btn{
  570. confirm-btn();
  571. width: 65px;
  572. height: 32px;
  573. padding: 0;
  574. }
  575. .cancel-btn{
  576. cancel-btn();
  577. width: 65px;
  578. height: 32px;
  579. padding: 0;
  580. }
  581. </style>