update:人员/项目根据点击次数排序
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
import { queryNodeListApi, queryNodeListNoPermissionApi } from '@/api/project/node';
|
||||
import { debounce } from 'lodash-es';
|
||||
import { ref, onMounted, watch, inject, type Ref } from 'vue';
|
||||
import { dataUseRate, dataUserRateSort } from '@/utils/common';
|
||||
|
||||
interface Props {
|
||||
modelValue: string;
|
||||
@@ -83,7 +84,7 @@ const getlistDataFun = () => {
|
||||
label: props.showCodeList ? item.nodeCode : item.nodeName,
|
||||
};
|
||||
});
|
||||
listData.value = build;
|
||||
listData.value = dataUserRateSort(props.resStr, build, 'project');
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -119,6 +120,7 @@ const multiplyChangeFun = debounce(() => {
|
||||
listData.value.forEach((item: any) => {
|
||||
if (choseList.value.includes(String(item[props.resStr]))) {
|
||||
changeData.push(item);
|
||||
dataUseRate(item[props.resStr], 'project');
|
||||
}
|
||||
});
|
||||
emit('change', changeData);
|
||||
@@ -133,6 +135,7 @@ const changeFun = () => {
|
||||
listData.value.some((item: any) => {
|
||||
if (choseList.value === String(item[props.resStr])) {
|
||||
changeData = item;
|
||||
dataUseRate(item[props.resStr], 'project');
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
<script lang="ts" setup>
|
||||
import { ref, onMounted, watch } from 'vue';
|
||||
import { userListUserApi, userQueryGroupApi, userQueryGroupDetailApi } from '@/api/system/user';
|
||||
import { dataUseRate, dataUserRateSort } from '@/utils/common';
|
||||
|
||||
interface Props {
|
||||
modelValue: string;
|
||||
@@ -116,6 +117,7 @@ const getGroupUsersFun = (id: string) => {
|
||||
};
|
||||
});
|
||||
listData.value = build;
|
||||
listData.value = dataUserRateSort('userId', build, 'user');
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -128,6 +130,7 @@ const changeFun = () => {
|
||||
listData.value.forEach((item: any) => {
|
||||
if (choseList.value.includes(String(item.userId))) {
|
||||
changeData.push(item);
|
||||
dataUseRate(item.userId, 'user');
|
||||
}
|
||||
});
|
||||
emit('change', changeData);
|
||||
@@ -137,6 +140,7 @@ const changeFun = () => {
|
||||
listData.value.some((item: any) => {
|
||||
if (choseList.value === String(item.userId)) {
|
||||
changeData = item;
|
||||
dataUseRate(item.userId, 'user');
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -101,3 +101,31 @@ export const jumpPage = (location: any) => {
|
||||
router.push(location);
|
||||
}
|
||||
};
|
||||
|
||||
const defaultRateData: any = {
|
||||
project: {}, // 项目列表
|
||||
user: {}, // 人员列表
|
||||
};
|
||||
const rateObjData = JSON.parse(
|
||||
localStorage.getItem('DATA_USE_RATE') || JSON.stringify(defaultRateData)
|
||||
);
|
||||
export const dataUseRate = (id: any, mode: any) => {
|
||||
const rateData = rateObjData[mode];
|
||||
if (!rateData[id]) {
|
||||
rateData[id] = 0;
|
||||
}
|
||||
// 每触发一次change 权重增加一次
|
||||
rateData[id] = rateData[id] + 1;
|
||||
defaultRateData[mode] = rateData;
|
||||
localStorage.setItem('DATA_USE_RATE', JSON.stringify(defaultRateData));
|
||||
};
|
||||
export const dataUserRateSort = (key: any, list: any, mode: any) => {
|
||||
const rateData = rateObjData[mode];
|
||||
// 更具权重重新排序
|
||||
const data = list.sort((x: any, y: any) => {
|
||||
const weightX = rateData[x[key]] ?? 0;
|
||||
const weightY = rateData[y[key]] ?? 0;
|
||||
return weightY - weightX;
|
||||
});
|
||||
return data;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user