Commit ad118ec8 by 胡悦

树组件删除修改刷新和用户 代码优化

1 parent 42115ac1
...@@ -55,7 +55,7 @@ const userRoleDetailColumn = [{ ...@@ -55,7 +55,7 @@ const userRoleDetailColumn = [{
}] }]
const userRoleDetailConsole = { const userRoleDetailConsole = {
// show: true, show: true,
label: '操作', label: '操作',
prop: 'option', prop: 'option',
button: [{ button: [{
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
ref='tree' ref='tree'
@node-click='nodeClick' @node-click='nodeClick'
:isDepart='isDepart' :isDepart='isDepart'
:updateTree="value.updateTree"
></tree> ></tree>
</div> </div>
</template> </template>
......
...@@ -21,14 +21,17 @@ ...@@ -21,14 +21,17 @@
v-model="value.form[i.value]" v-model="value.form[i.value]"
:disabled="i.disabled"> :disabled="i.disabled">
</gl-switch> </gl-switch>
<div class="el-input el-input--mini" v-else-if="i.value === 'iorder'">
<input type="text" @input="input(i.value)" v-model="value.form[i.value]" class="el-input__inner" placeholder="请输入数字" />
</div>
<gl-input <gl-input
v-else v-else
v-model="value.form[i.value]" v-model="value.form[i.value]"
:disabled="i.disabled"> :disabled="i.disabled">
</gl-input> </gl-input>
<div v-show="err && index === 0" class="err">{{textName}}</div> <div v-show="err && index === 0" class="err">{{textName}}</div>
<div v-show="errExist && index === 0" class="err">{{textExist}}</div> <!-- <div v-show="errExist && index === 0" class="err">{{textExist}}</div>
<div v-show="errIorder && index === 8" class="err">{{textType}}</div> <div v-show="errIorder && index === 8" class="err">{{textType}}</div> -->
</gl-form-item> </gl-form-item>
<gl-form-item> <gl-form-item>
<gl-button type="primary" @click="submit">{{value.btnTxt}}</gl-button> <gl-button type="primary" @click="submit">{{value.btnTxt}}</gl-button>
...@@ -51,6 +54,7 @@ ...@@ -51,6 +54,7 @@
</template> </template>
<script type='text/ecmascript-6'> <script type='text/ecmascript-6'>
import { delDepartment, delMenu, editMenu, addMenu, updateDepartment } from '@/api/api' import { delDepartment, delMenu, editMenu, addMenu, updateDepartment } from '@/api/api'
const reg = new RegExp(/^[0-9]*$/)
export default { export default {
name: 'rightForm', name: 'rightForm',
data() { data() {
...@@ -78,16 +82,21 @@ export default { ...@@ -78,16 +82,21 @@ export default {
}, },
'value.form.name'(val) { 'value.form.name'(val) {
if (val !== '') this.nameTip() if (val !== '') this.nameTip()
},
'value.form.iorder'(val) {
if (val && !parseInt(val)) {
this.errIorder = true
} else {
this.errIorder = false
}
} }
// 'value.form.iorder'(val) {
// if (val && !parseInt(val)) {
// this.errIorder = true
// } else {
// this.errIorder = false
// }
// }
}, },
methods: { methods: {
input(val) {
if (!reg.test(this.value.form[val])) {
this.value.form[val] = ''
}
},
nameTip() { nameTip() {
this.err = false this.err = false
this.errExist = false this.errExist = false
...@@ -148,6 +157,7 @@ export default { ...@@ -148,6 +157,7 @@ export default {
type: 'success' type: 'success'
}) })
this.value.showDetails = false this.value.showDetails = false
this.value.updateTree = !this.value.updateTree
} else { } else {
this.$notify({ this.$notify({
title: '已取消', title: '已取消',
...@@ -224,6 +234,7 @@ export default { ...@@ -224,6 +234,7 @@ export default {
type: 'success' type: 'success'
}) })
this.value.showDetails = false this.value.showDetails = false
this.value.updateTree = !this.value.updateTree
} else { } else {
this.$notify({ this.$notify({
title: '操作失败', title: '操作失败',
......
...@@ -37,6 +37,7 @@ export default { ...@@ -37,6 +37,7 @@ export default {
keyFresh: [Boolean, Array, Function], keyFresh: [Boolean, Array, Function],
showCheckbox: Boolean, showCheckbox: Boolean,
value: null, value: null,
updateTree: Boolean,
defaultExpandAll: Boolean, defaultExpandAll: Boolean,
treeStyle: null, treeStyle: null,
defaultCheckedKeys: { defaultCheckedKeys: {
...@@ -57,6 +58,9 @@ export default { ...@@ -57,6 +58,9 @@ export default {
}, },
propsData(val) { propsData(val) {
this.loadingTree() this.loadingTree()
},
updateTree(val) {
this.getData()
} }
}, },
methods: { methods: {
......
...@@ -4,8 +4,7 @@ ...@@ -4,8 +4,7 @@
<el-col :span="12"> <el-col :span="12">
<gl-form-item label="用户名" prop="username"> <gl-form-item label="用户名" prop="username">
<gl-input v-model="userManageForm.username" clearable></gl-input> <gl-input v-model="userManageForm.username" clearable></gl-input>
<!-- <input v-color="red" /> --> <!-- <input type="text" name="" v-blur="color" @blur="add" v-model="inputValue"> -->
<!-- <div v-show="!isEdit" class="err">{{msg}}</div> -->
</gl-form-item> </gl-form-item>
</el-col> </el-col>
<gl-col :span="12"> <gl-col :span="12">
...@@ -55,20 +54,7 @@ ...@@ -55,20 +54,7 @@
</gl-col> </gl-col>
<gl-col :span="24"> <gl-col :span="24">
<gl-form-item label="所属部门" prop="departName"> <gl-form-item label="所属部门" prop="departName">
<!-- <gl-select v-model="userManageForm.departName" placeholder="请选择">
<gl-option style="height:160px">
<tree ref='tree' :isDepart="isDepart" :defaultExpandAll="defaultExpandAll" @node-click='clickDepart' style="height:160px"></tree>
</gl-option>
</gl-select> -->
<gl-input-tree :data='userManageForm.departList' :props="props" :treeStyle='{ maxHeight: "160px" }' @node-click='clickDepart' v-model="userManageForm.departName" /> <gl-input-tree :data='userManageForm.departList' :props="props" :treeStyle='{ maxHeight: "160px" }' @node-click='clickDepart' v-model="userManageForm.departName" />
<!-- <gl-select v-model="userManageForm.departId" placeholder="请选择">
<gl-option
v-for="item in userManageForm.options"
:key="item.value"
:label="item.label"
:value="item.value">
</gl-option>
</gl-select> -->
</gl-form-item> </gl-form-item>
</gl-col> </gl-col>
<gl-col :span="24"> <gl-col :span="24">
...@@ -88,13 +74,13 @@ ...@@ -88,13 +74,13 @@
<script> <script>
import { userForm } from '@/common/userConst' import { userForm } from '@/common/userConst'
// import { updateUser } from '@/api/api'
export default { export default {
name: 'UserCreate', name: 'UserCreate',
props: { props: {
dialogFormVisible: Boolean, dialogFormVisible: Boolean,
userManageForm: Object, userManageForm: Object,
isEdit: Boolean isEdit: Boolean
// msg: String
}, },
components: { components: {
userForm userForm
...@@ -106,13 +92,24 @@ export default { ...@@ -106,13 +92,24 @@ export default {
!val && this.$refs['userManageForm'].resetFields() !val && this.$refs['userManageForm'].resetFields()
}, },
'userManageForm.id'(val) { 'userManageForm.id'(val) {
val && (this.placeholder = '不填为不修改') this.placeholder = val ? '不填为不修改' : ''
!val && (this.placeholder = '')
this.title = val ? '编辑用户' : '新建用户' this.title = val ? '编辑用户' : '新建用户'
} }
}, },
// directives: {
// blur: {
// update: function(el, binding) {
// console.log(el)
// console.log(binding)
// el.style = 'color:' + binding.value
// }
// }
// },
data() { data() {
return { return {
// msg: '',
// color: 'red',
// inputValue: 'dfadf',
key: Date.now(), key: Date.now(),
isDepart: true, isDepart: true,
props: { props: {
...@@ -127,14 +124,10 @@ export default { ...@@ -127,14 +124,10 @@ export default {
rules: { rules: {
username: [ username: [
{ required: true, message: '请输入用户名', trigger: 'blur' } { required: true, message: '请输入用户名', trigger: 'blur' }
// { min: 3, max: 5, message: '长度在 2 到 5 个字符', trigger: 'blur' }
], ],
realname: [ realname: [
{ required: true, message: '请输入用户真实名字', trigger: 'blur' } { required: true, message: '请输入用户真实名字', trigger: 'blur' }
], ],
// password: [
// { required: false, message: '请输入用户密码', trigger: 'blur' }
// ],
mobile: [ mobile: [
{ required: true, message: '请输入正确的手机号码', trigger: 'blur' } { required: true, message: '请输入正确的手机号码', trigger: 'blur' }
], ],
...@@ -155,19 +148,27 @@ export default { ...@@ -155,19 +148,27 @@ export default {
} }
}, },
methods: { methods: {
message(message, type) { // add() {
type && // this.color = '#' + Math.floor(Math.random() * 1000000)
this.$message({ // console.log(Math.floor(Math.random() * 1000000))
showClose: true, // // const params = {}
type: type, // // params.departId = 1000
message: message // // params.departName = '总经办'
}) // // params.email = 'kjkl@qq.com'
!type && // // params.isadmin = false
this.$message({ // // params.joinip = '192.168.2.22'
showClose: true, // // params.mobile = '546513216'
message: message // // params.realname = 'huyue'
}) // // params.roles = '1087.1088'
}, // // params.state = 1
// // params.username = this.inputValue
// // updateUser.req(params).then(res => {
// // console.log(res)
// // }).catch(message => {
// // console.log(message)
// // this.msg = message
// // })
// },
clickDepart(data, treeData, vue, props) { clickDepart(data, treeData, vue, props) {
if (data.parent !== '#' || !data.children) { if (data.parent !== '#' || !data.children) {
this.userManageForm.departId = data.id this.userManageForm.departId = data.id
...@@ -200,6 +201,7 @@ export default { ...@@ -200,6 +201,7 @@ export default {
} }
if (valid) { if (valid) {
this.$emit('userFormData', this.isEdit, this.userData) this.$emit('userFormData', this.isEdit, this.userData)
console.log(this.isEdit)
} else { } else {
return false return false
} }
......
...@@ -19,6 +19,7 @@ export default { ...@@ -19,6 +19,7 @@ export default {
return { return {
height: 0, height: 0,
department: { department: {
updateTree: false,
sublings: false, sublings: false,
children: false, children: false,
node: null, node: null,
......
...@@ -17,6 +17,7 @@ export default { ...@@ -17,6 +17,7 @@ export default {
return { return {
height: 0, height: 0,
menuMG: { menuMG: {
updateTree: false,
sublings: false, sublings: false,
children: false, children: false,
del: false, del: false,
......
...@@ -41,7 +41,6 @@ export default { ...@@ -41,7 +41,6 @@ export default {
isEdit: true, isEdit: true,
departList: [], departList: [],
dialogFormVisible: false, dialogFormVisible: false,
// msg: '',
userManageForm: this.$deep_clone(userForm), userManageForm: this.$deep_clone(userForm),
userDetailVisible: false, userDetailVisible: false,
userDetailTitle: '用户详情', userDetailTitle: '用户详情',
...@@ -154,14 +153,8 @@ export default { ...@@ -154,14 +153,8 @@ export default {
} }
}, },
mounted() { mounted() {
// console.log(parseInt(this.$client_height()))
this.findUserList() this.findUserList()
this.getRoleOptions() this.getRoleOptions()
// findDepartTree.req().then(res => {
// console.log(res)
// this.departList = res
// console.log(this.userForm)
// })
this.getdepartData() this.getdepartData()
}, },
watch: { watch: {
...@@ -214,47 +207,30 @@ export default { ...@@ -214,47 +207,30 @@ export default {
}, },
// 新增更新用户接口请求 // 新增更新用户接口请求
updateUser_Post(params) { updateUser_Post(params) {
if (params) { updateUser.req(params).then(res => {
updateUser.req(params).then(res => { this.message('操作成功', 'success')
console.log(res) this.dialogFormVisible = !this.dialogFormVisible
this.message('操作成功', 'success') this.findUserList()
this.dialogFormVisible = !this.dialogFormVisible }).catch(message => {
this.findUserList() this.message(message, 'error')
}).catch(message => { })
console.log(message)
this.message(message, 'error')
})
}
}, },
// 删除用户接口 // 删除用户接口
batcheDel(params) { batcheDel(params) {
if (params) { batcheDelUser.req({ ids: params }).then(res => {
batcheDelUser.req({ ids: params }).then(res => { this.findUserList()
this.findUserList() })
})
} else {
console.log('无数据!')
}
}, },
// 删除、禁用、启用接口f // 删除、禁用、启用接口f
operatUser(params) { operatUser(params) {
if (params) { operatUser.req(params).then(res => {
operatUser.req(params).then(res => { (params.state === 2) && this.findUserList()
if (params.state === 2) { })
this.findUserList()
}
})
} else {
console.log('无数据!')
}
}, },
// 接受子组件传递的值 // 接受子组件传递的值
handleUserFormData(isEdit, params) { handleUserFormData(isEdit, params) {
if (params) { params && this.updateUser_Post(params)
this.updateUser_Post(params) !params && (this.dialogFormVisible = !this.dialogFormVisible)
} else {
this.dialogFormVisible = !this.dialogFormVisible
}
}, },
// 新增按钮 // 新增按钮
createUser() { createUser() {
...@@ -285,7 +261,7 @@ export default { ...@@ -285,7 +261,7 @@ export default {
this.userManageForm = this.$deep_clone(row) this.userManageForm = this.$deep_clone(row)
}) })
this.dialogFormVisible = !this.dialogFormVisible this.dialogFormVisible = !this.dialogFormVisible
this.isEdit = this.isEdit this.isEdit = true
}, },
// 获取选中的行 // 获取选中的行
handleSelectionChange(val, row) { handleSelectionChange(val, row) {
...@@ -307,7 +283,6 @@ export default { ...@@ -307,7 +283,6 @@ export default {
this.message('删除成功', 'success') this.message('删除成功', 'success')
}).catch(() => { }).catch(() => {
console.log('error') console.log('error')
// this.message('取消删除', 'info')
}) })
} }
}, },
...@@ -334,11 +309,10 @@ export default { ...@@ -334,11 +309,10 @@ export default {
this.operatUser({ id: rows[index].id, state: 2 }) this.operatUser({ id: rows[index].id, state: 2 })
this.message('成功删除该用户', 'success') this.message('成功删除该用户', 'success')
}).catch(() => { }).catch(() => {
// this.message('取消删除', 'info') console.log('error')
}) })
}, },
findRolesName(params) { findRolesName(params) {
// console.log(userForm.roleList)
var nameArray = [] var nameArray = []
const userRoles = params.split(',') const userRoles = params.split(',')
userRoles.forEach(userItem => { userRoles.forEach(userItem => {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!