scorpio 2 سال پیش
والد
کامیت
14019e1257
2فایلهای تغییر یافته به همراه132 افزوده شده و 40 حذف شده
  1. 27 0
      src/api/role/index.js
  2. 105 40
      src/views/user/manage.vue

+ 27 - 0
src/api/role/index.js

@@ -1,4 +1,5 @@
 import fetch from '../fetch.js'
+import params from '@/api/params/index.js'
 
 export default {
   /**
@@ -26,6 +27,32 @@ export default {
       'json'
     )
   },
+  /**
+   * 更新用户
+   * @param params
+   * @returns {Promise | Promise<unknown>}
+   */
+  roleUpdate(params) {
+    // 保存用户设置信息
+    return fetch(
+      '/blade-project-manage-v2/roledept/v2/update',
+      params,
+      'post',
+      'json'
+    )
+  },
+  /**
+   * 重置密码
+   * @param params
+   * @returns {Promise | Promise<unknown>}
+   */
+  restPwde(params) {
+    return fetch(
+      '/blade-project-manage-v2/roledept/v2/resetPassword',
+      params,
+      'post'
+    )
+  },
   /**
    * 获取用户机构
    * @param parmas

+ 105 - 40
src/views/user/manage.vue

@@ -9,12 +9,16 @@
       :before-open="beforeOpen"
       @current-change="currentChange"
       @size-change="sizeChange"
+      @refresh-change="refreshChange"
       @on-load="onLoad"
     >
       <template #menu="{ row }">
         <el-button icon="Open" type="primary" text @click="Enable(row)">
           {{ row.clientId.indexOf('project_web') === -1 ? '启用' : '停用' }}
         </el-button>
+        <el-button icon="Refresh" type="primary" text @click="restPwd(row)">
+          重置密码
+        </el-button>
       </template>
       <template #status="{ row }">
         <el-tag
@@ -62,7 +66,7 @@
             </el-form-item>
           </div>
           <div class="flex flex-center">
-            <el-form-item class="full-width" label="手机号码" prop="phone">
+            <el-form-item label="手机号码" class="full-width" prop="phone">
               <el-input
                 v-model="userInfoForm.phone"
                 clearable
@@ -77,8 +81,9 @@
             >
               <el-input
                 v-model="userInfoForm.password"
+                :disabled="form.type !== 'add'"
                 clearable
-                placeholder="输入登陆密码"
+                :placeholder="form.type !== 'add' ? '******' : '输入登陆密码'"
               >
               </el-input>
             </el-form-item>
@@ -162,7 +167,7 @@
 <route>
 {
 name: '用户管理',
-meta: { 'back':true}
+meta: { 'back':true,'showMsg' : "添加用户时,手机号码为必填,用户使用手机号码进行登录;如果手机号为用户微信绑定的手机号时,微信小程序将自动登录,并同步信息!"}
 }
 </route>
 
@@ -170,6 +175,7 @@ meta: { 'back':true}
 import BasicContainer from '@/components/basic-container/main.vue'
 import { useStore } from '@/store/user.js'
 import baseButton from '@/components/base-button.vue'
+import { ElMessageBox } from 'element-plus'
 
 export default {
   name: 'manage',
@@ -200,7 +206,7 @@ export default {
         addBtnText: '添加用户',
         viewBtn: false,
         delBtn: false,
-        refreshBtn: false,
+        refreshBtn: true,
         columnBtn: false,
         labelWidth: 140,
         border: true,
@@ -267,7 +273,7 @@ export default {
         ],
         password: [
           { required: true, message: '请输入密码', trigger: 'blur' },
-          { min: 3, max: 16, message: '长度在 3 到 16 个字符', trigger: 'blur' }
+          { min: 6, max: 16, message: '长度在 6 到 16 个字符', trigger: 'blur' }
         ]
       }
     }
@@ -279,7 +285,10 @@ export default {
   methods: {
     onLoad() {
       this.loading = true
+      this.page.current = this.page.currentPage
+      this.page.size = this.page.pageSize
       const data = { deptId: this.user.info.deptId }
+      console.log(this.page)
       this.$api.role
         .roleList(Object.assign(this.page, data))
         .then(res => {
@@ -317,47 +326,71 @@ export default {
       })
     },
     beforeOpen(done, type) {
-      if (this.form.clientId.indexOf('project_web') === -1) {
-        this.$message.error('该账号已经停用,无需进行编辑!')
-        return
-      }
+      this.form.type = type
       if (type === 'edit') {
-        this.userInfoForm.name = this.form.name
-        this.userInfoForm.realName = this.form.realName
-        this.userInfoForm.phone = this.form.phone
-        this.userInfoForm.password = this.form.password
-        this.userInfoForm.deptId = this.form.deptId
-        this.jobs.find(e => {
-          const temp = this.form.roleId.split(',').find(sub => sub === e.id)
-          if (temp) {
-            this.userInfoForm.roleIds = temp
-          }
-          return temp
-        })
-        this.$api.role.managerList({ userId: this.form.id }).then(res => {
-          if (res.code === 200) {
-            res.data.forEach(ele => {
-              const tmp = this.deptList.findIndex(sub => sub.id === ele.deptId)
-              if (tmp > -1) {
-                this.deptList[tmp].checked = true
-              }
-              this.userInfoForm.deptIds = this.deptList.map(e => e.id)
-            })
-            this.showEdit = true
-          }
-        })
+        this.rowEdit()
       } else if (type === 'add') {
+        this.userInfoForm = {
+          name: '',
+          realName: '',
+          phone: '',
+          password: '',
+          roleIds: '',
+          deptIds: [],
+          deptId: ''
+        }
+        this.deptList.map(e => (e.checked = false))
         this.showEdit = true
       } else {
         done()
       }
     },
+    rowEdit() {
+      if (this.form.clientId.indexOf('project_web') === -1) {
+        this.$message.error('该账号已经停用,无需进行编辑!')
+        return
+      }
+      this.userInfoForm.name = this.form.name
+      this.userInfoForm.realName = this.form.realName
+      this.userInfoForm.phone = this.form.phone
+      this.userInfoForm.password = this.form.password
+      this.userInfoForm.deptId = this.form.deptId
+      this.jobs.find(e => {
+        const temp = this.form.roleId.split(',').find(sub => sub === e.id)
+        if (temp) {
+          this.userInfoForm.roleIds = temp
+        }
+        return temp
+      })
+      this.$api.role.managerList({ userId: this.form.id }).then(res => {
+        if (res.code === 200) {
+          res.data.forEach(ele => {
+            const tmp = this.deptList.findIndex(sub => sub.id === ele.deptId)
+            if (tmp > -1) {
+              this.deptList[tmp].checked = true
+            }
+            this.userInfoForm.deptIds = this.deptList.map(e => e.id)
+          })
+          if (
+            this.deptList.filter(e => e.checked).length === this.deptList.length
+          ) {
+            this.checkAll = true
+          } else {
+            this.checkAll = false
+          }
+          this.showEdit = true
+        }
+      })
+    },
     currentChange(currentPage) {
       this.page.current = currentPage
     },
     sizeChange(pageSize) {
       this.page.size = pageSize
     },
+    refreshChange() {
+      this.onLoad()
+    },
     getJobList() {
       this.$api.role.jobList({ roleAlias: 'post' }).then(res => {
         if (res.code === 200) {
@@ -413,14 +446,46 @@ export default {
       } else {
         data.deptIds = this.form.deptId
       }
-      this.$api.role.roleSave(data).then(res => {
-        if (res.code === 200) {
-          this.showEdit = false
-          this.$message.success(res.msg)
-          this.onLoad()
-        } else {
-          this.$message.error(res.msg)
+      data.isUpdate = false
+      if (this.form.id) {
+        data.userId = this.form.id
+        this.$api.role.roleUpdate(data).then(res => {
+          if (res.code === 200) {
+            this.showEdit = false
+            this.$message.success(res.msg)
+            this.onLoad()
+          } else {
+            this.$message.error(res.msg)
+          }
+        })
+      } else {
+        this.$api.role.roleSave(data).then(res => {
+          if (res.code === 200) {
+            this.showEdit = false
+            this.$message.success(res.msg)
+            this.onLoad()
+          } else {
+            this.$message.error(res.msg)
+          }
+        })
+      }
+    },
+    restPwd(row) {
+      console.log(row)
+      ElMessageBox.prompt('', '更改 (' + row.name + ') 的密码', {
+        inputPattern: /\w{6,16}/,
+        inputErrorMessage: '密码长度在 6 到 16 个字符'
+      }).then(({ value }) => {
+        if (value.length === 0) {
+          return
         }
+        this.$api.role
+          .restPwde({ userId: row.id, password: value })
+          .then(res => {
+            if (res.code === 200) {
+              console.log(res)
+            }
+          })
       })
     }
   }