Commit 2bea3649 by liwk

修改菜单组件

1 parent a9d6bb18
...@@ -70,7 +70,7 @@ export default { ...@@ -70,7 +70,7 @@ export default {
} }
if (this.value.form.createTime !== undefined) { if (this.value.form.createTime !== undefined) {
this.value.form.createTime = timeTip this.value.form.createTime = timeTip
this.value.form.changeTime = timeTip this.value.form.updateTime = timeTip
} }
} }
} }
......
...@@ -22,11 +22,11 @@ ...@@ -22,11 +22,11 @@
:disabled="i.disabled"> :disabled="i.disabled">
</gl-switch> </gl-switch>
<gl-input <gl-input
:ref='i.value'
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">{{errText}}</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>
...@@ -41,19 +41,21 @@ ...@@ -41,19 +41,21 @@
center> center>
<div style="text-align:center">确定是否要删除</div> <div style="text-align:center">确定是否要删除</div>
<span slot="footer"> <span slot="footer">
<gl-button @click="cancel">取 消</gl-button> <gl-button @click="delTip(false)">取 消</gl-button>
<gl-button type="primary" @click="delData">确 定</gl-button> <gl-button type="primary" @click="delData">确 定</gl-button>
</span> </span>
</gl-dialog> </gl-dialog>
</div> </div>
</template> </template>
<script type='text/ecmascript-6'> <script type='text/ecmascript-6'>
import { delDepartment, delMenu, editMenu } from '@/api/api' import { delDepartment, delMenu, editMenu, addMenu } from '@/api/api'
export default { export default {
name: 'rightForm', name: 'rightForm',
data() { data() {
return { return {
dialog: false dialog: false,
err: false,
errText: this.isDepart ? '请填写部门名称' : '请填写列表名称'
} }
}, },
props: { props: {
...@@ -65,69 +67,129 @@ export default { ...@@ -65,69 +67,129 @@ export default {
isDepart: Boolean isDepart: Boolean
}, },
watch: { watch: {
}, 'value.form.urlName'(val) {
mounted() { if (val !== '') this.err = false
},
'value.form.name'(val) {
if (val !== '') this.err = false
}
}, },
methods: { methods: {
getMenuObj(obj = {}) {
for (const key in this.value.form) {
obj[key] = this.value.form[key]
}
if (!this.isDepart) delete obj.name
return obj
},
// 删除 // 删除
delData() { delData() {
delete this.value.form['name'] const obj = this.getMenuObj()
console.log(this.value.form) obj.isHidden = this.value.form.isHidden === true ? 0 : 1
this.isDepart this.isDepart
? delDepartment.req(this.value.form).then(res => { ? delDepartment.req(obj).then(res => {
this.$notify({ this.delTip(true)
title: '删除成功',
type: 'success'
})
this.dialog = false
this.value.showDetails = false
}).catch(err => { }).catch(err => {
console.log(err) console.log(err)
this.delErrTip()
}) })
: delMenu.req(this.value.form).then(res => { : delMenu.req(obj).then(res => {
console.log(res) this.delTip(true)
this.$notify({
title: '删除成功',
type: 'success'
})
this.dialog = false
this.value.showDetails = false
}).catch(err => { }).catch(err => {
console.log(err) console.log(err)
this.delErrTip()
}) })
}, },
cancel() { delTip(val) {
if (val) {
const parent = this.value.node.parent
const children = parent.data.children || parent.data
const index = children.findIndex(d => d.id === this.value.data.id)
children.splice(index, 1)
this.$notify({
title: '删除成功',
type: 'success'
})
this.value.showDetails = false
} else {
this.$notify({
title: '已取消',
type: 'info'
})
}
this.dialog = false this.dialog = false
},
delErrTip() {
this.$notify({ this.$notify({
title: '已取消', title: '删除失败',
type: 'info' type: 'error'
}) })
this.dialog = false
}, },
// 保存修改 // 保存修改
submit() { submit() {
delete this.value.form['name'] const treeData = this.value.allNode
if (this.value.form[this.form[0].value] !== '' && this.value.form[this.form[0].value] !== null) { if (this.value.form[this.form[0].value] !== '' && this.value.form[this.form[0].value] !== null) {
const obj = this.getMenuObj()
obj.updateTime = new Date().getTime()
obj.isHidden = this.value.form.isHidden === true ? 0 : 1
console.log(obj)
// 添加同级 // 添加同级
if (this.value.sublings) { if (this.value.sublings) {
console.log(1) if (treeData.parent === '#') {
obj.parentId = 0
} else {
obj.parentId = treeData.parent
}
this.addData(obj)
// 添加子级 // 添加子级
} else if (this.value.children) { } else if (this.value.children) {
console.log(2) obj.parentId = treeData.id
this.addData(obj)
// 修改 // 修改
} else { } else {
editMenu.req(this.value.form).then(res => { obj.createTime = this.unix(this.value.form.createTime)
editMenu.req(obj).then(res => {
console.log(res) console.log(res)
this.$notify({ this.Tip(true)
title: '操作成功',
type: 'success'
})
}).catch(err => { }).catch(err => {
console.log(err) console.log(err)
this.Tip(false)
}) })
} }
} else {
this.err = true
}
},
unix(time) {
time = time.substring(0, 19)
time = time.replace(/-/g, '/')
return new Date(time).getTime()
},
addData(obj) {
obj.createTime = new Date().getTime()
if (!this.isDepart) {
addMenu.req(obj).then(res => {
console.log(res)
this.Tip(true)
}).catch(err => {
console.log(err)
this.Tip(false)
})
}
},
Tip(val) {
if (val) {
this.$notify({
title: '操作成功',
type: 'success'
})
this.value.showDetails = false this.value.showDetails = false
} else { } else {
this.$refs.urlName[0].$el.classList.add('err') this.$notify({
title: '操作失败',
type: 'error'
})
} }
} }
} }
...@@ -141,9 +203,7 @@ export default { ...@@ -141,9 +203,7 @@ export default {
.el-form-item{ .el-form-item{
margin-bottom: 15px; margin-bottom: 15px;
} }
.err::after{ .err{
content: '请填写列表名称';
display: block;
color: red; color: red;
} }
</style> </style>
\ No newline at end of file \ No newline at end of file
...@@ -28,6 +28,7 @@ export default { ...@@ -28,6 +28,7 @@ export default {
allNode: null, allNode: null,
data: [], data: [],
form: { form: {
id: 0,
urlName: '', urlName: '',
hostName: '', hostName: '',
openStyle: '新系统', openStyle: '新系统',
...@@ -42,7 +43,6 @@ export default { ...@@ -42,7 +43,6 @@ export default {
updateTime: null, updateTime: null,
grade: 0, grade: 0,
iconUrl: '', iconUrl: '',
id: 0,
lastOperatorId: 0, lastOperatorId: 0,
lastOperatorName: '', lastOperatorName: '',
parentId: 0, parentId: 0,
...@@ -82,7 +82,7 @@ export default { ...@@ -82,7 +82,7 @@ export default {
label: '菜单' label: '菜单'
}, },
{ {
value: '选项3', value: 2,
label: '按钮' label: '按钮'
} }
] ]
...@@ -115,7 +115,10 @@ export default { ...@@ -115,7 +115,10 @@ export default {
this.menuMG.del = true this.menuMG.del = true
this.menuMG.push = false this.menuMG.push = false
findMenuById.req({ id: data.id }).then(res => { findMenuById.req({ id: data.id }).then(res => {
console.log(res) // for (const key in res) {
// console.log(res[key], typeof res[key], key)
// }
// console.log(this.menuMG.allNode, this.menuMG.node)
for (const key in this.menuMG.form) { for (const key in this.menuMG.form) {
if (key === 'isHidden') { if (key === 'isHidden') {
this.menuMG.form[key] = res[key] === 0 this.menuMG.form[key] = res[key] === 0
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!