Commit 80aaf3aa authored by lei's avatar lei

fix:权重

parent 3ec57629
...@@ -2,7 +2,7 @@ import request from '@/utils/request' ...@@ -2,7 +2,7 @@ import request from '@/utils/request'
// 获取信息分类数据 // 获取信息分类数据
export function getAllCategory(params) { export function getAllCategory(params) {
return request({ return request({
url: '/api/informationClass/findAllInformationClass', url: '/api/informationClass/findInformationClassByPidTree',
method: 'get', method: 'get',
params params
}) })
...@@ -12,7 +12,7 @@ export function addAssignWeight(data) { ...@@ -12,7 +12,7 @@ export function addAssignWeight(data) {
return request({ return request({
url: '/api/tabAssignWeight/insertWeight', url: '/api/tabAssignWeight/insertWeight',
method: 'post', method: 'post',
data, data
}) })
} }
export function showAssignWeight(params) { export function showAssignWeight(params) {
......
This diff is collapsed.
...@@ -191,9 +191,44 @@ import { ...@@ -191,9 +191,44 @@ import {
import { reqInformationTreeList, reqAllInfoTreeList } from '@/api/treeMenus.js' import { reqInformationTreeList, reqAllInfoTreeList } from '@/api/treeMenus.js'
import Treeselect from '@riophae/vue-treeselect' import Treeselect from '@riophae/vue-treeselect'
import '@riophae/vue-treeselect/dist/vue-treeselect.css' import '@riophae/vue-treeselect/dist/vue-treeselect.css'
function deepHasValue(data, targetValue) {
const items = Array.isArray(data) ? data : [data]
for (const item of items) {
// 直接匹配基本类型
if (item === targetValue) return true
// 处理对象类型
if (typeof item === 'object' && item !== null) {
// 深度遍历所有属性值
for (const value of Object.values(item)) {
if (value === targetValue || deepHasValue(value, targetValue)) {
return true
}
}
}
}
return false
}
export default { export default {
components: { Treeselect }, components: { Treeselect },
data() { data() {
let self = this
var checkRepeat = (rule, value, callback) => {
var onOf = deepHasValue(self.infoTree.menus, value)
if (onOf) {
self.typeManage.flag = 1
self.typeManage.flag = 1
return callback(new Error('分类名称重复'))
} else {
self.typeManage.flag = 1
self.typeManage.flag = 1
callback()
}
}
return { return {
// 1.获取全部信息分类 // 1.获取全部信息分类
typeManage: { typeManage: {
...@@ -209,6 +244,9 @@ export default { ...@@ -209,6 +244,9 @@ export default {
addname: '', addname: '',
test: [] // 默认选项,要在el-checkbox-group里绑定一个空数组 test: [] // 默认选项,要在el-checkbox-group里绑定一个空数组
}, },
rules: {
addname: []
},
editDialog: false, editDialog: false,
fromData: [] fromData: []
}, },
...@@ -267,11 +305,17 @@ export default { ...@@ -267,11 +305,17 @@ export default {
newval: [], newval: [],
// 验证 // 验证
formrules: { formrules: {
addname: [{ required: true, message: '请输入类别', trigger: 'blur' }], addname: [
{ required: true, message: '请输入类别', trigger: 'blur' },
{ validator: checkRepeat, trigger: 'blur' }
],
test: [{ required: true, message: '请选择推送信息', trigger: 'change' }] test: [{ required: true, message: '请选择推送信息', trigger: 'change' }]
}, },
rules: { rules: {
type: [{ required: true, message: '请输入类别', trigger: 'blur' }], type: [
{ required: true, message: '请输入类别', trigger: 'blur' },
{ validator: checkRepeat, trigger: 'blur' }
],
choose: [{ required: true, message: '请选择推送信息', trigger: 'change' }] choose: [{ required: true, message: '请选择推送信息', trigger: 'change' }]
}, },
infoTree: { infoTree: {
...@@ -376,6 +420,7 @@ export default { ...@@ -376,6 +420,7 @@ export default {
determine() { determine() {
if (this.typeManage.flag) { if (this.typeManage.flag) {
this.typeManage.flag = 0 this.typeManage.flag = 0
this.chooseString = this.typeManage.from.test.join() this.chooseString = this.typeManage.from.test.join()
this.$refs.addDataForm.validate((valid) => { this.$refs.addDataForm.validate((valid) => {
if (valid) { if (valid) {
......
...@@ -199,15 +199,31 @@ ...@@ -199,15 +199,31 @@
<div v-for="(item, i) in typeList"> <div v-for="(item, i) in typeList">
<el-form ref="addDataForm" :model="typeList[i]" :rules="fromrules"> <el-form ref="addDataForm" :model="typeList[i]" :rules="fromrules">
<el-form-item prop="infoClass" label="信息分类" :label-width="'120px'"> <el-form-item prop="infoClass" label="信息分类" :label-width="'120px'">
<el-select clearable v-model="typeList[i].infoClass" placeholder="请选择类别" filterable allow-create> <el-cascader
<el-option v-for="(item, index) in listType" :key="index" :label="item.type" :value="item.typeId" /> clearable
</el-select> v-model="typeList[i].infoClass"
:options="listType"
:show-all-levels="false"
:props="{
emitPath: false,
checkStrictly: true,
value: 'id',
label: 'label',
children: 'children',
disabled: 'disabled'
}"
placeholder="请选择类别"
filterable
allow-create
>
<!-- <el-option v-for="(item, index) in listType" :key="index" :label="item.type" :value="item.typeId" /> -->
</el-cascader>
</el-form-item> </el-form-item>
<el-form-item prop="value" label="权重值:" :label-width="'120px'"> <el-form-item prop="value" label="权重值:" :label-width="'120px'">
<el-input-number v-model="typeList[i].value" :min="1" :max="5" label="描述文字"></el-input-number> <el-input-number v-model="typeList[i].value" :min="1" :max="3" label="描述文字"></el-input-number>
</el-form-item> </el-form-item>
<el-button circle icon="el-icon-plus" @click="addList()"></el-button> <el-button circle icon="el-icon-plus" @click="addList(item)"></el-button>
<el-button circle icon="el-icon-minus" @click="subList(i)" v-if="i > 0"></el-button> <el-button circle icon="el-icon-minus" @click="subList(item, i)" v-if="i > 0"></el-button>
</el-form> </el-form>
</div> </div>
<div slot="footer"> <div slot="footer">
...@@ -315,7 +331,7 @@ export default { ...@@ -315,7 +331,7 @@ export default {
// //
newManage: { newManage: {
page: 1, page: 1,
size: 10, size: '',
total: 0 total: 0
}, },
// 获取信息分类数据 // 获取信息分类数据
...@@ -347,20 +363,22 @@ export default { ...@@ -347,20 +363,22 @@ export default {
}, },
methods: { methods: {
//加号 //加号
addList() { addList(i) {
console.log(this.typeList.length)
console.log(this.totalTypeNumber)
if (this.typeList.length <= this.totalTypeNumber) { if (this.typeList.length <= this.totalTypeNumber) {
this.typeList.push({ infoClass: '', value: '' }) this.typeList.push({ infoClass: '', value: '' })
this.typeList.forEach((el) => {
this.listType = this.disableByField(this.listType, 'id', el.infoClass, true)
})
console.log(this.listType, i.infoClass)
} else { } else {
this.$message.error('已超过权重总数') this.$message.error('已超过权重总数')
return return
} }
}, },
//减号 //减号
subList(index) { subList(item, index) {
console.log(index)
this.typeList.splice(index, 1) this.typeList.splice(index, 1)
this.listType = this.disableByField(this.listType, 'id', item.infoClass, false)
}, },
// 获取信息分类 // 获取信息分类
classification(params) { classification(params) {
...@@ -372,11 +390,24 @@ export default { ...@@ -372,11 +390,24 @@ export default {
getAllCategory(params).then((res) => { getAllCategory(params).then((res) => {
var newlist = res.object.records || [] var newlist = res.object.records || []
this.totalTypeNumber = newlist.length this.totalTypeNumber = newlist.length
console.log(this.totalTypeNumber, 'this.totalTypeNumber') console.log(newlist)
for (var i = 0; i < newlist.length; i++) {
this.listType.push({ type: newlist[i].name, typeId: newlist[i].id }) newlist.forEach((e) => {
console.log(this.listType, 'this.listType') console.log(e.id)
}
if (e.children.length !== 0) {
this.listType.push({ ...e, disabled: true })
} else {
this.listType.push({ ...e })
}
})
console.log(this.listType, 'huoqu')
// console.log(this.totalTypeNumber, 'this.totalTypeNumber')
// for (var i = 0; i < newlist.length; i++) {
// this.listType.push({ type: newlist[i].name, typeId: newlist[i].id })
// console.log(this.listType, 'this.listType')
// }
}) })
}, },
handleChange(value) {}, handleChange(value) {},
...@@ -625,6 +656,42 @@ export default { ...@@ -625,6 +656,42 @@ export default {
}) })
.catch(() => {}) .catch(() => {})
}, },
/**
* 根据指定字段值标记嵌套结构中的对象
* @param {Array} nestedArray - 包含 children 的多层嵌套数据
* @param {string} field - 目标字段名
* @param {*} value - 要匹配的字段值
* @returns {Array} 标记后的新数据结构
*/
disableByField(nestedArray, field, value, tf) {
return nestedArray.map((item) => {
// 处理数组元素
if (Array.isArray(item)) {
return this.disableByField(item, field, value, tf)
}
// 处理对象元素
if (typeof item === 'object' && item !== null) {
// 创建新对象(保持不可变性)
const newItem = { ...item }
// 标记匹配元素
if (newItem[field] === value) {
newItem.disabled = tf
}
// 递归处理 children
if (Array.isArray(newItem.children)) {
newItem.children = this.disableByField(newItem.children, field, value, tf)
}
return newItem
}
// 其他类型直接返回
return item
})
},
checkboxT(row, rowIndex) { checkboxT(row, rowIndex) {
return row.id !== this.user.id return row.id !== this.user.id
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment