Commit 9f57ca73 authored by 白舜's avatar 白舜 🎱

重构能力推荐管理功能,修复之前的bug

parent c2cf6ba7
...@@ -2,25 +2,46 @@ ...@@ -2,25 +2,46 @@
<div class="item_card" :style="{ height: props.flag ? '242px' : '206px' }"> <div class="item_card" :style="{ height: props.flag ? '242px' : '206px' }">
<div class="action_box" v-if="props.flag"> <div class="action_box" v-if="props.flag">
<div class="can_click_text" @click="deleteItem(props.item)">删除</div> <div class="can_click_text" @click="deleteItem(props.item)">删除</div>
<div class="can_click_text" @click="move(1)" :class="props.item.canDown ? '' : 'disabled'">下移</div> <div class="can_click_text" @click="move(1)" :class="props.item.canDown ? '' : 'disabled'">
<div class="can_click_text" @click="move(2)" :class="props.item.canUp ? '' : 'disabled'">上移</div> 下移
</div>
<div class="can_click_text" @click="move(2)" :class="props.item.canUp ? '' : 'disabled'">
上移
</div>
</div> </div>
<div class="top_info" :style="{ 'padding-left': !props.flag ? '8px' : '24px' }"> <div class="top_info" :style="{ 'padding-left': !props.flag ? '8px' : '24px' }">
<template v-if="props.item.isSelected">
<el-checkbox <el-checkbox
v-if="!props.flag" v-if="!props.flag"
class="select_box" class="select_box"
v-model="props.item.checked" v-model="props.item.isSelected"
@change="change_check"></el-checkbox> :disabled="props.item.isSelected"
@change="changeSelectedList"></el-checkbox>
</template>
<el-checkbox
v-else-if="!props.flag"
class="select_box"
v-model="checked"
@change="changeSelectedList"></el-checkbox>
<div class="logo"> <div class="logo">
<img v-if="props.item.ability_logo" :src="JSON.parse(props.item.ability_logo)[0].url" alt="" /> <img
v-if="props.item.ability_logo !== '[]'"
:src="JSON.parse(props.item.ability_logo)[0].url"
alt="" />
<img v-else src="../assets/imgs/img_cover_ability.png" alt="" /> <img v-else src="../assets/imgs/img_cover_ability.png" alt="" />
</div> </div>
<div class="info"> <div class="info">
<div class="name"> <div class="name">
<el-tooltip class="box-item" effect="light" :content="props.item.ability_name" placement="top"> <el-tooltip
class="box-item"
effect="light"
:content="props.item.ability_name"
placement="top">
<span class="ability_name">{{ props.item.ability_name }}</span> <span class="ability_name">{{ props.item.ability_name }}</span>
</el-tooltip> </el-tooltip>
<span class="icon_box openness" :class="openClassObj[props.item.openness_id]">{{ props.item.openness }}</span> <span class="icon_box openness" :class="openClassObj[props.item.openness_id]">{{
props.item.openness
}}</span>
<span class="icon_box mock" v-if="props.item.include_mock_service">mock</span> <span class="icon_box mock" v-if="props.item.include_mock_service">mock</span>
</div> </div>
<div class="count"> <div class="count">
...@@ -33,7 +54,8 @@ ...@@ -33,7 +54,8 @@
<div class="line"></div> <div class="line"></div>
<div class="box2"> <div class="box2">
阅读{{ 阅读{{
props.item.browse_count == 0 || (props.item.browse_count && props.item.browse_count < 10000) props.item.browse_count == 0 ||
(props.item.browse_count && props.item.browse_count < 10000)
? props.item.browse_count ? props.item.browse_count
: props.item.browse_count < 10000000 : props.item.browse_count < 10000000
? Math.floor(props.item.browse_count / 10000) + "万+" ? Math.floor(props.item.browse_count / 10000) + "万+"
...@@ -53,7 +75,9 @@ ...@@ -53,7 +75,9 @@
</div> </div>
</div> </div>
</div> </div>
<div class="bottom_info" :style="{ height: props.flag ? 'calc(100% - 128px)' : 'calc(100% - 92px)' }"> <div
class="bottom_info"
:style="{ height: props.flag ? 'calc(100% - 128px)' : 'calc(100% - 92px)' }">
<div class="desc" :title="props.item.synopsis"> <div class="desc" :title="props.item.synopsis">
{{ props.item.synopsis }} {{ props.item.synopsis }}
</div> </div>
...@@ -68,8 +92,9 @@ ...@@ -68,8 +92,9 @@
</template> </template>
<script setup> <script setup>
import { ref } from "vue";
import { useRouter } from "vue-router"; import { useRouter } from "vue-router";
const checked = ref(false);
const router = useRouter(); const router = useRouter();
const props = defineProps({ const props = defineProps({
item: { item: {
...@@ -81,7 +106,7 @@ const props = defineProps({ ...@@ -81,7 +106,7 @@ const props = defineProps({
default: false, default: false,
}, },
}); });
const emit = defineEmits(["change_check", "deleteItem", "move"]); const emit = defineEmits(["changeSelectedList", "deleteItem", "move"]);
const openClassObj = { const openClassObj = {
"9de06ba6-6ee2-4449-91d9-31a1c7554311": "open", "9de06ba6-6ee2-4449-91d9-31a1c7554311": "open",
"4e8b4c37-e565-4195-8303-3b1ccd48dd13": "share", "4e8b4c37-e565-4195-8303-3b1ccd48dd13": "share",
...@@ -89,9 +114,8 @@ const openClassObj = { ...@@ -89,9 +114,8 @@ const openClassObj = {
"4e8b4c37-e565-4195-8303-3b1ccd48dd16": "sensitive", "4e8b4c37-e565-4195-8303-3b1ccd48dd16": "sensitive",
}; };
const change_check = () => { const changeSelectedList = () => {
console.log(props.item); emit("changeSelectedList", props.item, checked.value);
emit("change_check", props.item);
}; };
const deleteItem = (item) => { const deleteItem = (item) => {
emit("deleteItem", item); emit("deleteItem", item);
......
<template> <template>
<div v-if="!props.flag && props.loading === true">
<div class="empty-tips">数据加载中...</div>
</div>
<div class="card_list"> <div class="card_list">
<div v-for="(e, i) in props.list" :key="'card' + i" class="item"> <template v-if="props.list.length > 0">
<div v-for="(item, i) in props.list" :key="'card' + i" class="item">
<ability-card <ability-card
v-if="e.id" :item="item"
:item="e" @change-selected-list="changeSelectedList"
@change_check="changeCheck"
:flag="props.flag" :flag="props.flag"
@deleteItem="deleteItem" @deleteItem="deleteItem"
@move="move" /> @move="move" />
<div v-else class="empty_card" @click="open"> </div>
</template>
<div class="item" v-if="props.flag">
<div v-if="props.list.length < 9" class="empty_card" @click="open">
<span>+</span> <span>+</span>
</div> </div>
</div> </div>
...@@ -26,13 +32,16 @@ const props = defineProps({ ...@@ -26,13 +32,16 @@ const props = defineProps({
type: Boolean, type: Boolean,
default: false, default: false,
}, },
loading: {
type: Boolean,
default: false,
}
}); });
const emit = defineEmits(["changeCheck", "openBox", "deleteItem", "move"]); const emit = defineEmits(["changeSelectedList", "openBox", "deleteItem", "move"]);
const changeCheck = (item) => { const changeSelectedList = (item, checked) => {
emit("changeCheck", item); emit("changeSelectedList", item, checked);
}; };
const open = () => { const open = () => {
console.log(3333);
emit("openBox"); emit("openBox");
}; };
const deleteItem = (item) => { const deleteItem = (item) => {
...@@ -67,5 +76,9 @@ const move = (temp) => { ...@@ -67,5 +76,9 @@ const move = (temp) => {
font-size: 48px; font-size: 48px;
font-weight: 100; font-weight: 100;
} }
.empty-tips {
text-align: center;
}
} }
</style> </style>
...@@ -11,14 +11,14 @@ ...@@ -11,14 +11,14 @@
@changeType="changeType"></type-form> @changeType="changeType"></type-form>
<div class="ability_select"> <div class="ability_select">
<div class="title"> <div class="title">
<span>已选择能力({{ selectArrNew.length }}/9)</span> <span>已选择能力({{ selectedItemList.length }}/9)</span>
<el-tooltip class="box-item" effect="light" content="最少需选择6个能力" placement="top"> <el-tooltip class="box-item" effect="light" content="最少需选择6个能力" placement="top">
<bg-icon icon="#bg-ic-circle-warning" style="color: #7784a6"></bg-icon> <bg-icon icon="#bg-ic-circle-warning" style="color: #7784a6"></bg-icon>
</el-tooltip> </el-tooltip>
</div> </div>
<div class="select_arr"> <div class="select_arr">
<ability-list <ability-list
:list="selectArr" :list="selectedItemList"
:flag="true" :flag="true"
@openBox="openDialog" @openBox="openDialog"
@deleteItem="deleteItem" @deleteItem="deleteItem"
...@@ -37,7 +37,12 @@ ...@@ -37,7 +37,12 @@
</div> </div>
</div> </div>
</div> </div>
<el-dialog class="select_dialog" title="选择能力" v-model="selectDialog" width="1220px"> <el-dialog
class="select_dialog"
title="选择能力"
v-model="selectDialog"
width="1220px"
:before-close="cancelSelectDialog">
<div class="select_box"> <div class="select_box">
<div class="topFilter"> <div class="topFilter">
<div class="right"> <div class="right">
...@@ -97,13 +102,17 @@ ...@@ -97,13 +102,17 @@
</div> </div>
<div> <div>
<span>已选择</span> <span>已选择</span>
<span class="num">({{ selectArrNew.length }}/9)</span> <span class="num">({{ toBeAddedItemList.length }}/9)</span>
<span></span> <span></span>
<span class="can_click_text" @click="clearSelection">清空</span> <span class="can_click_text" @click="clearSelection">清空</span>
</div> </div>
</div> </div>
<div class="user_table bg-scroll"> <div class="user_table bg-scroll">
<ability-list :list="list" @changeCheck="changeCheck"></ability-list> <ability-list
:list="list"
:loading="abilityLoading"
:flag="false"
@change-selected-list="changeSelectedList"></ability-list>
</div> </div>
</div> </div>
</div> </div>
...@@ -117,8 +126,8 @@ ...@@ -117,8 +126,8 @@
:pageSizes="[15, 30, 50]"> :pageSizes="[15, 30, 50]">
</bg-pagination> </bg-pagination>
<div class="apaas_button"> <div class="apaas_button">
<el-button type="default" @click="selectDialog = false">取 消</el-button> <el-button type="default" @click="cancelSelectDialog">取 消</el-button>
<el-button type="primary" @click="conform">确 定</el-button> <el-button type="primary" @click="confirm">确 定</el-button>
</div> </div>
</template> </template>
</el-dialog> </el-dialog>
...@@ -143,7 +152,7 @@ const state = reactive({ ...@@ -143,7 +152,7 @@ const state = reactive({
logo: [], logo: [],
state: 1, state: 1,
}, },
selectArr: ["", "", "", "", "", "", "", "", ""], selectedItemList: [],
selectDialog: false, selectDialog: false,
dialogFilter: { dialogFilter: {
openness: [], openness: [],
...@@ -176,7 +185,8 @@ const state = reactive({ ...@@ -176,7 +185,8 @@ const state = reactive({
], ],
businessList: [], businessList: [],
list: [], list: [],
selectArrNew: [], abilityLoading: false,
toBeAddedItemList: [],
}); });
const getDetail = (id) => { const getDetail = (id) => {
...@@ -185,30 +195,25 @@ const getDetail = (id) => { ...@@ -185,30 +195,25 @@ const getDetail = (id) => {
.then((res) => { .then((res) => {
if (res.data.code == 200) { if (res.data.code == 200) {
const data = res.data.data; const data = res.data.data;
console.log(data);
typeFormRef.value.setForm({ typeFormRef.value.setForm({
business_type_id: data.business_type_id, business_type_id: data.business_type_id,
logo: data.logo ? [{ url: data.logo }] : [], logo: data.logo ? [{ url: data.logo }] : [],
}); });
state.selectArr = []; state.selectedItemList = [];
state.selectArrNew = []; state.toBeAddedItemList = [];
state.formData.state = data.state; state.formData.state = data.state;
state.formData.business_type_id = data.business_type_id; state.formData.business_type_id = data.business_type_id;
state.selectArrNew = data.ability_list || []; state.selectedItemList = data.ability_list || [];
state.selectArrNew.forEach((e, i) => { state.selectedItemList.forEach((e, i) => {
e.canDown = true; e.canDown = true;
e.canUp = true; e.canUp = true;
if (i == 0) { if (i == 0) {
e.canUp = false; e.canUp = false;
} }
if (i == state.selectArrNew.length - 1) { if (i == state.selectedItemList.length - 1) {
e.canDown = false; e.canDown = false;
} }
}); });
state.selectArr.push(...state.selectArrNew);
for (var i = 0; i < 9 - state.selectArrNew.length; i++) {
state.selectArr.push("");
}
} else { } else {
ElMessage.error(res.data.data); ElMessage.error(res.data.data);
} }
...@@ -230,36 +235,33 @@ const getOrgList = () => { ...@@ -230,36 +235,33 @@ const getOrgList = () => {
const changeType = (val) => { const changeType = (val) => {
state.formData.business_type_id = val; state.formData.business_type_id = val;
state.selectArr = ["", "", "", "", "", "", "", "", ""]; state.selectedItemList = [];
state.selectArrNew = []; state.toBeAddedItemList = [];
}; };
const getAbilityList = () => { const getAbilityList = () => {
state.abilityLoading = true;
let params = { let params = {
...state.dialogFilter, ...state.dialogFilter,
business_type: state.formData.business_type_id, business_type: state.formData.business_type_id,
}; };
params.organization_id = params.organization_id =
params.organization_id && params.organization_id.length > 0 ? params.organization_id.join(",") : ""; params.organization_id && params.organization_id.length > 0
? params.organization_id.join(",")
: "";
params.openness = params.openness && params.openness.length > 0 ? params.openness.join(",") : ""; params.openness = params.openness && params.openness.length > 0 ? params.openness.join(",") : "";
axios.get(`/apaas/system/v5/recommend/ability/list`, { params }).then((res) => { axios.get(`/apaas/system/v5/recommend/ability/list`, { params }).then((res) => {
if (res.data.code == 200) { if (res.data.code == 200) {
let selecteItemIdList = state.selectedItemList.map((e) => e.id);
state.list = res.data.data.ability_list || []; state.list = res.data.data.ability_list || [];
state.selectArrNew = []; state.list.forEach((item) => {
state.total = res.data.data.ability_total; if (selecteItemIdList.indexOf(item.id) > -1) {
nextTick(() => { item.isSelected = true;
state.list.forEach((e) => {
e.checked = false;
state.selectArr.forEach((k) => {
if (k.id) {
if (e.id == k.id) {
e.checked = true;
state.selectArrNew.push(e);
}
} }
}); });
}); state.total = res.data.data.ability_total;
});
} }
state.abilityLoading = false;
}); });
}; };
...@@ -269,58 +271,58 @@ const openDialog = () => { ...@@ -269,58 +271,58 @@ const openDialog = () => {
}; };
const deleteItem = (item) => { const deleteItem = (item) => {
changeCheck(item, true); let selecteItemIdList = state.selectedItemList.map((e) => e.id);
state.selectedItemList.splice(selecteItemIdList.indexOf(item.id), 1);
moveAbleChanging();
}; };
const move = (temp) => { const move = (temp) => {
let id = temp.item.id; let id = temp.item.id;
let index = null; let index = null;
state.selectArr.forEach((e, i) => { state.selectedItemList.forEach((e, i) => {
if (e.id == id) { if (e.id == id) {
index = i; index = i;
} }
}); });
if (temp.type == 1) { if (temp.type == 1) {
state.selectArr[index] = state.selectArr[index + 1]; state.selectedItemList[index] = state.selectedItemList[index + 1];
state.selectArr[index + 1] = temp.item; state.selectedItemList[index + 1] = temp.item;
} else { } else {
state.selectArr[index] = state.selectArr[index - 1]; state.selectedItemList[index] = state.selectedItemList[index - 1];
state.selectArr[index - 1] = temp.item; state.selectedItemList[index - 1] = temp.item;
} }
state.selectArr.forEach((e, i) => { state.selectedItemList.forEach((e, i) => {
if (e != "") { if (e != "") {
e.canDown = true; e.canDown = true;
e.canUp = true; e.canUp = true;
if (i == 0) { if (i == 0) {
e.canUp = false; e.canUp = false;
} }
if (i == state.selectArrNew.length - 1) { if (i == state.selectedItemList.length - 1) {
e.canDown = false; e.canDown = false;
} }
} }
}); });
state.selectArrNew = state.selectArr.filter((e) => e )
}; };
const changePage = (val) => { const changePage = (val) => {
state.dialogFilter.page = 1; state.dialogFilter.page = val;
getAbilityList(); getAbilityList();
}; };
const changeSize = (val) => { const changeSize = (val) => {
state.dialogFilter.limit = val; state.dialogFilter.limit = val;
changePage(1); changePage(val);
}; };
const changeCollation = (val) => { const changeCollation = (val) => {
state.dialogFilter.collation = val; state.dialogFilter.collation = val;
changePage(1); changePage(val);
}; };
const clearSelection = () => { const clearSelection = () => {
state.list.forEach((e) => { state.toBeAddedItemList = [];
e.checked = false; state.list = [];
});
state.selectArrNew = [];
}; };
const searchAction = () => { const searchAction = () => {
changePage(1); changePage(1);
...@@ -337,59 +339,73 @@ const clearAction = () => { ...@@ -337,59 +339,73 @@ const clearAction = () => {
changePage(1); changePage(1);
}; };
const changeCheck = (item, deleteFlag) => { const changeSelectedList = (item, checked) => {
let arr = state.selectArrNew.map((e) => e.id) || []; if (checked) {
if (arr.indexOf(item.id) > -1) { state.toBeAddedItemList.push(item);
state.selectArrNew.splice(arr.indexOf(item.id), 1);
} else { } else {
state.selectArrNew.push(item); let _toBeAddedItemIdList = state.toBeAddedItemList.map((e) => e.id);
state.toBeAddedItemList.splice(_toBeAddedItemIdList.indexOf(item.id), 1);
} }
state.selectArrNew.forEach((e, i) => { moveAbleChanging();
};
const moveAbleChanging = () => {
state.selectedItemList.forEach((e, i) => {
e.canDown = true; e.canDown = true;
e.canUp = true; e.canUp = true;
if (i == 0) { if (i == 0) {
e.canUp = false; e.canUp = false;
} }
if (i == state.selectArrNew.length - 1) { if (i == state.selectedItemList.length - 1) {
e.canDown = false; e.canDown = false;
} }
}); });
if (deleteFlag) {
conform();
}
}; };
const submit = () => { const submit = () => {
typeFormRef.value.submitForm(); typeFormRef.value.submitForm();
}; };
const conform = () => { const cancelSelectDialog = () => {
if (state.selectArrNew.length > 9) { state.selectDialog = false;
clearSelection();
};
const confirm = () => {
if (
state.toBeAddedItemList.length > 9 ||
state.selectedItemList.length + state.toBeAddedItemList.length > 9
) {
ElMessage.error("最多可选择9个能力"); ElMessage.error("最多可选择9个能力");
return; return;
} }
state.selectArr = JSON.parse(JSON.stringify(state.selectArrNew)); const _newItemList = [];
if (state.selectArr.length < 9) { state.toBeAddedItemList.forEach((toBeAddedItem) => {
let arr = []; const hasItem = state.selectedItemList.some(
for (var i = 0; i < 9 - state.selectArr.length; i++) { (selectedItem) => toBeAddedItem.id === selectedItem.id
arr.push(""); );
} if (!hasItem) {
state.selectArr.push(...arr); _newItemList.push(toBeAddedItem);
} }
});
state.selectedItemList.push(..._newItemList);
state.toBeAddedItemList.length = 0;
moveAbleChanging();
clearSelection();
state.selectDialog = false; state.selectDialog = false;
}; };
const submitFormData = (data) => { const submitFormData = (data) => {
if (state.selectArrNew.length < 6) { if (state.selectedItemList.length < 6) {
ElMessage.error("最少选择6个能力"); ElMessage.error("最少选择6个能力");
return; return;
} }
if (data) { if (data) {
Object.assign(state.formData, data); Object.assign(state.formData, data);
console.log(state.formData);
if (route.query.id) { if (route.query.id) {
// 编辑 // 编辑
let abilitys = []; let abilitys = [];
state.selectArrNew.forEach((e) => { state.selectedItemList.forEach((e) => {
abilitys.push(e.ability_id); abilitys.push(e.ability_id);
}); });
let params = { let params = {
...@@ -409,7 +425,7 @@ const submitFormData = (data) => { ...@@ -409,7 +425,7 @@ const submitFormData = (data) => {
}); });
} else { } else {
let abilitys = []; let abilitys = [];
state.selectArrNew.forEach((e) => { state.selectedItemList.forEach((e) => {
abilitys.push(e.ability_id); abilitys.push(e.ability_id);
}); });
let params = { let params = {
...@@ -461,16 +477,16 @@ onBeforeMount(() => { ...@@ -461,16 +477,16 @@ onBeforeMount(() => {
const { const {
formData, formData,
selectArr, selectedItemList,
selectDialog, selectDialog,
dialogFilter, dialogFilter,
typeList, typeList,
total, total,
orgList, orgList,
collationArr, collationArr,
selection,
list, list,
selectArrNew, abilityLoading,
toBeAddedItemList,
businessList, businessList,
} = toRefs(state); } = toRefs(state);
</script> </script>
......
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