index.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <template>
  2. <div id="index">
  3. <el-row>
  4. <el-col :span="24" class="main animate__animated animate__backInRight">
  5. <el-col :span="24" class="one"> <span>用户管理</span> </el-col>
  6. <el-col :span="24" class="two">
  7. <data-search :fields="searchFields" v-model="searchInfo" @query="search"> </data-search>
  8. </el-col>
  9. <el-col :span="24" class="four">
  10. <data-table :fields="fields" :opera="opera" @query="search" :data="list" :total="total" @del="toDel"> </data-table>
  11. </el-col>
  12. </el-col>
  13. </el-row>
  14. <e-dialog :dialog="dialog" @toClose="toClose">
  15. <template v-slot:info>
  16. <data-form :span="24" :fields="fieldsForm" :rules="fieldRules" v-model="fieldform" labelWidth="150px" @save="onSubmit"> </data-form>
  17. </template>
  18. </e-dialog>
  19. </div>
  20. </template>
  21. <script>
  22. const _ = require('lodash');
  23. import { mapState, mapGetters, createNamespacedHelpers } from 'vuex';
  24. const { mapActions } = createNamespacedHelpers('users');
  25. const { mapActions: admin } = createNamespacedHelpers('admins');
  26. const { mapActions: dictData } = createNamespacedHelpers('dictData');
  27. export default {
  28. name: 'index',
  29. props: {},
  30. components: {},
  31. data: function () {
  32. const that = this;
  33. return {
  34. // 列表
  35. opera: [{ label: '删除', method: 'del' }],
  36. fields: [
  37. { label: 'openid', model: 'openid' },
  38. { label: '用户姓名', model: 'name' },
  39. { label: '电话', model: 'phone' },
  40. { label: '邮箱', model: 'email' },
  41. { label: '出生年月', model: 'birth' },
  42. {
  43. label: '性别',
  44. model: 'gender',
  45. format: (i) => {
  46. let data = that.genderList.find((f) => f.value == i);
  47. if (data) return data.label;
  48. else return '';
  49. },
  50. },
  51. {
  52. label: '状态',
  53. model: 'status',
  54. format: (i) => {
  55. let data = that.useList.find((f) => f.value == i);
  56. if (data) return data.label;
  57. else return '';
  58. },
  59. },
  60. ],
  61. list: [],
  62. total: 0,
  63. // 查询
  64. searchInfo: {},
  65. searchFields: [{ label: '用户姓名', model: 'name' }],
  66. // 性别
  67. genderList: [],
  68. // 用户状态
  69. useList: [],
  70. // 弹框
  71. dialog: { title: '信息管理', show: false, type: '1' },
  72. fieldform: {},
  73. fieldsForm: [{ label: '密码', model: 'password', type: 'password' }],
  74. fieldRules: { password: [{ required: true, message: '请输入密码', trigger: 'blur' }] },
  75. };
  76. },
  77. async created() {
  78. await this.searchOther();
  79. await this.search();
  80. },
  81. methods: {
  82. ...dictData({ dictQuery: 'query' }),
  83. ...admin({ adminPass: 'pass' }),
  84. ...mapActions(['query', 'delete', 'fetch', 'update', 'create']),
  85. async search({ skip = 0, limit = this.$limit, ...info } = {}) {
  86. let condition = _.cloneDeep(this.searchForm);
  87. let res = await this.query({ skip, limit, ...condition, ...info });
  88. if (this.$checkRes(res)) {
  89. this.$set(this, 'list', res.data);
  90. this.$set(this, 'total', res.total);
  91. }
  92. },
  93. // 修改
  94. async toDel({ data }) {
  95. this.$confirm('是否确认删除,需确认密码', '提示', {
  96. confirmButtonText: '确定',
  97. cancelButtonText: '取消',
  98. type: 'warning',
  99. }).then(async () => {
  100. this.$set(this.fieldform, 'target', data.id);
  101. this.dialog = { title: '信息管理', show: true, type: '1' };
  102. });
  103. },
  104. async onSubmit({ data }) {
  105. let res;
  106. res = await this.adminPass(data);
  107. if (this.$checkRes(res)) {
  108. if (res.errcode == 0) {
  109. this.$confirm('是否确认删除', '提示', {
  110. confirmButtonText: '确定',
  111. cancelButtonText: '取消',
  112. type: 'warning',
  113. }).then(async () => {
  114. let info = {
  115. key: res.data,
  116. target: data.target,
  117. };
  118. res = await this.delete(info);
  119. if (this.$checkRes(res)) {
  120. this.$message({ type: `success`, message: `删除成功` });
  121. this.toClose();
  122. }
  123. });
  124. }
  125. }
  126. },
  127. // 重置
  128. toClose() {
  129. this.fieldform = {};
  130. this.dialog = { title: '信息管理', show: false, type: '1' };
  131. this.search();
  132. },
  133. async searchOther() {
  134. let res;
  135. // 性别
  136. res = await this.dictQuery({ code: 'gender' });
  137. if (this.$checkRes(res)) {
  138. this.$set(this, `genderList`, res.data);
  139. }
  140. // 用户状态
  141. res = await this.dictQuery({ code: 'user_status' });
  142. if (this.$checkRes(res)) {
  143. this.$set(this, `useList`, res.data);
  144. }
  145. },
  146. },
  147. computed: {
  148. ...mapState(['user']),
  149. },
  150. metaInfo() {
  151. return { title: this.$route.meta.title };
  152. },
  153. watch: {
  154. test: {
  155. deep: true,
  156. immediate: true,
  157. handler(val) {},
  158. },
  159. },
  160. };
  161. </script>
  162. <style lang="less" scoped>
  163. .main {
  164. .one {
  165. margin: 0 0 10px 0;
  166. span:nth-child(1) {
  167. font-size: 20px;
  168. font-weight: 700;
  169. margin-right: 10px;
  170. }
  171. }
  172. .two {
  173. margin: 0 0 10px 0;
  174. }
  175. .thr {
  176. margin: 0 0 10px 0;
  177. }
  178. }
  179. </style>