用户列表代码提交

ywj_dev
郑明梁 2 years ago
parent b0fd941e0c
commit e51f8d14e4

@ -18,6 +18,7 @@
</el-select> </el-select>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="4">
<el-form-item> <el-form-item>
<el-button-group> <el-button-group>
<el-button type="primary" icon="el-icon-refresh" @click="onReset"></el-button> <el-button type="primary" icon="el-icon-refresh" @click="onReset"></el-button>
@ -25,11 +26,11 @@
<el-button type="primary" @click.native="handleForm(null, null)">新增</el-button> <el-button type="primary" @click.native="handleForm(null, null)">新增</el-button>
</el-button-group> </el-button-group>
</el-form-item> </el-form-item>
</el-col>
</el-row> </el-row>
</el-form> </el-form>
<el-table v-loading="loading" :data="list" border style="width: 100%"> <el-table v-loading="loading" :data="list" border style="width: 100%">
<el-table-column label="序号" type="index" width="50" fixed></el-table-column> <el-table-column label="序号" type="index" width="50" fixed></el-table-column>
<el-table-column label="用户账号" prop="userName" fixed></el-table-column> <el-table-column label="用户账号" prop="userName" fixed></el-table-column>
@ -131,50 +132,50 @@ import {
authAdminList, authAdminList,
authCustomerRoles, authCustomerRoles,
authAdminSave, authAdminSave,
authAdminDelete, authAdminDelete
} from "../../api/auth/authAdmin"; } from '../../api/auth/authAdmin'
import {userInfo} from "../../api/auth/login"; import { userInfo } from '../../api/auth/login'
const formJson = { const formJson = {
id: "", id: '',
passWord: "", passWord: '',
userName: "", userName: '',
checkPassword: "", checkPassword: '',
employeeName: "", employeeName: '',
userFlag: 1, userFlag: 1,
customerId: "", customerId: '',
comments: "", comments: '',
roles: [], roles: []
}; }
export default { export default {
data() { data() {
let validatePass = (rule, value, callback) => { let validatePass = (rule, value, callback) => {
if (value === "") { if (value === '') {
callback(new Error("请输入密码")); callback(new Error('请输入密码'))
} else { } else {
callback(); callback()
}
} }
};
let validatePass2 = (rule, value, callback) => { let validatePass2 = (rule, value, callback) => {
if (value === "") { if (value === '') {
callback(new Error("请再次输入密码")); callback(new Error('请再次输入密码'))
} else if (value !== this.formData.passWord) { } else if (value !== this.formData.passWord) {
callback(new Error("两次输入密码不一致!")); callback(new Error('两次输入密码不一致!'))
} else { } else {
callback(); callback()
}
} }
};
return { return {
roles: [], roles: [],
query: { query: {
userName: "", userName: '',
userFlag: "", userFlag: '',
page: 1, page: 1,
limit: 20, limit: 20,
roleId: "", roleId: '',
customerId: "", customerId: this.$store.getters.customerId,
companyName: "", companyName: ''
}, },
list: [], list: [],
total: 0, total: 0,
@ -182,98 +183,97 @@ export default {
index: null, index: null,
formName: null, formName: null,
formMap: { formMap: {
add: "新增", add: '新增',
edit: "编辑", edit: '编辑'
}, },
userInfo: { userInfo: {
customerId: "", customerId: '',
companyName: "", companyName: '',
userId: "", userId: '',
roles: [], roles: []
}, },
formLoading: false, formLoading: false,
formVisible: false, formVisible: false,
formData: formJson, formData: formJson,
formRules: {}, formRules: {},
addRules: { addRules: {
userName: [{required: true, message: "请输入姓名", trigger: "blur"}], userName: [{ required: true, message: '请输入姓名', trigger: 'blur' }],
passWord: [ passWord: [
{required: true, message: "请输入密码", trigger: "blur"}, { required: true, message: '请输入密码', trigger: 'blur' },
{validator: validatePass, trigger: "blur"}, { validator: validatePass, trigger: 'blur' }
], ],
checkPassword: [ checkPassword: [
{ {
required: true, required: true,
message: "请再次输入密码", message: '请再次输入密码',
trigger: "blur", trigger: 'blur'
}, },
{validator: validatePass2, trigger: "blur"}, { validator: validatePass2, trigger: 'blur' }
], ]
// userFlag: [ // userFlag: [
// { required: true, message: "", trigger: "change" }, // { required: true, message: "", trigger: "change" },
// ], // ],
}, },
editRules: { editRules: {
userName: [{required: true, message: "请输入姓名", trigger: "blur"}], userName: [{ required: true, message: '请输入姓名', trigger: 'blur' }]
// userFlag: [ // userFlag: [
// { required: true, message: "", trigger: "change" }, // { required: true, message: "", trigger: "change" },
// ], // ],
}, },
deleteLoading: false, deleteLoading: false
}; }
}, },
methods: { methods: {
onReset() { onReset() {
this.$router.push({ this.$router.push({
path: "", path: ''
}); })
this.query = { this.query = {
userName: "", userName: '',
userFlag: "", userFlag: '',
page: 1, page: 1,
limit: 20, limit: 20,
roleId: "", roleId: '',
customerId: this.userInfo.customerId, customerId: this.$store.getters.customerId
companyName: this.userInfo.companyName, }
}; this.getList()
this.getList();
}, },
onSubmit() { onSubmit() {
this.$router.push({ this.$router.push({
path: "", path: '',
query: this.query, query: this.query
}); })
this.query.page = 1; this.query.page = 1
this.getList(); this.getList()
}, },
handleCurrentChange(val) { handleCurrentChange(val) {
this.query.page = val.page; this.query.page = val.page
this.getList(); this.getList()
}, },
getList() { getList() {
this.loading = true; this.loading = true
authAdminList(this.query) authAdminList(this.query)
.then((response) => { .then((response) => {
this.loading = false; this.loading = false
this.list = response.data.list || []; this.list = response.data.list || []
this.total = response.data.total || 0; this.total = response.data.total || 0
}) })
.catch(() => { .catch(() => {
this.loading = false; this.loading = false
this.list = []; this.list = []
this.total = 0; this.total = 0
this.roles = []; this.roles = []
}); })
}, },
getRoleList() { getRoleList() {
authCustomerRoles(this.query) authCustomerRoles(this.query)
.then((response) => { .then((response) => {
this.roles = response.data.list || []; this.roles = response.data.list || []
}) })
.catch(() => { .catch(() => {
this.roles = []; this.roles = []
}); })
}, },
getUserInfo() { getUserInfo() {
@ -283,60 +283,60 @@ export default {
customerId: response.data.customerId, customerId: response.data.customerId,
companyName: response.data.companyName, companyName: response.data.companyName,
userId: response.data.id, userId: response.data.id,
roles: response.data.roleIds, roles: response.data.roleIds
}; }
this.query.customerId = response.data.customerId; this.query.customerId = response.data.customerId
this.query.companyName = response.data.companyName; this.query.companyName = response.data.companyName
this.getList(); this.getList()
}) })
.catch(() => { .catch(() => {
this.customerId = ""; this.customerId = ''
this.companyName = ""; this.companyName = ''
}); })
}, },
// //
resetForm() { resetForm() {
if (this.$refs["dataForm"]) { if (this.$refs['dataForm']) {
// //
this.$refs["dataForm"].clearValidate(); this.$refs['dataForm'].clearValidate()
// //
this.$refs["dataForm"].resetFields(); this.$refs['dataForm'].resetFields()
} }
}, },
// //
hideForm() { hideForm() {
// //
this.formVisible = !this.formVisible; this.formVisible = !this.formVisible
// //
this.$refs["dataForm"].resetFields(); this.$refs['dataForm'].resetFields()
return true; return true
}, },
// //
handleForm(index, row) { handleForm(index, row) {
this.formVisible = true; this.formVisible = true
this.formData = JSON.parse(JSON.stringify(formJson)); this.formData = JSON.parse(JSON.stringify(formJson))
if (row !== null) { if (row !== null) {
this.formData = Object.assign({}, row); this.formData = Object.assign({}, row)
} }
this.formName = "add"; this.formName = 'add'
this.formRules = this.addRules; this.formRules = this.addRules
if (index !== null) { if (index !== null) {
this.index = index; this.index = index
this.formName = "edit"; this.formName = 'edit'
this.formRules = this.addRules; this.formRules = this.addRules
} }
}, },
formSubmit() { formSubmit() {
this.$refs["dataForm"].validate((valid) => { this.$refs['dataForm'].validate((valid) => {
if (valid) { if (valid) {
this.formLoading = true; this.formLoading = true
this.formData.userFlag = 1; this.formData.userFlag = 1
this.formData.roles = this.userInfo.roles; this.formData.roles = this.userInfo.roles
this.formData.customerId = this.userInfo.customerId; this.formData.customerId = this.userInfo.customerId
this.formData.companyName = this.userInfo.companyName; this.formData.companyName = this.userInfo.companyName
let data = Object.assign({}, this.formData); let data = Object.assign({}, this.formData)
let savequery = { let savequery = {
id: this.formData.id, id: this.formData.id,
userFlag: 1, userFlag: 1,
@ -346,88 +346,90 @@ export default {
passWord: this.formData.passWord, passWord: this.formData.passWord,
userName: this.formData.userName, userName: this.formData.userName,
employeeName: this.formData.employeeName, employeeName: this.formData.employeeName,
comments: this.formData.comments, comments: this.formData.comments
}; }
authAdminSave(savequery, this.formName).then((response) => { authAdminSave(savequery, this.formName).then((response) => {
this.formLoading = false; this.formLoading = false
if (response.code !== 20000) { if (response.code !== 20000) {
this.$message.error(response.message); this.$message.error(response.message)
return false; return false
} }
this.$message.success("操作成功"); this.$message.success('操作成功')
this.formVisible = false; this.formVisible = false
if (this.formName === "add") { if (this.formName === 'add') {
// //
if (response.data && response.data.id) { if (response.data && response.data.id) {
data.id = response.data.id; data.id = response.data.id
this.list.unshift(data); this.list.unshift(data)
} }
} else { } else {
this.list.splice(this.index, 1, data); this.list.splice(this.index, 1, data)
} }
// //
this.resetForm(); this.resetForm()
}); })
} else { } else {
} }
}); })
}, },
// //
handleDel(index, row) { handleDel(index, row) {
if (row.id === this.userInfo.userId) { if (row.id === this.userInfo.userId) {
this.$message.warning("不能删除自己"); this.$message.warning('不能删除自己')
} else if (row.id) { } else if (row.id) {
this.$confirm("确认删除该记录吗?", "提示", { this.$confirm('确认删除该记录吗?', '提示', {
type: "warning", type: 'warning'
}) })
.then(() => { .then(() => {
let para = {id: row.id}; let para = { id: row.id }
this.deleteLoading = true; this.deleteLoading = true
authAdminDelete(para) authAdminDelete(para)
.then((response) => { .then((response) => {
this.deleteLoading = false; this.deleteLoading = false
if (response.code !== 20000) { if (response.code !== 20000) {
this.$message.error(response.message); this.$message.error(response.message)
return false; return false
} }
this.$message.success("操作成功"); this.$message.success('操作成功')
// //
this.list.splice(index, 1); this.list.splice(index, 1)
}) })
.catch(() => { .catch(() => {
this.deleteLoading = false; this.deleteLoading = false
}); })
}) })
.catch(() => { .catch(() => {
this.$message.info("取消删除"); this.$message.info('取消删除')
}); })
}
} }
},
}, },
filters: { filters: {
statusFilterType(status) { statusFilterType(status) {
const statusMap = { const statusMap = {
0: "gray", 0: 'gray',
1: "success", 1: 'success',
2: "danger", 2: 'danger'
}; }
return statusMap[status]; return statusMap[status]
}, },
statusFilterName(status) { statusFilterName(status) {
const statusMap = { const statusMap = {
0: "禁用", 0: '禁用',
1: "正常", 1: '正常',
2: "未验证", 2: '未验证'
}; }
return statusMap[status]; return statusMap[status]
}, }
}, },
mounted() { mounted() {
}, },
created() { created() {
this.getList(); this.getList()
}, debugger
};
}
}
</script> </script>
<style type="text/scss" lang="scss"> <style type="text/scss" lang="scss">

Loading…
Cancel
Save