From 9c094a1fe3e1ae3dadef6433f8401818fe2b8304 Mon Sep 17 00:00:00 2001 From: lzhe <lzhe@example.com> Date: 星期五, 21 六月 2024 10:53:43 +0800 Subject: [PATCH] 1 --- src/views/setting/dic/index.vue | 543 +++++++++++++++++++++++++++++------------------------- 1 files changed, 290 insertions(+), 253 deletions(-) diff --git a/src/views/setting/dic/index.vue b/src/views/setting/dic/index.vue index d09db7f..3e9bdfc 100644 --- a/src/views/setting/dic/index.vue +++ b/src/views/setting/dic/index.vue @@ -6,15 +6,19 @@ <el-input placeholder="杈撳叆鍏抽敭瀛楄繘琛岃繃婊�" v-model="dicFilterText" clearable></el-input> </el-header> <el-main class="nopadding"> - <el-tree ref="dic" class="menu" node-key="id" :data="dicList" :props="dicProps" :highlight-current="true" :expand-on-click-node="false" :filter-node-method="dicFilterNode" @node-click="dicClick"> - <template #default="{node, data}"> + <el-tree :expand-on-click-node="false" ref="dic" class="menu" node-key="id" :data="dicList" + :props="dicProps" :highlight-current="true" :filter-node-method="dicFilterNode" + @node-click="dicClick"> + <template #default="{ node, data }"> <span class="custom-tree-node"> <span class="label">{{ node.label }}</span> <span class="code">{{ data.code }}</span> <span class="do"> <el-button-group> - <el-button icon="el-icon-edit" size="small" @click.stop="dicEdit(data)"></el-button> - <el-button icon="el-icon-delete" size="small" @click.stop="dicDel(node, data)"></el-button> + <el-button icon="el-icon-edit" size="small" + @click.stop="dicEdit(data)"></el-button> + <el-button icon="el-icon-delete" size="small" + @click.stop="dicDel(node, data)"></el-button> </el-button-group> </span> </span> @@ -22,7 +26,8 @@ </el-tree> </el-main> <el-footer style="height:51px;"> - <el-button type="primary" size="small" icon="el-icon-plus" style="width: 100%;" @click="addDic">瀛楀吀鍒嗙被</el-button> + <el-button type="primary" size="small" icon="el-icon-plus" style="width: 100%;" + @click="addDic">瀛楀吀鍒嗙被</el-button> </el-footer> </el-container> </el-aside> @@ -30,28 +35,33 @@ <el-header> <div class="left-panel"> <el-button type="primary" icon="el-icon-plus" @click="addInfo"></el-button> - <el-button type="danger" plain icon="el-icon-delete" :disabled="selection.length==0" @click="batch_del"></el-button> + <el-button type="danger" plain icon="el-icon-delete" :disabled="selection.length == 0" + @click="batch_del"></el-button> </div> </el-header> <el-main class="nopadding"> - <scTable ref="table" :apiObj="listApi" row-key="id" :params="listApiParams" @selection-change="selectionChange" stripe :paginationLayout="'prev, pager, next'"> + <scTable ref="table" :apiObj="listApi" row-key="id" :params="listApiParams" + @selection-change="selectionChange" stripe :paginationLayout="'prev, pager, next'"> <el-table-column type="selection" width="50"></el-table-column> <el-table-column label="" width="60"> <template #default> - <el-tag class="move" style="cursor: move;"><el-icon-d-caret style="width: 1em; height: 1em;"/></el-tag> + <el-tag class="move" style="cursor: move;"><el-icon-d-caret + style="width: 1em; height: 1em;" /></el-tag> </template> </el-table-column> <el-table-column label="鍚嶇О" prop="name" width="150"></el-table-column> <el-table-column label="閿��" prop="key" width="150"></el-table-column> <el-table-column label="鏄惁鏈夋晥" prop="yx" width="100"> <template #default="scope"> - <el-switch v-model="scope.row.yx" @change="changeSwitch($event, scope.row)" :loading="scope.row.$switch_yx" active-value="1" inactive-value="0"></el-switch> + <el-switch v-model="scope.row.yx" @change="changeSwitch($event, scope.row)" + :loading="scope.row.$switch_yx" active-value="1" inactive-value="0"></el-switch> </template> </el-table-column> <el-table-column label="鎿嶄綔" fixed="right" align="right" width="120"> <template #default="scope"> <el-button-group> - <el-button text type="primary" size="small" @click="table_edit(scope.row, scope.$index)">缂栬緫</el-button> + <el-button text type="primary" size="small" + @click="table_edit(scope.row, scope.$index)">缂栬緫</el-button> <el-popconfirm title="纭畾鍒犻櫎鍚楋紵" @confirm="table_del(scope.row, scope.$index)"> <template #reference> <el-button text type="primary" size="small">鍒犻櫎</el-button> @@ -65,269 +75,296 @@ </el-container> </el-container> - <dic-dialog v-if="dialog.dic" ref="dicDialog" @success="handleDicSuccess" @closed="dialog.dic=false"></dic-dialog> + <dic-dialog v-if="dialog.dic" ref="dicDialog" @success="handleDicSuccess" @closed="dialog.dic = false"></dic-dialog> - <list-dialog v-if="dialog.list" ref="listDialog" @success="handleListSuccess" @closed="dialog.list=false"></list-dialog> + <list-dialog v-if="dialog.list" ref="listDialog" @success="handleListSuccess" + @closed="dialog.list = false"></list-dialog> </template> <script> - import dicDialog from './dic' - import listDialog from './list' - import Sortable from 'sortablejs' +import dicDialog from './dic' +import listDialog from './list' +import Sortable from 'sortablejs' - export default { - name: 'dic', - components: { - dicDialog, - listDialog - }, - data() { - return { - dialog: { - dic: false, - info: false - }, - showDicloading: true, - dicList: [], - dicFilterText: '', - dicProps: { - label: 'name' - }, - listApi: null, - listApiParams: {}, - selection: [] +export default { + name: 'dic', + components: { + dicDialog, + listDialog + }, + data() { + return { + dialog: { + dic: false, + info: false + }, + showDicloading: true, + dicList: [], + dicFilterText: '', + dicProps: { + label: 'name' + }, + listApi: null, + listApiParams: {}, + selection: [] + } + }, + watch: { + dicFilterText(val) { + this.$refs.dic.filter(val); + } + }, + mounted() { + this.getDic() + this.rowDrop() + }, + methods: { + //鍔犺浇鏍戞暟鎹� + async getDic() { + var res = await this.$API.system.dic.tree.get(); + this.showDicloading = false; + this.dicList = res.data; + //鑾峰彇绗竴涓妭鐐�,璁剧疆閫変腑 & 鍔犺浇鏄庣粏鍒楄〃 + var firstNode = this.dicList[0]; + if (firstNode) { + this.$nextTick(() => { + this.$refs.dic.setCurrentKey(firstNode.id) + }) + this.listApiParams = { + code: firstNode.code + } + this.listApi = this.$API.system.dic.list; } }, - watch: { - dicFilterText(val) { - this.$refs.dic.filter(val); - } + //鏍戣繃婊� + dicFilterNode(value, data) { + if (!value) return true; + var targetText = data.name + data.code; + return targetText.indexOf(value) !== -1; }, - mounted() { - this.getDic() - this.rowDrop() + //鏍戝鍔� + addDic() { + this.dialog.dic = true + this.$nextTick(() => { + this.$refs.dicDialog.open() + }) }, - methods: { - //鍔犺浇鏍戞暟鎹� - async getDic(){ - var res = await this.$API.system.dic.tree.get(); - this.showDicloading = false; - this.dicList = res.data; - //鑾峰彇绗竴涓妭鐐�,璁剧疆閫変腑 & 鍔犺浇鏄庣粏鍒楄〃 - var firstNode = this.dicList[0]; - if(firstNode){ - this.$nextTick(() => { - this.$refs.dic.setCurrentKey(firstNode.id) - }) - this.listApiParams = { - code: firstNode.code - } - this.listApi = this.$API.system.dic.list; - } - }, - //鏍戣繃婊� - dicFilterNode(value, data){ - if (!value) return true; - var targetText = data.name + data.code; - return targetText.indexOf(value) !== -1; - }, - //鏍戝鍔� - addDic(){ - this.dialog.dic = true - this.$nextTick(() => { - this.$refs.dicDialog.open() - }) - }, - //缂栬緫鏍� - dicEdit(data){ - this.dialog.dic = true - this.$nextTick(() => { - var editNode = this.$refs.dic.getNode(data.id); - var editNodeParentId = editNode.level==1?undefined:editNode.parent.data.id - data.parentId = editNodeParentId - this.$refs.dicDialog.open('edit').setData(data) - }) - }, - //鏍戠偣鍑讳簨浠� - dicClick(data){ - this.$refs.table.reload({ - code: data.code - }) - }, - //鍒犻櫎鏍� - dicDel(node, data){ - this.$confirm(`纭畾鍒犻櫎 ${data.name} 椤瑰悧锛焋, '鎻愮ず', { - type: 'warning' - }).then(() => { - this.showDicloading = true; + //缂栬緫鏍� + dicEdit(data) { + this.dialog.dic = true + this.$nextTick(() => { + var editNode = this.$refs.dic.getNode(data.id); + var editNodeParentId = editNode.level == 1 ? undefined : editNode.parent.data.id + data.parentId = editNodeParentId + this.$refs.dicDialog.open('edit').setData(data) + }) + }, + //鏍戠偣鍑讳簨浠� + dicClick(data) { + this.$refs.table.reload({ + code: data.code + }) + }, + //鍒犻櫎鏍� + dicDel(node, data) { + this.$confirm(`纭畾鍒犻櫎 ${data.name} 椤瑰悧锛焋, '鎻愮ず', { + type: 'warning' + }).then(() => { + this.showDicloading = true; - //鍒犻櫎鑺傜偣鏄惁涓洪珮浜綋鍓� 鏄殑璇� 璁剧疆绗竴涓妭鐐归珮浜� - var dicCurrentKey = this.$refs.dic.getCurrentKey(); - this.$refs.dic.remove(data.id) - if(dicCurrentKey == data.id){ - var firstNode = this.dicList[0]; - if(firstNode){ - this.$refs.dic.setCurrentKey(firstNode.id); - this.$refs.table.upData({ - code: firstNode.code - }) - }else{ - this.listApi = null; - this.$refs.table.tableData = [] - } - } - - this.showDicloading = false; - this.$message.success("鎿嶄綔鎴愬姛") - }).catch(() => { - - }) - }, - //琛屾嫋鎷� - rowDrop(){ - const _this = this - const tbody = this.$refs.table.$el.querySelector('.el-table__body-wrapper tbody') - Sortable.create(tbody, { - handle: ".move", - animation: 300, - ghostClass: "ghost", - onEnd({ newIndex, oldIndex }) { - const tableData = _this.$refs.table.tableData - const currRow = tableData.splice(oldIndex, 1)[0] - tableData.splice(newIndex, 0, currRow) - _this.$message.success("鎺掑簭鎴愬姛") - } - }) - }, - //娣诲姞鏄庣粏 - addInfo(){ - this.dialog.list = true - this.$nextTick(() => { - var dicCurrentKey = this.$refs.dic.getCurrentKey(); - const data = { - dic: dicCurrentKey - } - this.$refs.listDialog.open().setData(data) - }) - }, - //缂栬緫鏄庣粏 - table_edit(row){ - this.dialog.list = true - this.$nextTick(() => { - this.$refs.listDialog.open('edit').setData(row) - }) - }, - //鍒犻櫎鏄庣粏 - async table_del(row, index){ - var reqData = {id: row.id} - var res = await this.$API.demo.post.post(reqData); - if(res.code == 200){ - this.$refs.table.tableData.splice(index, 1); - this.$message.success("鍒犻櫎鎴愬姛") - }else{ - this.$alert(res.message, "鎻愮ず", {type: 'error'}) - } - }, - //鎵归噺鍒犻櫎 - async batch_del(){ - this.$confirm(`纭畾鍒犻櫎閫変腑鐨� ${this.selection.length} 椤瑰悧锛焋, '鎻愮ず', { - type: 'warning' - }).then(() => { - const loading = this.$loading(); - this.selection.forEach(item => { - this.$refs.table.tableData.forEach((itemI, indexI) => { - if (item.id === itemI.id) { - this.$refs.table.tableData.splice(indexI, 1) - } - }) - }) - loading.close(); - this.$message.success("鎿嶄綔鎴愬姛") - }).catch(() => { - - }) - }, - //鎻愪氦鏄庣粏 - saveList(){ - this.$refs.listDialog.submit(async (formData) => { - this.isListSaveing = true; - var res = await this.$API.demo.post.post(formData); - this.isListSaveing = false; - if(res.code == 200){ - //杩欓噷閫夋嫨鍒锋柊鏁翠釜琛ㄦ牸 OR 鎻掑叆/缂栬緫鐜版湁琛ㄦ牸鏁版嵁 - this.listDialogVisible = false; - this.$message.success("鎿嶄綔鎴愬姛") - }else{ - this.$alert(res.message, "鎻愮ず", {type: 'error'}) - } - }) - }, - //琛ㄦ牸閫夋嫨鍚庡洖璋冧簨浠� - selectionChange(selection){ - this.selection = selection; - }, - //琛ㄦ牸鍐呭紑鍏充簨浠� - changeSwitch(val, row){ - //1.杩樺師鏁版嵁 - row.yx = row.yx == '1'?'0':'1' - //2.鎵ц鍔犺浇 - row.$switch_yx = true; - //3.绛夊緟鎺ュ彛杩斿洖鍚庢敼鍙樺�� - setTimeout(()=>{ - delete row.$switch_yx; - row.yx = val; - this.$message.success(`鎿嶄綔鎴愬姛id:${row.id} val:${val}`) - }, 500) - }, - //鏈湴鏇存柊鏁版嵁 - handleDicSuccess(data, mode){ - if(mode=='add'){ - data.id = new Date().getTime() - if(this.dicList.length > 0){ + //鍒犻櫎鑺傜偣鏄惁涓洪珮浜綋鍓� 鏄殑璇� 璁剧疆绗竴涓妭鐐归珮浜� + var dicCurrentKey = this.$refs.dic.getCurrentKey(); + this.$refs.dic.remove(data.id) + if (dicCurrentKey == data.id) { + var firstNode = this.dicList[0]; + if (firstNode) { + this.$refs.dic.setCurrentKey(firstNode.id); this.$refs.table.upData({ - code: data.code + code: firstNode.code }) - }else{ - this.listApiParams = { - code: data.code + } else { + this.listApi = null; + this.$refs.table.tableData = [] + } + } + + this.showDicloading = false; + this.$message.success("鎿嶄綔鎴愬姛") + }).catch(() => { + + }) + }, + //琛屾嫋鎷� + rowDrop() { + const _this = this + const tbody = this.$refs.table.$el.querySelector('.el-table__body-wrapper tbody') + Sortable.create(tbody, { + handle: ".move", + animation: 300, + ghostClass: "ghost", + onEnd({ newIndex, oldIndex }) { + const tableData = _this.$refs.table.tableData + const currRow = tableData.splice(oldIndex, 1)[0] + tableData.splice(newIndex, 0, currRow) + _this.$message.success("鎺掑簭鎴愬姛") + } + }) + }, + //娣诲姞鏄庣粏 + addInfo() { + this.dialog.list = true + this.$nextTick(() => { + var dicCurrentKey = this.$refs.dic.getCurrentKey(); + const data = { + dic: dicCurrentKey + } + this.$refs.listDialog.open().setData(data) + }) + }, + //缂栬緫鏄庣粏 + table_edit(row) { + this.dialog.list = true + this.$nextTick(() => { + this.$refs.listDialog.open('edit').setData(row) + }) + }, + //鍒犻櫎鏄庣粏 + async table_del(row, index) { + var reqData = { id: row.id } + var res = await this.$API.demo.post.post(reqData); + if (res.code == 200) { + this.$refs.table.tableData.splice(index, 1); + this.$message.success("鍒犻櫎鎴愬姛") + } else { + this.$alert(res.message, "鎻愮ず", { type: 'error' }) + } + }, + //鎵归噺鍒犻櫎 + async batch_del() { + this.$confirm(`纭畾鍒犻櫎閫変腑鐨� ${this.selection.length} 椤瑰悧锛焋, '鎻愮ず', { + type: 'warning' + }).then(() => { + const loading = this.$loading(); + this.selection.forEach(item => { + this.$refs.table.tableData.forEach((itemI, indexI) => { + if (item.id === itemI.id) { + this.$refs.table.tableData.splice(indexI, 1) } - this.listApi = this.$API.dic.info; - } - this.$refs.dic.append(data, data.parentId[0]) - this.$refs.dic.setCurrentKey(data.id) - }else if(mode=='edit'){ - var editNode = this.$refs.dic.getNode(data.id); - //鍒ゆ柇鏄惁绉诲姩锛� - var editNodeParentId = editNode.level==1?undefined:editNode.parent.data.id - if(editNodeParentId != data.parentId){ - var obj = editNode.data; - this.$refs.dic.remove(data.id) - this.$refs.dic.append(obj, data.parentId[0]) - } - Object.assign(editNode.data, data) - } - }, - //鏈湴鏇存柊鏁版嵁 - handleListSuccess(data, mode){ - if(mode=='add'){ - data.id = new Date().getTime() - this.$refs.table.tableData.push(data) - }else if(mode=='edit'){ - this.$refs.table.tableData.filter(item => item.id===data.id ).forEach(item => { - Object.assign(item, data) }) + }) + loading.close(); + this.$message.success("鎿嶄綔鎴愬姛") + }).catch(() => { + + }) + }, + //鎻愪氦鏄庣粏 + saveList() { + this.$refs.listDialog.submit(async (formData) => { + this.isListSaveing = true; + var res = await this.$API.demo.post.post(formData); + this.isListSaveing = false; + if (res.code == 200) { + //杩欓噷閫夋嫨鍒锋柊鏁翠釜琛ㄦ牸 OR 鎻掑叆/缂栬緫鐜版湁琛ㄦ牸鏁版嵁 + this.listDialogVisible = false; + this.$message.success("鎿嶄綔鎴愬姛") + } else { + this.$alert(res.message, "鎻愮ず", { type: 'error' }) } + }) + }, + //琛ㄦ牸閫夋嫨鍚庡洖璋冧簨浠� + selectionChange(selection) { + this.selection = selection; + }, + //琛ㄦ牸鍐呭紑鍏充簨浠� + changeSwitch(val, row) { + //1.杩樺師鏁版嵁 + row.yx = row.yx == '1' ? '0' : '1' + //2.鎵ц鍔犺浇 + row.$switch_yx = true; + //3.绛夊緟鎺ュ彛杩斿洖鍚庢敼鍙樺�� + setTimeout(() => { + delete row.$switch_yx; + row.yx = val; + this.$message.success(`鎿嶄綔鎴愬姛id:${row.id} val:${val}`) + }, 500) + }, + //鏈湴鏇存柊鏁版嵁 + handleDicSuccess(data, mode) { + if (mode == 'add') { + data.id = new Date().getTime() + if (this.dicList.length > 0) { + this.$refs.table.upData({ + code: data.code + }) + } else { + this.listApiParams = { + code: data.code + } + this.listApi = this.$API.dic.info; + } + this.$refs.dic.append(data, data.parentId[0]) + this.$refs.dic.setCurrentKey(data.id) + } else if (mode == 'edit') { + var editNode = this.$refs.dic.getNode(data.id); + //鍒ゆ柇鏄惁绉诲姩锛� + var editNodeParentId = editNode.level == 1 ? undefined : editNode.parent.data.id + if (editNodeParentId != data.parentId) { + var obj = editNode.data; + this.$refs.dic.remove(data.id) + this.$refs.dic.append(obj, data.parentId[0]) + } + Object.assign(editNode.data, data) + } + }, + //鏈湴鏇存柊鏁版嵁 + handleListSuccess(data, mode) { + if (mode == 'add') { + data.id = new Date().getTime() + this.$refs.table.tableData.push(data) + } else if (mode == 'edit') { + this.$refs.table.tableData.filter(item => item.id === data.id).forEach(item => { + Object.assign(item, data) + }) } } } +} </script> <style scoped> - .menu:deep(.el-tree-node__label) {display: flex;flex: 1;height:100%;} - .custom-tree-node {display: flex;flex: 1;align-items: center;justify-content: space-between;font-size: 14px;padding-right: 24px;height:100%;} - .custom-tree-node .code {font-size: 12px;color: #999;} - .custom-tree-node .do {display: none;} - .custom-tree-node:hover .code {display: none;} - .custom-tree-node:hover .do {display: inline-block;} +.menu:deep(.el-tree-node__label) { + display: flex; + flex: 1; + height: 100%; +} + +.custom-tree-node { + display: flex; + flex: 1; + align-items: center; + justify-content: space-between; + font-size: 14px; + padding-right: 24px; + height: 100%; +} + +.custom-tree-node .code { + font-size: 12px; + color: #999; +} + +.custom-tree-node .do { + display: none; +} + +.custom-tree-node:hover .code { + display: none; +} + +.custom-tree-node:hover .do { + display: inline-block; +} </style> -- Gitblit v1.9.3