Commit 57cf6a0f by 胡悦

启用禁用接口 前的提交

1 parent 305e7c28
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
"lint": "vue-cli-service lint" "lint": "vue-cli-service lint"
}, },
"dependencies": { "dependencies": {
"glsx-vue-common": "^1.1.11", "glsx-vue-common": "^1.1.12",
"glsx-vue-components": "^1.0.13", "glsx-vue-components": "^1.0.13",
"lodash": "^4.17.10", "lodash": "^4.17.10",
"node-sass": "^4.9.3", "node-sass": "^4.9.3",
......
...@@ -10,17 +10,7 @@ const userForm = { ...@@ -10,17 +10,7 @@ const userForm = {
departName: '', departName: '',
roles: [], roles: [],
departId: '', departId: '',
roleList: [], roleList: []
options: [
{
value: '1006',
label: '总经办'
},
{
value: '1001',
label: '研发中心-网络软件部'
}
]
} }
const userDetailColumn = [{ const userDetailColumn = [{
label: '用户名', label: '用户名',
...@@ -47,7 +37,8 @@ const userDetailColumn = [{ ...@@ -47,7 +37,8 @@ const userDetailColumn = [{
label: '状态', label: '状态',
prop: 'state', prop: 'state',
formatter: (cellValue) => { formatter: (cellValue) => {
return cellValue < 1 ? '禁止' : '启动' console.log(cellValue)
return cellValue.state < 1 ? '禁用' : '启动'
} }
}] }]
......
...@@ -12,8 +12,10 @@ ...@@ -12,8 +12,10 @@
</gl-form-item> </gl-form-item>
</gl-col> </gl-col>
<gl-col :span="12"> <gl-col :span="12">
<gl-form-item label="密码" prop="password"> <gl-form-item label="密码" prop="password" :rules="[
<gl-input type='password' v-model="userManageForm.password" placeholder='不填为不修改' clearable></gl-input> { required: !userManageForm.id, message: '请输入用户密码', trigger: 'blur' }
]">
<gl-input type='password' v-model="userManageForm.password" :placeholder='placeholder' clearable></gl-input>
</gl-form-item> </gl-form-item>
</gl-col> </gl-col>
<gl-col :span="12"> <gl-col :span="12">
...@@ -85,7 +87,8 @@ export default { ...@@ -85,7 +87,8 @@ export default {
name: 'UserCreate', name: 'UserCreate',
props: { props: {
dialogFormVisible: Boolean, dialogFormVisible: Boolean,
userManageForm: Object userManageForm: Object,
isEdit: Boolean
}, },
components: { components: {
userForm userForm
...@@ -95,6 +98,11 @@ export default { ...@@ -95,6 +98,11 @@ export default {
this.key = Date.now() this.key = Date.now()
val && console.log(this.userManageForm) val && console.log(this.userManageForm)
!val && this.$refs['userManageForm'].resetFields() !val && this.$refs['userManageForm'].resetFields()
},
'userManageForm.id'(val) {
console.log(val)
val && (this.placeholder = '不填为不修改')
!val && (this.placeholder = '')
} }
}, },
mounted() { mounted() {
...@@ -104,6 +112,8 @@ export default { ...@@ -104,6 +112,8 @@ export default {
return { return {
key: Date.now(), key: Date.now(),
isDepart: true, isDepart: true,
// userData: {},
placeholder: '',
defaultExpandAll: true, defaultExpandAll: true,
val: '', val: '',
tel: '[ 1, /[34578]/, /d/{9}]', tel: '[ 1, /[34578]/, /d/{9}]',
...@@ -115,9 +125,9 @@ export default { ...@@ -115,9 +125,9 @@ export default {
realname: [ realname: [
{ required: true, message: '请输入用户真实名字', trigger: 'blur' } { required: true, message: '请输入用户真实名字', trigger: 'blur' }
], ],
password: [ // password: [
{ required: false, message: '请输入用户密码', trigger: 'blur' } // { required: false, message: '请输入用户密码', trigger: 'blur' }
], // ],
mobile: [ mobile: [
{ required: true, message: '请输入正确的手机号码', trigger: 'blur' } { required: true, message: '请输入正确的手机号码', trigger: 'blur' }
], ],
...@@ -128,7 +138,10 @@ export default { ...@@ -128,7 +138,10 @@ export default {
{ required: true, message: '请输入邮箱', trigger: 'blur' }, { required: true, message: '请输入邮箱', trigger: 'blur' },
{ type: 'email', message: '请输入正确的邮箱地址', trigger: ['blur', 'change'] } { type: 'email', message: '请输入正确的邮箱地址', trigger: ['blur', 'change'] }
], ],
departId: [ departName: [
{ required: true, message: '请输入所属部门', trigger: 'blur' }
],
roles: [
{ required: true, message: '请输入所属部门', trigger: 'blur' } { required: true, message: '请输入所属部门', trigger: 'blur' }
] ]
} }
...@@ -149,11 +162,9 @@ export default { ...@@ -149,11 +162,9 @@ export default {
}) })
}, },
clickDepart(data, treeData, vue, props) { clickDepart(data, treeData, vue, props) {
console.log(data)
if (data.parent !== '#' || !data.children) { if (data.parent !== '#' || !data.children) {
this.userManageForm.departId = data.id this.userManageForm.departId = data.id
this.userManageForm.departName = data.text this.userManageForm.departName = data.text
console.log(this.userManageForm.departName)
this.getDepartName(treeData) this.getDepartName(treeData)
// this.userManageForm.departName = this.departName.join(' - ') // this.userManageForm.departName = this.departName.join(' - ')
this.departName = [] this.departName = []
...@@ -161,7 +172,6 @@ export default { ...@@ -161,7 +172,6 @@ export default {
}, },
getDepartName(params) { getDepartName(params) {
this.userManageForm.departName.split().push(params.data.text) this.userManageForm.departName.split().push(params.data.text)
console.log(this.userManageForm.departName)
if (params.data.parent !== '#') { if (params.data.parent !== '#') {
this.getDepartName(params.parent) this.getDepartName(params.parent)
} else { } else {
...@@ -170,25 +180,16 @@ export default { ...@@ -170,25 +180,16 @@ export default {
}, },
submitForm(formName) { submitForm(formName) {
this.$refs[formName].validate(valid => { this.$refs[formName].validate(valid => {
const userData = this.$deep_clone(this.userManageForm) this.userData = this.$deep_clone(this.userManageForm)
console.log(userData.roleList) !this.userData.password && delete userForm.password
// userData.roleList = userData.roleList.map(item => item.id).join(',') this.userData.roles = this.val
// userData.roles = userData.roles.join(',') delete this.userData.createTime
console.log(this.val) delete this.userData.updateTime
console.log(userData.password)
!userData.password && delete userForm.password
userData.roles = this.val
delete userData.createTime
delete userData.updateTime
// userData.departId = userData.options.map(item => item.value).join(',')
console.log(userData)
const isflagId = userData.id
if (valid) { if (valid) {
this.$emit('userFormData', isflagId, userData) this.$emit('userFormData', this.isEdit, this.userData)
} else { } else {
return false return false
} }
console.log(userData)
}) })
}, },
cancelForm() { cancelForm() {
...@@ -196,7 +197,6 @@ export default { ...@@ -196,7 +197,6 @@ export default {
}, },
handleCheckedChange(value) { handleCheckedChange(value) {
if (!value) return if (!value) return
console.log(value)
this.val = value.join(',') this.val = value.join(',')
} }
} }
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
<div class="control-tabledata-button"> <div class="control-tabledata-button">
<gl-button size="small" @click="createUser()">新增用户</gl-button> <gl-button size="small" @click="createUser()">新增用户</gl-button>
<gl-button size="small" @click="toggleRowSelection">删除选中</gl-button> <gl-button size="small" @click="toggleRowSelection">删除选中</gl-button>
<user-create :dialogFormVisible="dialogFormVisible" :userManageForm="userManageForm" @userFormData="handleUserFormData"></user-create> <user-create :dialogFormVisible="dialogFormVisible" :userManageForm="userManageForm" :isEdit="isEdit" @userFormData="handleUserFormData"></user-create>
</div> </div>
<div class="m-b8"> <div class="m-b8">
<gl-table :table="userData" ref="multipleTable"></gl-table> <gl-table :table="userData" ref="multipleTable"></gl-table>
...@@ -23,7 +23,6 @@ ...@@ -23,7 +23,6 @@
</template> </template>
<script> <script>
var consoleState = '禁用'
import { UserCreate, UserDetail } from '@/components/index' import { UserCreate, UserDetail } from '@/components/index'
// 接口 // 接口
import { findAll, updateUser, getRoleList, batcheDelUser, operatUser, findDepartTree } from '@/api/api' import { findAll, updateUser, getRoleList, batcheDelUser, operatUser, findDepartTree } from '@/api/api'
...@@ -40,7 +39,7 @@ export default { ...@@ -40,7 +39,7 @@ export default {
return { return {
userName: '', userName: '',
toggle: [], toggle: [],
state: '0', isEdit: true,
departList: [], departList: [],
dialogFormVisible: false, dialogFormVisible: false,
userManageForm: this.$deep_clone(userForm), userManageForm: this.$deep_clone(userForm),
...@@ -83,11 +82,16 @@ export default { ...@@ -83,11 +82,16 @@ export default {
label: '状态', label: '状态',
prop: 'state', prop: 'state',
formatter: (cellValue) => { formatter: (cellValue) => {
return +cellValue.state < 1 ? '禁止' : '启动' return +cellValue.state < 1 ? '禁用' : '启动'
} }
}, { }, {
label: '创建时间', label: '创建时间',
prop: 'createTime' prop: 'createTime',
formatter: (cellValue) => {
if (cellValue.createTime) {
return new Date(cellValue.createTime).format('yyyy-MM-dd HH:mm:ss')
}
}
}], }],
number: { number: {
label: '序号', label: '序号',
...@@ -104,7 +108,7 @@ export default { ...@@ -104,7 +108,7 @@ export default {
type: 'text', type: 'text',
callback: (index, rows) => { callback: (index, rows) => {
console.log(rows[index]) console.log(rows[index])
this.createUser(rows[index]) this.editUser(rows[index])
} }
}, { }, {
label: '详细', label: '详细',
...@@ -115,18 +119,17 @@ export default { ...@@ -115,18 +119,17 @@ export default {
}, { }, {
label: '禁用', label: '禁用',
type: 'text', type: 'text',
formatter(cellValue) { formatter(index, column, rows) {
column.label = rows[index].state < 1 ? '启动' : '禁用'
}, },
callback: (index, rows) => { callback: (index, rows) => {
// rows[index].state = '0'
console.log(rows[index].state) console.log(rows[index].state)
if (rows[index].state < 1) {
this.$set(rows[index], 'state', '1') this.$set(rows[index], 'state', '1')
} else {
this.$set(rows[index], 'state', '0')
}
console.log(rows[index].state) console.log(rows[index].state)
// this.state = '1'
// console.log(this.updateState())
// this.updateState()
// console.log(consoleState)
// this.$alert(rows[index])
} }
}, { }, {
label: '删除', label: '删除',
...@@ -168,21 +171,19 @@ export default { ...@@ -168,21 +171,19 @@ export default {
findAll.req(params).then(res => { findAll.req(params).then(res => {
this.total = res.total this.total = res.total
this.userData.data = res.list this.userData.data = res.list
console.log(this.userData.data)
}).catch(err => { }).catch(err => {
console.log(err) console.log(err)
}) })
}, },
// 接口请求-end
message(message, type) { message(message, type) {
type && this.$message({ type && this.$notify({
showClose: true,
type: type, type: type,
message: message title: message,
duration: 2000
}) })
!type && this.$message({ !type && this.$notify({
showClose: true, title: message,
message: message duration: 2000
}) })
}, },
// 获取所有角色选项 // 获取所有角色选项
...@@ -196,9 +197,12 @@ export default { ...@@ -196,9 +197,12 @@ export default {
if (params) { if (params) {
updateUser.req(params).then(res => { updateUser.req(params).then(res => {
console.log(res) console.log(res)
}).catch(res => { this.message('操作成功', 'success')
console.log(res) // this.createOrEditSuccess()
// this.message(message, 'error') this.findUserList()
}).catch(message => {
console.log(message)
this.message(message, 'error')
}) })
} }
}, },
...@@ -212,7 +216,7 @@ export default { ...@@ -212,7 +216,7 @@ export default {
console.log('无数据!') console.log('无数据!')
} }
}, },
// 删除、禁用、启用接口 // 删除、禁用、启用接口f
operatUser(params) { operatUser(params) {
if (params) { if (params) {
operatUser.req(params).then(res => { operatUser.req(params).then(res => {
...@@ -223,55 +227,40 @@ export default { ...@@ -223,55 +227,40 @@ export default {
} }
}, },
// 接受子组件传递的值 // 接受子组件传递的值
handleUserFormData(isflag, params) { handleUserFormData(isEdit, params) {
this.dialogFormVisible = !this.dialogFormVisible console.log(isEdit)
this.userManageForm = {} this.userManageForm = {}
!params && this.message('取消操作') !params && this.message('取消操作', 'warning')
params && !isflag && this.updateUser_Post(params) && this.message('已经添加用户!', 'success') params && this.updateUser_Post(params)
params && isflag && this.updateUser_Post(params) && this.message('已经成功修改数据!', 'success') this.dialogFormVisible = !this.dialogFormVisible
}, },
// 新增按钮 // 新增按钮
createUser(userManageForm) { createUser(userManageForm) {
this.userManageForm = {} this.userManageForm = this.$deep_clone(userForm)
if (userManageForm) { this.dialogFormVisible = !this.dialogFormVisible
userManageForm.password = '' this.isEdit = false
userManageForm.roleList = this.$deep_clone(userForm.roleList) },
// userManageForm.options = userForm.options // 编辑按钮
userManageForm.state = userManageForm.state + '' editUser(row) {
userManageForm.isadmin = userManageForm.isadmin + '' row.password = ''
row.roleList = this.$deep_clone(userForm.roleList)
row.state = row.state + ''
row.isadmin = row.isadmin + ''
this.departList.forEach(item => { this.departList.forEach(item => {
if (item.id === userManageForm.departId) { if (item.id === row.departId) {
userManageForm.departName = item.text row.departName = item.text
} }
}) })
Promise.all([findAll, getRoleList]).then((result) => { Promise.all([findAll, getRoleList]).then((result) => {
// error if (row.roles && typeof (row.roles) === 'string') {
console.log(typeof (userManageForm.roles)) row.roles = (row.roles + '').split(',').map(role => +role)
if (userManageForm.roles && typeof (userManageForm.roles) === 'string') {
console.log(userManageForm.roles)
userManageForm.roles = (userManageForm.roles + '').split(',').map(role => +role)
} else { } else {
userManageForm.roles = [] row.roles = []
} }
console.log(userManageForm.roles) this.userManageForm = this.$deep_clone(row)
// arr.forEach(index => {
// userManageForm.roleList.forEach(item => {
// if (+item.id === +index) {
// item.isSelect = true
// return false
// }
// })
// })
// userManageForm.roleList = [{ id: 1, roleName: 'aaa' }]
this.userManageForm = this.$deep_clone(userManageForm)
}) })
} else {
this.userManageForm = this.$deep_clone(userForm)
}
this.dialogFormVisible = !this.dialogFormVisible this.dialogFormVisible = !this.dialogFormVisible
}, this.isEdit = this.isEdit
// 编辑按钮
editUser(row) {
}, },
// 获取选中的行 // 获取选中的行
handleSelectionChange(val, row) { handleSelectionChange(val, row) {
...@@ -290,18 +279,25 @@ export default { ...@@ -290,18 +279,25 @@ export default {
type: 'warning' type: 'warning'
}).then(() => { }).then(() => {
this.batcheDel(ids.join(',')) this.batcheDel(ids.join(','))
this.message('删除成功', 'success')
}).catch(() => { }).catch(() => {
this.message('取消删除') this.message('取消删除', 'info')
}) })
} else { } else {
this.message('', '操作失败') this.message('', '操作失败')
} }
}, },
// 提示
createOrEditSuccess() {
this.dialogFormVisible = !this.dialogFormVisible
this.message(!this.isEdit ? '创建角色成功' : '已经成功修改数据', 'success')
this.findUserList()
},
// 搜索
finduserName() { finduserName() {
// this.userName = ''
this.findUserList() this.findUserList()
}, },
// 调取接口相关函数 // 调取接口相关函数 分页
handleSizeChange(val) { handleSizeChange(val) {
this.pageSize = val this.pageSize = val
this.findUserList() this.findUserList()
...@@ -310,42 +306,42 @@ export default { ...@@ -310,42 +306,42 @@ export default {
this.pageNum = val this.pageNum = val
this.findUserList() this.findUserList()
}, },
// 单行删除
confirmDeleteOrNot(index, rows) { confirmDeleteOrNot(index, rows) {
this.$confirm('确定要删除这条数据?', '', { this.$confirm('确定要删除这条数据?', '', {
confirmButtonText: '确定', confirmButtonText: '确定',
cancelButtonText: '取消', cancelButtonText: '取消',
type: 'warning' type: 'warning'
}).then(() => { }).then(() => {
// 删除角色,根据返回的code值来判断是否删除成功(已有拦截器)
this.operatUser({ id: rows[index].id, state: 2 }) this.operatUser({ id: rows[index].id, state: 2 })
this.message('成功删除该用户', 'success')
}).catch(() => { }).catch(() => {
this.message('取消删除') this.message('取消删除', 'info')
}) })
}, },
userDetailDialogVisible() { // 详细操作
this.userDetailVisible = !this.userDetailVisible
},
handleGetUserDetail(index, rows) { handleGetUserDetail(index, rows) {
this.columnParam = userDetailColumn this.columnParam = userDetailColumn
this.consoleParam = [] this.consoleParam = []
this.flagRoleOrUser = false this.flagRoleOrUser = false
this.apiParam = rows[index] this.apiParam = rows[index]
this.userDetailDialogVisible() console.log(this.apiParam)
this.userDetailVisible = !this.userDetailVisible
}, },
handleUserDetailClose() { handleUserDetailClose() {
this.userDetailDialogVisible() this.userDetailVisible = !this.userDetailVisible
this.apiParam = Number this.apiParam = Number
},
// 修改启用禁用
updateState() {
if (this.state === '0') {
consoleState = '禁用'
return consoleState
} else {
consoleState = '启用'
return consoleState
}
} }
// 修改启用禁用
// updateState() {
// if (this.state === '0') {
// consoleState = '禁用'
// return consoleState
// } else {
// consoleState = '启用'
// return consoleState
// }
// }
} }
} }
</script> </script>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!