From 236fdf92ecb6ff876d400f6c360efca8ab085f5c Mon Sep 17 00:00:00 2001 From: odc.xiaohui <xiaohui@Q1> Date: 星期四, 30 十一月 2023 09:04:38 +0800 Subject: [PATCH] 修改青羊后台部门bug --- vue.config.js | 2 src/views/exam/personalRandomTemplate/edit.vue | 30 ++++++- src/components/Cascader/index.vue | 169 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 194 insertions(+), 7 deletions(-) diff --git a/src/components/Cascader/index.vue b/src/components/Cascader/index.vue new file mode 100644 index 0000000..c470092 --- /dev/null +++ b/src/components/Cascader/index.vue @@ -0,0 +1,169 @@ +<template> + <el-cascader + ref="cascaderEle" + :options="optionList" + :props="config" + collapse-tags + :filterable="filterable" + :size="size" + :style="{width: width + 'px'}" + v-model="choiceEle" + @change="selectChange" + clearable> + </el-cascader> +</template> + +<script> +/** + * options [{ value: "", label: "", childList: []}] + * checkStrictly 璁剧疆鐖跺瓙鑺傜偣鍙栨秷閫変腑鍏宠仈 + * 鑾峰彇閫変腑缁撴灉 change浜嬩欢 + * all 鏄叏閮� + * size 澶у皬 + * filterable 鏄惁鏀寔绛涢�� + */ +export default { + name: 'AiCascaderAll', + props: { + optionsData: { + type: Array, + default: () => { + return []; + } + }, + options: { + type: Array, + default: () => { + return []; + } + }, + width: { + type: Number, + default: 180 + }, + checkStrictly: { + type: Boolean, + default: false + }, + filterable: { + type: Boolean, + default: true + }, + size: { + type: String, + default: "mini" + } + }, + data() { + return { + optionList: [], + lastSelectedList: [], + choiceEle: [], + allLength: 0, + allOptions: [{ value: "all", label: "鍏ㄩ儴", childList: null }], + config: { + multiple: true, + checkStrictly: false + } + } + }, + watch: { + options() { + this.setData(); + }, + optionsData() { + this.setData(); + } + }, + mounted() { + this.setData(); + this.config.checkStrictly = this.checkStrictly; + }, + methods: { + setData() { + this.optionList = []; + if (this.optionsData.length > 0) { + this.choiceEle = this.optionsData + } + + this.optionList = this.allOptions.concat(this.options); + // this.loopSelectData(this.options); + console.log(this.options) + + console.log(this.optionsData) + // 璁板綍涓嬪叏閮ㄩ�変腑鏃剁殑涓暟 + this.allLength = this.choiceEle.length; + this.lastSelectedList = [...this.choiceEle]; + this.sendInfo(); + }, + selectChange(val) { + let lastHasAll = this.lastSelectedList.find(arr => { + return arr[0] === 'all'; + }); + let nowHasAll = val.find(arr => { + return arr[0] === 'all'; + }); + if (lastHasAll && !nowHasAll) { + // 鐐瑰嚮鍙栨秷浜� 鍏ㄩ�� + // this.clearCascader(); + this.choiceEle = []; + this.lastSelectedList = []; + this.$nextTick(() => { + this.sendInfo(); + }); + return; + } + if (!lastHasAll && nowHasAll) { + this.choiceEle = []; + // 鐐瑰嚮浜� 鍏ㄩ�� + this.loopSelectData(this.optionList); + this.lastSelectedList = [...this.choiceEle]; + this.$nextTick(() => { + this.sendInfo(); + }); + return; + } + // 褰撶偣閫変簡闄ゅ叏閮ㄦ寜閽鐨勬墍鏈� 閫変腑鍏ㄩ儴鎸夐挳 + if (!nowHasAll && val.length === this.allLength - 1) { + this.choiceEle = [['all']].concat(this.choiceEle); + val = [['all']].concat(val); + } + // 褰撳叏閮ㄩ�夐」閮介�変腑 杩欐椂鍙栨秷浜嗛櫎鍏ㄩ儴鎸夐挳澶栫殑涓�涓� 鍘绘帀閫変腑鍏ㄩ儴鎸夐挳 + if (nowHasAll && val.length < this.allLength) { + val = val.filter(arr => { + return arr[0] !== 'all'; + }); + this.choiceEle = [...val]; + } + this.sendInfo(); + this.lastSelectedList = [...val]; + }, + loopSelectData(list, parentNode = []) { + list.length > 0 && + list.forEach((e) => { + let pNode = [...parentNode]; // 娉ㄦ剰杩欓噷蹇呴』鏄繁鎷疯礉锛屽惁鍒欎細鐢变簬寮曠敤绫诲瀷璧嬪�肩殑鏄湴鍧�锛堟寚閽堬級锛屽鑷磒arentNode鍦╬Node鏇存柊鏃讹紝鍚屾椂琚洿鏂� + if (e.children && e.children.length > 0) { + pNode.push(e.value); + // 褰撴病鏈夊叧鑱旀椂 闇�瑕佹瘡涓�绾ч兘瀛樹笅 + if (this.checkStrictly) { + this.choiceEle.push([...pNode]); + } + this.loopSelectData(e.children, pNode); + } else { + if (parentNode.length > 0) { + this.choiceEle.push([...parentNode, e.value]); + } else { + this.choiceEle.push([e.value]); + } + } + }); + }, + sendInfo() { + this.$emit('change', this.choiceEle); + } + } +}; +</script> + +<style scoped></style> + diff --git a/src/views/exam/personalRandomTemplate/edit.vue b/src/views/exam/personalRandomTemplate/edit.vue index 4d955fb..3009191 100644 --- a/src/views/exam/personalRandomTemplate/edit.vue +++ b/src/views/exam/personalRandomTemplate/edit.vue @@ -2,8 +2,12 @@ <div class="app-container"> <el-form :model="form" ref="form" label-width="200px" v-loading="formLoading" :rules="rules"> <el-form-item label="鑰冪敓锛�" prop="menuIds" required> - <el-cascader v-model="form.menuIds" :options="options" :props="props" clearable collapse-tags> - </el-cascader> +<!-- <el-cascader v-model="form.menuIds" :options="options" @change="cascaderChangeFun" :props="props" clearable collapse-tags>--> +<!-- </el-cascader>--> + <all-cascader :options="options" + :optionsData = "optionsData" + @change="cascaderChangeFun" + :width="200"></all-cascader> </el-form-item> <el-form-item label="璇剧洰锛�" prop="subjectId" required > <el-select ref="subjectIdRef" v-model="form.subjectId" placeholder="璇剧洰" multiple @@ -18,7 +22,7 @@ </el-select> </el-form-item> - <el-form-item label="鏃堕棿闄愬埗锛�""> + <el-form-item label="鏃堕棿闄愬埗锛�"> <el-date-picker v-model="form.limitDateTime" value-format="yyyy-MM-dd HH:mm:ss" type="datetimerange" range-separator="鑷�" start-placeholder="寮�濮嬫棩鏈�" end-placeholder="缁撴潫鏃ユ湡"> </el-date-picker> @@ -132,9 +136,9 @@ import examPaperApi from '@/api/examPaper' import questionApi from '@/api/question' import departmentApi from '@/api/department' - +import allCascader from '@/components/Cascader' export default { - components: { Pagination, QuestionShow }, + components: { Pagination, QuestionShow ,allCascader}, data () { return { @@ -154,6 +158,7 @@ // } }, options: [], + optionsData:[], departCascaderProps:{ multiple: true }, @@ -162,7 +167,7 @@ aggregateSource:'100', id: null, departmentIds: [], - + menuIds:[], subjectId: [], paperType: 7, limitDateTime: [], @@ -225,7 +230,9 @@ await examPaperApi.selfselect(id).then(re => { _this.form = re.response _this.form.menuIds = JSON.parse(re.response.menuIds) + _this.optionsData = _this.form.menuIds console.log(_this.form) + _this.formLoading = false }) } @@ -244,6 +251,10 @@ // this.subjectIdEvent(false) }, methods: { + cascaderChangeFun(event){ + console.log(event) + this.form.menuIds = event + }, titlejs(val){ console.log(val) let str = '' @@ -320,6 +331,13 @@ if (this.subjectIdList.length == 1){ this.form.subjectId= this.form.subjectId }; + + let lastHasAll = this.form.menuIds.find(arr => { + return arr[0] === 'all'; + }); + if (lastHasAll){ + this.form.menuIds = this.form.menuIds.slice(1) + } let op = []; for(var ele of this.form.menuIds){ op.push(ele[1]) diff --git a/vue.config.js b/vue.config.js index 43e9f92..a9437ad 100644 --- a/vue.config.js +++ b/vue.config.js @@ -19,7 +19,7 @@ hotOnly: false, proxy: { '/api': { - target: 'http://localhost:8000', + target: 'http://192.168.3.64:8000', changeOrigin: true } } -- Gitblit v1.8.0