¶Ô±ÈÐÂÎļþ |
| | |
| | | <template> |
| | | <basic-container> |
| | | <avue-crud :option="option" :table-loading="loading" :data="data" ref="crud" v-model="form" |
| | | :permission="permissionList" :before-open="beforeOpen" :before-close="beforeClose" @row-del="rowDel" |
| | | @row-save="rowSave" @search-change="searchChange" @search-reset="searchReset" |
| | | @selection-change="selectionChange" @current-change="currentChange" @size-change="sizeChange" |
| | | @refresh-change="refreshChange" @on-load="onLoad"> |
| | | <template #menu-left> |
| | | <el-button type="primary" plain |
| | | @click="reassign">éæ°ææ´¾ |
| | | </el-button> |
| | | </template> |
| | | <!-- <template #source="{ row }"> |
| | | <div style="text-align: center"> |
| | | <i :class="row.source" /> |
| | | </div> |
| | | </template> --> |
| | | </avue-crud> |
| | | </basic-container> |
| | | </template> |
| | | |
| | | <script> |
| | | import { getLazyList, remove, update, add, getMenu } from '@/api/system/menu'; |
| | | import { mapGetters } from 'vuex'; |
| | | import iconList from '@/config/iconList'; |
| | | import func from '@/utils/func'; |
| | | import { getMenuTree } from '@/api/system/menu'; |
| | | |
| | | export default { |
| | | data() { |
| | | return { |
| | | form: {}, |
| | | query: {}, |
| | | loading: true, |
| | | selectionList: [], |
| | | parentId: 0, |
| | | page: { |
| | | pageSize: 10, |
| | | currentPage: 1, |
| | | total: 0, |
| | | }, |
| | | option: { |
| | | addBtn: false, |
| | | lazy: true, |
| | | tip: false, |
| | | simplePage: true, |
| | | searchShow: true, |
| | | searchMenuSpan: 6, |
| | | dialogWidth: '60%', |
| | | tree: true, |
| | | border: true, |
| | | index: true, |
| | | selection: true, |
| | | viewBtn: true, |
| | | menuWidth: 320, |
| | | dialogClickModal: false, |
| | | column: [ |
| | | { |
| | | label: 'å建æ¶é´', |
| | | prop: 'time', |
| | | width: 300, |
| | | type: 'datetime', |
| | | search: true, |
| | | searchRange: true, |
| | | searchSpan: 8, |
| | | hide: true, |
| | | }, |
| | | { |
| | | label: 'å
³é®å', |
| | | prop: 'keyWord', |
| | | width: 300, |
| | | search: true, |
| | | searchType: 'input', |
| | | hide: true, |
| | | dicData: [ |
| | | { |
| | | label: 'æ¶å¯ç½ç¨åº', |
| | | value: 1, |
| | | }, |
| | | { |
| | | label: 'å·¥æ§ç½è½¦åºç¨åº', |
| | | value: 2, |
| | | }, |
| | | ], |
| | | }, |
| | | |
| | | { |
| | | label: 'ç¼å·', |
| | | prop: 'name', |
| | | width: 300, |
| | | }, |
| | | { |
| | | label: 'æµç¨ç±»å', |
| | | prop: 'path', |
| | | rules: [ |
| | | { |
| | | required: true, |
| | | message: '请è¾å
¥è·¯ç±å°å', |
| | | trigger: 'blur', |
| | | }, |
| | | ], |
| | | }, |
| | | { |
| | | label: 'å®ä¾ç¼å·', |
| | | type: 'tree', |
| | | }, |
| | | { |
| | | label: 'æµç¨å®ä¾å', |
| | | type: 'tree', |
| | | }, |
| | | { |
| | | label: 'æºåº', |
| | | type: 'tree', |
| | | }, |
| | | { |
| | | label: 'å建人', |
| | | type: 'tree', |
| | | }, |
| | | { |
| | | label: 'å建æ¶é´', |
| | | type: 'tree', |
| | | }, |
| | | { |
| | | label: 'å°è¾¾æ¶é´', |
| | | type: 'tree', |
| | | }, |
| | | { |
| | | label: 'å°è¾¾æè¿°', |
| | | type: 'tree', |
| | | }, |
| | | { |
| | | label: 'æä»¶', |
| | | type: 'tree', |
| | | }, |
| | | { |
| | | label: 'å°è¾¾æ¶é´', |
| | | type: 'tree', |
| | | }, |
| | | |
| | | ], |
| | | }, |
| | | data: [], |
| | | }; |
| | | }, |
| | | watch: { |
| | | 'form.category'() { |
| | | const category = func.toInt(this.form.category); |
| | | this.$refs.crud.option.column.filter(item => { |
| | | if (item.prop === 'path') { |
| | | item.rules[0].required = category === 1; |
| | | } |
| | | if (item.prop === 'isOpen') { |
| | | item.disabled = category === 2; |
| | | } |
| | | }); |
| | | }, |
| | | }, |
| | | computed: { |
| | | ...mapGetters(['userInfo', 'permission']), |
| | | permissionList() { |
| | | return { |
| | | addBtn: this.validData(this.permission.menu_add, false), |
| | | viewBtn: this.validData(this.permission.menu_view, false), |
| | | delBtn: this.validData(this.permission.menu_delete, false), |
| | | editBtn: this.validData(this.permission.menu_edit, false), |
| | | }; |
| | | }, |
| | | ids() { |
| | | let ids = []; |
| | | this.selectionList.forEach(ele => { |
| | | ids.push(ele.id); |
| | | }); |
| | | return ids.join(','); |
| | | }, |
| | | }, |
| | | methods: { |
| | | reassign () {// éæ°ææ´¾ |
| | | |
| | | }, |
| | | initData() { |
| | | getMenuTree().then(res => { |
| | | const column = this.findObject(this.option.column, 'parentId'); |
| | | column.dicData = res.data.data; |
| | | }); |
| | | }, |
| | | handleAdd(row) { |
| | | this.parentId = row.id; |
| | | const column = this.findObject(this.option.column, 'parentId'); |
| | | column.value = row.id; |
| | | column.addDisabled = true; |
| | | this.$refs.crud.rowAdd(); |
| | | }, |
| | | rowSave(row, done, loading) { |
| | | add(row).then( |
| | | res => { |
| | | // è·åæ°å¢æ°æ®çç¸å
³å段 |
| | | const data = res.data.data; |
| | | row.id = data.id; |
| | | this.$message({ |
| | | type: 'success', |
| | | message: 'æä½æå!', |
| | | }); |
| | | // æ°æ®åè°è¿è¡å·æ° |
| | | done(row); |
| | | }, |
| | | error => { |
| | | window.console.log(error); |
| | | loading(); |
| | | } |
| | | ); |
| | | }, |
| | | rowUpdate(row, index, done, loading) { |
| | | update(row).then( |
| | | () => { |
| | | this.$message({ |
| | | type: 'success', |
| | | message: 'æä½æå!', |
| | | }); |
| | | // æ°æ®åè°è¿è¡å·æ° |
| | | done(row); |
| | | }, |
| | | error => { |
| | | window.console.log(error); |
| | | loading(); |
| | | } |
| | | ); |
| | | }, |
| | | rowDel(row, index, done) { |
| | | this.$confirm('ç¡®å®å°éæ©æ°æ®å é¤?', { |
| | | confirmButtonText: 'ç¡®å®', |
| | | cancelButtonText: 'åæ¶', |
| | | type: 'warning', |
| | | }) |
| | | .then(() => { |
| | | return remove(row.id); |
| | | }) |
| | | .then(() => { |
| | | this.$message({ |
| | | type: 'success', |
| | | message: 'æä½æå!', |
| | | }); |
| | | // æ°æ®åè°è¿è¡å·æ° |
| | | done(row); |
| | | }); |
| | | }, |
| | | handleDelete() { |
| | | if (this.selectionList.length === 0) { |
| | | this.$message.warning('è¯·éæ©è³å°ä¸æ¡æ°æ®'); |
| | | return; |
| | | } |
| | | this.$confirm('ç¡®å®å°éæ©æ°æ®å é¤?', { |
| | | confirmButtonText: 'ç¡®å®', |
| | | cancelButtonText: 'åæ¶', |
| | | type: 'warning', |
| | | }) |
| | | .then(() => { |
| | | return remove(this.ids); |
| | | }) |
| | | .then(() => { |
| | | // å·æ°è¡¨æ ¼æ°æ®å¹¶éè½½ |
| | | this.data = []; |
| | | this.parentId = 0; |
| | | this.$refs.crud.refreshTable(); |
| | | this.$refs.crud.toggleSelection(); |
| | | // è¡¨æ ¼æ°æ®éè½½ |
| | | this.onLoad(this.page); |
| | | this.$message({ |
| | | type: 'success', |
| | | message: 'æä½æå!', |
| | | }); |
| | | }); |
| | | }, |
| | | searchReset() { |
| | | this.query = {}; |
| | | this.parentId = 0; |
| | | this.onLoad(this.page); |
| | | }, |
| | | searchChange(params, done) { |
| | | this.query = params; |
| | | this.parentId = ''; |
| | | this.page.currentPage = 1; |
| | | this.onLoad(this.page, params); |
| | | done(); |
| | | }, |
| | | selectionChange(list) { |
| | | this.selectionList = list; |
| | | }, |
| | | selectionClear() { |
| | | this.selectionList = []; |
| | | this.$refs.crud.toggleSelection(); |
| | | }, |
| | | beforeOpen(done, type) { |
| | | if (['add', 'edit'].includes(type)) { |
| | | this.initData(); |
| | | } |
| | | if (['edit', 'view'].includes(type)) { |
| | | getMenu(this.form.id).then(res => { |
| | | this.form = Object.assign(res.data.data, { |
| | | hasChildren: this.form.hasChildren, |
| | | }); |
| | | }); |
| | | } |
| | | done(); |
| | | }, |
| | | beforeClose(done) { |
| | | this.parentId = ''; |
| | | const column = this.findObject(this.option.column, 'parentId'); |
| | | column.value = ''; |
| | | column.addDisabled = false; |
| | | done(); |
| | | }, |
| | | currentChange(currentPage) { |
| | | this.page.currentPage = currentPage; |
| | | }, |
| | | sizeChange(pageSize) { |
| | | this.page.pageSize = pageSize; |
| | | }, |
| | | refreshChange() { |
| | | this.onLoad(this.page, this.query); |
| | | }, |
| | | onLoad(page, params = {}) { |
| | | this.loading = true; |
| | | getLazyList(this.parentId, Object.assign(params, this.query)).then(res => { |
| | | this.data = res.data.data; |
| | | this.loading = false; |
| | | this.selectionClear(); |
| | | }); |
| | | }, |
| | | treeLoad(tree, treeNode, resolve) { |
| | | const parentId = tree.id; |
| | | // getLazyList(parentId).then(res => { |
| | | // resolve(res.data.data); |
| | | // }); |
| | | }, |
| | | }, |
| | | }; |
| | | </script> |
| | | |
| | | <style></style> |