From 4822994d2d6d524f0a08336dd610dc5366d28061 Mon Sep 17 00:00:00 2001
From: yujialong <479214531@qq.com>
Date: Thu, 24 Mar 2022 18:19:50 +0800
Subject: [PATCH] =?UTF-8?q?=E5=90=8E=E5=8F=B0=E8=B4=A6=E5=8F=B7=E8=81=94?=
=?UTF-8?q?=E8=B0=83?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/utils/api.js | 3 +
src/views/system/staff.vue | 536 ++++++++++++++++---------------------
2 files changed, 238 insertions(+), 301 deletions(-)
diff --git a/src/utils/api.js b/src/utils/api.js
index c7e7354..cc168d8 100644
--- a/src/utils/api.js
+++ b/src/utils/api.js
@@ -10,6 +10,9 @@ export default {
bindPhoneOrEmail: `users/users/userAccount/bindPhoneOrEmail`,// 绑定手机
sendPhoneOrEmailCode: `users/users/userAccount/sendPhoneOrEmailCode`,// 手机验证码
+ checkEmailOrPhone: `occupationlab/architecture/checkEmailOrPhone`, // 新增学生前:校验手机号或者邮箱
+ checkWorkNumOrAccount: `occupationlab/architecture/checkWorkNumOrAccount`, // 新增/编辑学生前:校验学号或者学生账号
+
// 订单管理
orderAdd: `nakadai/nakadai/order/add`,// 订单添加
orderDelete: `nakadai/nakadai/order/delete`,// 删除定单
diff --git a/src/views/system/staff.vue b/src/views/system/staff.vue
index 56e9a9b..e958dd4 100644
--- a/src/views/system/staff.vue
+++ b/src/views/system/staff.vue
@@ -103,15 +103,13 @@
-
-
-
- 员工
-
+
+
+
- 查看
- 编辑
+ 查看
+ 编辑
重置密码
删除
@@ -121,7 +119,7 @@
-
+
@@ -133,13 +131,13 @@
-
+
-
+
-
-
+
+
-
+
@@ -206,33 +204,58 @@ import OrgTree from "@/components/org-tree/src/tree";
export default {
components: { OrgTree },
data() {
- var accountPass = (rule, value, callback) => {
- if (value === '') {
- callback(new Error('请输入账号'));
- } else {
- var pattern = /^[A-Za-z0-9]*$/;
- if(pattern.test(value)){
- this.accountChange();
- callback();
- }else{
- callback(new Error('请输入正确账号格式'));
- }
+ const accountPass = (rule, value, callback) => {
+ if (value === '') {
+ callback(new Error('请输入账号'))
+ } else {
+ const pattern = /^[A-Za-z0-9]*$/
+ if(pattern.test(value)){
+ this.accountChange()
+ callback()
+ }else{
+ callback(new Error('请输入正确账号格式'))
}
- };
- var workNumberPass = (rule, value, callback) => {
- if (value === '') {
- callback(new Error('请输入员工学号'));
- } else {
- var pattern = /^[A-Za-z0-9]*$/;
- if(pattern.test(value)){
- this.worknumberChange();
- callback();
- }else{
- callback(new Error('请输入正确员工学号格式'));
- }
+ }
+ }
+ const workNumberPass = (rule, value, callback) => {
+ if (value === '') {
+ callback(new Error('请输入工号'))
+ } else {
+ const pattern = /^[A-Za-z0-9]*$/
+ if(pattern.test(value)){
+ this.worknumberChange()
+ callback()
+ }else{
+ callback(new Error('请输入正确工号格式'))
}
- };
- let that = this;
+ }
+ }
+ const phonePass = (rule, value, callback) => {
+ if (value) {
+ const pattern = /^1[3456789]\d{9}$/
+ if(pattern.test(value)){
+ this.phoneChange()
+ callback()
+ }else{
+ callback(new Error('请输入正确手机号格式'))
+ }
+ } else {
+ callback()
+ }
+ }
+ const emailPass = (rule, value, callback) => {
+ if (value) {
+ const pattern = /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/
+ if(pattern.test(value)){
+ this.emailChange()
+ callback()
+ }else{
+ callback(new Error('请输入正确邮箱格式'))
+ }
+ } else {
+ callback()
+ }
+ }
return {
orgList: [],
orgListDia: [],
@@ -262,34 +285,27 @@ export default {
uniqueIdentification: '',
workNumber: '',
email: '',
- account: ''
+ account: '',
+ staffArchitectureId: []
},
rules: {
- organizationName: [
- { required: true, message: "请输入名称", trigger: "blur" }
- ],
account: [
- { required: true,validator: accountPass, trigger: 'blur' }
+ { required: true,validator: accountPass, trigger: 'blur' }
],
userName: [
- { required: true, message: "请输入姓名", trigger: "blur" }
+ { required: true, message: "请输入姓名", trigger: "blur" }
],
workNumber: [
- { required: true,validator: workNumberPass, trigger: 'blur' }
+ { required: true,validator: workNumberPass, trigger: 'blur' }
+ ],
+ roleList: [
+ { required: true, message: "请选择授权角色", trigger: "change" }
],
phone: [
- {
- pattern: /^1[3456789]\d{9}$/,
- message: "请输入正确的手机号",
- trigger: "blur"
- }
+ { validator: phonePass, trigger: 'blur' }
],
email: [
- {
- pattern: /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/,
- message: "请输入正确的邮箱",
- trigger: "blur"
- }
+ { validator: emailPass, trigger: 'blur' }
]
},
listData: [],
@@ -305,7 +321,6 @@ export default {
originWorkNumber: '',
phoneRepeat: false,
emailRepeat: false,
- defaultCheckedKeys: [],
casProps: {
multiple: true,
checkStrictly: true,
@@ -325,10 +340,10 @@ export default {
};
},
watch: {
- keyWord: function(val) {
- clearTimeout(this.searchTimer);
- this.searchTimer = setTimeout(this.getStaff, 500);
- }
+ keyWord: function(val) {
+ clearTimeout(this.searchTimer);
+ this.searchTimer = setTimeout(this.getStaff, 500);
+ }
},
mounted() {
this.getOrg()
@@ -445,17 +460,16 @@ export default {
},
// 员工列表
getStaff() {
- let data = {
- type: this.studentType || '',
- staffArchitectureId: this.$refs.orgTree.getCurrentKey() || '',
- keyWord: this.keyWord,
- pageNum: this.page,
- pageSize: this.pageSize
- };
- this.$post(this.api.staffList, data).then(res => {
- this.listData = res.records
- this.total = res.total
- }).catch(err => {})
+ this.$post(this.api.staffList, {
+ type: this.studentType || 1,
+ staffArchitectureId: this.$refs.orgTree.getCurrentKey() || '',
+ keyWord: this.keyWord,
+ pageNum: this.page,
+ pageSize: this.pageSize
+ }).then(res => {
+ this.listData = res.page.records
+ this.total = res.page.total
+ }).catch(err => {})
},
// 切换页码
currentChange(val) {
@@ -466,41 +480,40 @@ export default {
this.multipleSelection = val
},
initData() {
- this.$refs.table.clearSelection()
- this.page = 1
- this.getStaff()
+ this.$refs.table.clearSelection()
+ this.page = 1
+ this.getStaff()
},
// 删除
delStaff(row) {
- this.$confirm("确定要删除吗?", "提示", {
- type: "warning"
- }).then(() => {
- this.$post(`${this.api.delStaff}?accountIds=${row.accountId}`).then(res => {
- util.successMsg("删除成功")
- this.getStaff()
- }).catch(res => {
- });
- }).catch(() => {})
- },
- resetPassword(row) { // 重置密码
- this.$confirm(`重置后的密码为:${Setting.initialPassword},确定重置?`, "提示", { type: "warning" }).then(() => {
- this.$get(`${this.api.resetPassword}?userId=${row.userId}&newPwd=111aaa`).then(res => {
- util.successMsg("重置成功");
- }).catch(res => {
- });
- }).catch(() => {
- });
+ this.$confirm("确定要删除吗?", "提示", {
+ type: "warning"
+ }).then(() => {
+ this.$post(`${this.api.delStaff}?accountIds=${row.accountId}`).then(res => {
+ util.successMsg("删除成功")
+ this.getStaff()
+ }).catch(res => {})
+ }).catch(() => {})
+ },
+ // 重置密码
+ resetPassword(row) {
+ this.$confirm(`重置后的密码为:${Setting.initialPassword},确定重置?`, "提示", { type: "warning" }).then(() => {
+ this.$get(`${this.api.resetPassword}?userId=${row.userId}&newPwd=111aaa`).then(res => {
+ util.successMsg("重置成功")
+ }).catch(res => {})
+ }).catch(() => {})
},
// 添加员工
addStaff() {
this.staffVisible = true
},
// 编辑/查看
- editStaff(row, isDetail) {
+ queryStaff(row, isDetail) {
this.isDetail = isDetail
this.staffVisible = true
- this.$post(`${this.api.staffDetail}?accountId=${row.accountId}`).then(res => {
+ this.$get(`${this.api.staffDetail}?accountId=${row.accountId}`).then(res => {
const { data } = res
+ data.staffArchitectureId = data.staffArchitectureId.split(',')
this.form = data
this.originAccount = data.account
this.originWorkNumber = data.workNumber
@@ -513,189 +526,107 @@ export default {
this.roleList = res.rolePage.records
}).catch(res => {})
},
- // 处理切换角色
- roleChange(value) {
- if (value.length) {
- let ids = this.form.roleAndDeptList.map(e => e.roleId);
- this.roleList.forEach(i => {
- let obj = {
- roleId: "",
- roleName: "",
- cascaderValue: []
- };
- if (value.includes(i.id) && !ids.includes(i.id)) {
- console.log(i)
- obj.roleId = i.id;
- obj.roleName = i.roleName;
- this.form.roleAndDeptList.push(obj);
- }
- });
- } else {
- this.form.roleAndDeptList.splice(0);
- }
- },
- roleRemove(value) { // 处理移除角色
- let list = [];
- for(var i=0;i {
- this.disableds = false
- if (this.form.accountId) {
- this.$refs.form.clearValidate();
- this.form = {
- account: this.form.account,
- userName: '',
- phone: '',
- uniqueIdentification: '',
- workNumber: '',
- email: '',
- classId: ""
- };
- this.$refs.classTree.setCheckedKeys([]);
- } else {
- this.$refs.form.clearValidate();
- }
- this.accountReapeat = false;
- }).catch(err => {
-
- if (this.form.accountId) {
- } else {
- this.accountReapeat = true;
- }
- });
- }
+ // 账号判重
+ accountChange() {
+ const form = this.form
+ const { account } = form
+ if (account === this.originAccount) {
+ this.accountReapeat = false
+ } else {
+ const { accountId } = form
+ this.$post(`${this.api.checkWorkNumOrAccount}?platformId=${Setting.platformId}&type=2&account=${account}${accountId ? `&accountId=${accountId}` : ''}`).then(res => {
+ this.accountReapeat = false
+ }).catch(err => {
+ this.accountReapeat = true
+ })
+ }
},
+ // 工号判重
worknumberChange() {
- if (this.form.workNumber) {
- let url = "";
- if (!this.form.accountId) {
- url = `${this.api.checkWorkNumOrAccount}?platformId=${Setting.platformId}&type=1&workNumber=${this.form.workNumber}&account=`;
- } else {
- url = `${this.api.checkWorkNumOrAccount}?platformId=${Setting.platformId}&type=1&accountId=${this.form.accountId}&workNumber=${this.form.workNumber}&account=`;
- }
- this.$post(url).then(res => {
- if (res.status === 200) {
- this.workNumberReapeat = false;
- }
- }).catch(err => {
- this.$post(`${this.api.getDetailByAccount}?workNumber=${this.form.workNumber}&platformId=${Setting.platformId}&type=1`).then(res => {
- let classId = res.data.classList.map(e => e.id);
- this.form.classId = classId.toString();
- delete this.form.classList;
- this.accountReapeat = false;
- this.$refs.form.clearValidate();
- }).catch(res => {});
- this.workNumberReapeat = true;
- });
- }
+ const form = this.form
+ const { workNumber } = form
+ if (workNumber === this.originWorkNumber) {
+ this.workNumberReapeat = false
+ } else {
+ const { accountId } = form
+ this.$post(`${this.api.checkWorkNumOrAccount}?platformId=${Setting.platformId}&type=2&workNumber=${workNumber}${accountId ? `&accountId=${accountId}` : ''}`).then(res => {
+ this.workNumberReapeat = false
+ }).catch(err => {
+ this.workNumberReapeat = true
+ })
+ }
},
+ // 手机号判重
phoneChange() {
- let regex = /^1[3456789]\d{9}$/;
- if (regex.test(this.form.phone)) {
- let url = "";
- if (!this.form.accountId) {
- url = `${this.api.checkEmailOrPhone}?phone=${this.form.phone}&email=`;
- } else {
- url = `${this.api.checkEmailOrPhone}?accountId=${this.form.accountId}&phone=${this.form.phone}&email=`;
- }
- this.$post(url).then(res => {
- if (res.status === 200) {
- this.phoneRepeat = false;
- }
- }).catch(err => {
- this.phoneRepeat = true;
- });
- }
+ const form = this.form
+ const { phone } = form
+ if (phone) {
+ const { accountId } = form
+ this.$post(`${this.api.checkEmailOrPhone}?phone=${phone}${accountId ? `&accountId=${accountId}` : ''}`).then(res => {
+ this.phoneRepeat = false
+ }).catch(err => {
+ this.phoneRepeat = true
+ })
+ }
},
+ // 邮箱判重
emailChange() {
- let regex = /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/;
- if (regex.test(this.form.email)) {
- let url = "";
- if (!this.form.accountId) {
- url = `${this.api.checkEmailOrPhone}?email=${this.form.email}&phone=`;
- } else {
- url = `${this.api.checkEmailOrPhone}?accountId=${this.form.accountId}&email=${this.form.email}&phone=`;
- }
- this.$post(url).then(res => {
- if (res.status === 200) {
- this.emailRepeat = false;
- }
- }).catch(err => {
- this.emailRepeat = true;
- });
- }
+ const form = this.form
+ const { email } = form
+ if (email) {
+ const { accountId } = form
+ this.$post(`${this.api.checkEmailOrPhone}?email=${email}${accountId ? `&accountId=${accountId}` : ''}`).then(res => {
+ this.emailRepeat = false
+ }).catch(err => {
+ this.emailRepeat = true
+ })
+ }
},
// 提交新增/编辑员工
submitStaff() {
- this.$refs.form.validate((valid) => {
- if (valid) {
- if (this.submiting) return false
- if (this.accountReapeat) return util.warningMsg("该账号已存在")
- if (this.workNumberReapeat) return util.warningMsg("该员工学号已存在")
- if (this.phoneRepeat) return util.warningMsg("该手机号已存在")
- if (this.emailRepeat) return util.warningMsg("该邮箱已存在")
- const form = this.form
- if (this.teacherForm.roleAndDeptList.length){
- for (let i = 0; i < this.teacherForm.roleAndDeptList.length; i++) {
- if (this.teacherForm.roleAndDeptList[i].cascaderValue.length < 2) {
- util.warningMsg(`请选择${this.teacherForm.roleAndDeptList[i].roleName}所属部门`)
- return;
- } else {
- data.roleAndDeptList.push({
- roleId: this.teacherForm.roleAndDeptList[i].roleId,
- staffArchitectureId: this.teacherForm.roleAndDeptList[i].cascaderValue[0],
- gradeId: this.teacherForm.roleAndDeptList[i].cascaderValue[1]
- })
- }
- }
- }
- this.submiting = true
- if (form.accountId) {
- this.$post(this.api.modifyStaff, form).then(res => {
- util.successMsg("编辑成功!")
- this.closeStudent()
- setTimeout(() => {
- this.submiting = false
- }, 2000)
- }).catch(res => {
- setTimeout(() => {
- this.submiting = false
- }, 2000)
- })
- } else {
- form.uniqueIdentification = new Date().getTime()
- this.$post(this.api.saveStaff, form).then(res => {
- util.successMsg("新增成功!")
- this.closeStudent()
- setTimeout(() => {
- this.submiting = false
- }, 2000)
- }).catch(res => {
- setTimeout(() => {
- this.submiting = false
- }, 2000)
- })
- }
- }
- })
+ this.$refs.form.validate((valid) => {
+ if (valid) {
+ if (this.submiting) return false
+ if (this.accountReapeat) return util.warningMsg("该账号已存在")
+ if (this.workNumberReapeat) return util.warningMsg("该工号已存在")
+ if (this.phoneRepeat) return util.warningMsg("该手机号已存在")
+ if (this.emailRepeat) return util.warningMsg("该邮箱已存在")
+ this.submiting = true
+ const form = this.form
+ const ids = form.staffArchitectureId
+ form.staffArchitectureId = ids.map(e => e[e.length - 1])
+ console.log("🚀 ~ file: staff.vue ~ line 622 ~ this.$refs.form.validate ~ form", form)
+ if (form.accountId) {
+ this.$post(this.api.modifyStaff, form).then(res => {
+ util.successMsg("编辑成功!")
+ this.staffVisible = false
+ setTimeout(() => {
+ this.submiting = false
+ }, 2000)
+ }).catch(res => {
+ setTimeout(() => {
+ this.submiting = false
+ }, 2000)
+ })
+ } else {
+ form.uniqueIdentification = new Date().getTime()
+ this.$post(this.api.saveStaff, form).then(res => {
+ util.successMsg("新增成功!")
+ this.staffVisible = false
+ setTimeout(() => {
+ this.submiting = false
+ }, 2000)
+ }).catch(res => {
+ setTimeout(() => {
+ this.submiting = false
+ }, 2000)
+ })
+ }
+ }
+ })
},
// 关闭新增员工对话框
- closeStudent() {
+ closeStaff() {
this.$refs.form.clearValidate()
this.form = {
accountId: '',
@@ -705,65 +636,65 @@ export default {
uniqueIdentification: '',
workNumber: '',
email: '',
- classId: ''
+ staffArchitectureId: [],
+ roleList: []
};
- this.defaultCheckedKeys = []
this.isDetail = false
this.staffVisible = false
this.getStaff()
},
// 批量导入
batchImport() {
- this.importVisible = true;
- this.uploadList = [];
- this.uploadFaild = false;
+ this.importVisible = true
+ this.uploadList = []
+ this.uploadFaild = false
},
// 模板下载
downLoad() {
- location.href = this.api.studentTemplate;
+ location.href = this.api.studentTemplate
},
// 上传文件
handleExceed(files, fileList) {
- util.warningMsg(
- `当前限制选择 1 个文件,如需更换,请删除上一个文件再重新选择!`
- );
+ util.warningMsg(
+ `当前限制选择 1 个文件,如需更换,请删除上一个文件再重新选择!`
+ )
},
// 下载失败文件
showFaild() {
- location.href = `${this.api.exportFailure}?exportCode=${this.exportCode}`;
+ location.href = `${this.api.exportFailure}?exportCode=${this.exportCode}`
},
uploadSuccess(res, file, fileList) {
- this.uploadFaild = false;
- if (res.status === 200) {
- if (res.data.exportCode) {
- this.exportCode = res.data.exportCode;
- this.uploadFaild = true;
- }
- util.successMsg(`上传成功${res.data.successNum},上传失败${res.data.failureNum}`);
- util.successMsg(`本次上传有${res.data.failureNum}个错误信息录入`);
- } else {
- res.message ? util.errorMsg(res.message) : util.errorMsg("上传失败,请检查数据");
+ this.uploadFaild = false
+ if (res.status === 200) {
+ if (res.data.exportCode) {
+ this.exportCode = res.data.exportCode
+ this.uploadFaild = true
}
+ util.successMsg(`上传成功${res.data.successNum},上传失败${res.data.failureNum}`)
+ util.successMsg(`本次上传有${res.data.failureNum}个错误信息录入`)
+ } else {
+ res.message ? util.errorMsg(res.message) : util.errorMsg("上传失败,请检查数据")
+ }
},
uploadError(err, file, fileList) {
- this.$message({
- message: "上传出错,请重试!",
- type: "error",
- center: true
- });
+ this.$message({
+ message: "上传出错,请重试!",
+ type: "error",
+ center: true
+ })
},
beforeRemove(file, fileList) {
- return this.$confirm(`确定移除 ${file.name}?`);
+ return this.$confirm(`确定移除 ${file.name}?`)
},
handleRemove(file, fileList) {
- this.uploadList = fileList;
- this.uploadFaild = false;
+ this.uploadList = fileList
+ this.uploadFaild = false
},
uploadSure() {
- this.importVisible = false;
- this.studentType = 1;
- this.keyWord = "";
- this.initData();
+ this.importVisible = false
+ this.studentType = 1
+ this.keyWord = ''
+ this.initData()
}
}
};
@@ -776,4 +707,7 @@ export default {
.org-name {
margin-right: 20px;
}
+.w-100 {
+ width: 100%;
+}
\ No newline at end of file