index.vue 5.4 KB

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