feat:添加模板标签

This commit is contained in:
fanpeijiang
2022-10-22 20:48:35 +08:00
parent b3539f1bf8
commit 643ef4d705
3 changed files with 252 additions and 134 deletions

View File

@@ -123,7 +123,7 @@ export function setSurveyStatus(params) {
export function getTagsList(params) { export function getTagsList(params) {
return request({ return request({
method: "GET", method: "GET",
url: '/console/survey_tags', url: `/console/survey_tags`,
params, params,
}); });
} }

View File

@@ -30,7 +30,35 @@
:key="item.id" :key="item.id"
> >
<div style="display: flex; justify-content: space-between"> <div style="display: flex; justify-content: space-between">
<span :style="countColor(item.color)" :title="item.title">{{ item.title }}</span> <span :style="countColor(item.color)" :title="item.title">{{
item.title
}}</span>
</div>
</a-select-option>
<!-- <a-select-option v-for="item in tagsList" :key="item.id">
{{ item.title }}
</a-select-option> -->
</a-select>
</a-form-item>
<a-form-item label="模板标签">
<a-select
mode="multiple"
v-model:value="ruleForm.templateTags"
placeholder="选择问卷标签"
:filter-option="false"
:not-found-content="fetching ? undefined : null"
@search="fetchUser"
>
<a-select-option
:value="item.id"
:label="item.title"
v-for="item in templateTagsList"
:key="item.id"
>
<div style="display: flex; justify-content: space-between">
<span :style="countColor(item.color)" :title="item.title">{{
item.title
}}</span>
</div> </div>
</a-select-option> </a-select-option>
<!-- <a-select-option v-for="item in tagsList" :key="item.id"> <!-- <a-select-option v-for="item in tagsList" :key="item.id">
@@ -57,27 +85,38 @@
</a-select> </a-select>
</a-form-item> </a-form-item>
<a-form-item label="创建时间"> <a-form-item label="创建时间">
<a-range-picker v-model:value="ruleForm.created_at" @change="handleCreated"/> <a-range-picker
v-model:value="ruleForm.created_at"
@change="handleCreated"
/>
</a-form-item> </a-form-item>
<a-form-item label="编辑时间"> <a-form-item label="编辑时间">
<a-range-picker v-model:value="ruleForm.updated_at" @change="handleUpdated"/> <a-range-picker
v-model:value="ruleForm.updated_at"
@change="handleUpdated"
/>
</a-form-item> </a-form-item>
<a-form-item class="button" style="text-align: right"> <a-form-item class="button" style="text-align: right">
<a-button style="margin-right:12px" type="cancel" @click="$emit('cancel')">取消</a-button> <a-button
style="margin-right: 12px"
type="cancel"
@click="$emit('cancel')"
>取消</a-button
>
<a-button type="primary" @click="onSubmit">确定</a-button> <a-button type="primary" @click="onSubmit">确定</a-button>
</a-form-item> </a-form-item>
</a-form> </a-form>
</template> </template>
<script> <script>
import { defineComponent, reactive, ref, onBeforeMount } from 'vue'; import { defineComponent, reactive, ref, onBeforeMount } from "vue";
import { debounce } from 'lodash-es'; import { debounce } from "lodash-es";
import { getUserList, getTagsList } from '../api'; import { getUserList, getTagsList } from "../api";
const statusOptions = [ const statusOptions = [
{ label: '编辑中', value: 0 }, { label: "编辑中", value: 0 },
{ label: '发布中', value: 1 }, { label: "发布中", value: 1 },
{ label: '已结束', value: 2 }, { label: "已结束", value: 2 },
] ];
export default defineComponent({ export default defineComponent({
props: { props: {
info: { info: {
@@ -90,23 +129,25 @@ export default defineComponent({
const ruleForm = reactive({ const ruleForm = reactive({
status: [0], status: [0],
owner_id: undefined, owner_id: undefined,
created_at: '', created_at: "",
updated_at: '', updated_at: "",
tags: [], tags: [],
templateTags: [],
}); });
let lastFetchId = 0; let lastFetchId = 0;
const fetching = ref(false); const fetching = ref(false);
const userList = ref([]) const userList = ref([]);
const tagsList = ref([]) const tagsList = ref([]);
const templateTagsList = ref([]);
const handleCreated = (value, dateString) => { const handleCreated = (value, dateString) => {
console.log('dateString', dateString) console.log("dateString", dateString);
ruleForm.created_at = dateString; ruleForm.created_at = dateString;
}; };
const handleUpdated = (value, dateString) => { const handleUpdated = (value, dateString) => {
ruleForm.updated_at = dateString; ruleForm.updated_at = dateString;
}; };
/** 搜索用户防抖 */ /** 搜索用户防抖 */
const fetchUser = debounce(value => { const fetchUser = debounce((value) => {
lastFetchId += 1; lastFetchId += 1;
userList.value = []; userList.value = [];
fetching.value = true; fetching.value = true;
@@ -114,148 +155,178 @@ export default defineComponent({
getUsers(value); getUsers(value);
}, 500); }, 500);
/** 获取用户列表 */ /** 获取用户列表 */
const getUsers = async (val)=> { const getUsers = async (val) => {
try { try {
const { data } = await getUserList({nickname: val || ''}); const { data } = await getUserList({ nickname: val || "" });
const fetchId = lastFetchId; const fetchId = lastFetchId;
if (fetchId !== lastFetchId) { if (fetchId !== lastFetchId) {
return; return;
} }
userList.value = data; userList.value = data;
} catch(error) { } catch (error) {
context.message.error( context.message.error(
error.data?.message || error.message || "服务器错误" error.data?.message || error.message || "服务器错误"
); );
} }
} };
/** 获取项目标签列表 */ /** 获取项目标签列表 */
const getTagList = async (val)=> { const getTagList = async () => {
try { try {
const { data } = await getTagsList(); const { data } = await getTagsList();
console.log(data); console.log(data);
const fetchId = lastFetchId; const fetchId = lastFetchId;
if (fetchId !== lastFetchId) { if (fetchId !== lastFetchId) {
return; return;
} }
tagsList.value = data; tagsList.value = data;
} catch(error) { } catch (error) {
context.message.error( context.message.error(
error.data?.message || error.message || "服务器错误" error.data?.message || error.message || "服务器错误"
); );
} }
} };
/** 获取项目标签列表 */
const getTemplateTagList = async () => {
try {
const { data } = await getTagsList({
type: 2
});
console.log(data);
const fetchId = lastFetchId;
if (fetchId !== lastFetchId) {
return;
}
templateTagsList.value = data;
} catch (error) {
context.message.error(
error.data?.message || error.message || "服务器错误"
);
}
};
// 标签颜色 // 标签颜色
const countColor = (value) => { const countColor = (value) => {
let style = {} let style = {};
switch (value) { switch (value) {
case 1: case 1:
style = { style = {
'color' : '#4DB8FA', color: "#4DB8FA",
'border' : '1px solid #4DB8FA', border: "1px solid #4DB8FA",
'padding': '0 5px', padding: "0 5px",
'border-radius': '4px', "border-radius": "4px",
'line-height': '20px', "line-height": "20px",
} };
break; break;
case 2: case 2:
style = { style = {
'color' : '#0CC126', color: "#0CC126",
// 'border-color' : '#0CC126', // 'border-color' : '#0CC126',
'border' : '1px solid #0CC126', border: "1px solid #0CC126",
'padding': '0 5px', padding: "0 5px",
'border-radius': '4px', "border-radius": "4px",
'line-height': '20px', "line-height": "20px",
} };
break; break;
case 3: case 3:
style = { style = {
'color' : '#FF8800', color: "#FF8800",
// 'border-color' : '#FF8800', // 'border-color' : '#FF8800',
'border' : '1px solid #FF8800', border: "1px solid #FF8800",
'padding': '0 5px', padding: "0 5px",
'border-radius': '4px', "border-radius": "4px",
'line-height': '20px', "line-height": "20px",
} };
break; break;
case 4: case 4:
style = { style = {
'color' : '#FF374F', color: "#FF374F",
// 'border-color' : '#FF374F', // 'border-color' : '#FF374F',
'border' : '1px solid #FF374F', border: "1px solid #FF374F",
'padding': '0 5px', padding: "0 5px",
'border-radius': '4px', "border-radius": "4px",
'line-height': '20px', "line-height": "20px",
} };
break; break;
case 5: case 5:
style = { style = {
'color' : '#1C6FFF', color: "#1C6FFF",
// 'border-color' : '#1C6FFF', // 'border-color' : '#1C6FFF',
'border' : '1px solid #1C6FFF', border: "1px solid #1C6FFF",
'padding': '0 5px', padding: "0 5px",
'border-radius': '4px', "border-radius": "4px",
'line-height': '20px', "line-height": "20px",
} };
break; break;
case 6: case 6:
style = { style = {
'color' : '#11AEA7', color: "#11AEA7",
// 'border-color' : '#11AEA7', // 'border-color' : '#11AEA7',
'border' : '1px solid #11AEA7', border: "1px solid #11AEA7",
'padding': '0 5px', padding: "0 5px",
'border-radius': '4px', "border-radius": "4px",
'line-height': '20px', "line-height": "20px",
} };
break; break;
case 7: case 7:
style = { style = {
'color' : '#25D8C8', color: "#25D8C8",
// 'border-color' : '#25D8C8', // 'border-color' : '#25D8C8',
'border' : '1px solid #25D8C8', border: "1px solid #25D8C8",
'padding': '0 5px', padding: "0 5px",
'border-radius': '4px', "border-radius": "4px",
'line-height': '20px', "line-height": "20px",
} };
break; break;
case 8: case 8:
style = { style = {
'color' : '#FECB0D', color: "#FECB0D",
// 'border-color' : '#FECB0D', // 'border-color' : '#FECB0D',
'border' : '1px solid #FECB0D', border: "1px solid #FECB0D",
'padding': '0 5px', padding: "0 5px",
'border-radius': '4px', "border-radius": "4px",
'line-height': '20px', "line-height": "20px",
} };
// break; // break;
// case 9: // case 9:
// style = { // style = {
// 'color' : '4DB8FA', // 'color' : '4DB8FA',
// 'border-color' : '4DB8FA', // 'border-color' : '4DB8FA',
// } // }
} }
return style return style;
} };
/** 提交筛选条件 */ /** 提交筛选条件 */
const onSubmit = () => { const onSubmit = () => {
formRef.value.validate().then(() => { formRef.value
.validate()
.then(() => {
const params = { const params = {
owner_id: ruleForm.owner_id ? (ruleForm.owner_id.map(e=> e.key)).join(',') : '', owner_id: ruleForm.owner_id
status: ruleForm.status ? ruleForm.status.join(',') : '', ? ruleForm.owner_id.map((e) => e.key).join(",")
created_at: ruleForm.created_at ? ruleForm.created_at.join(',') : '', : "",
updated_at: ruleForm.updated_at ? ruleForm.updated_at.join(',') : '', status: ruleForm.status ? ruleForm.status.join(",") : "",
tags: ruleForm.tags ? ruleForm.tags.join(',') : '', created_at: ruleForm.created_at
} ? ruleForm.created_at.join(",")
console.log('values', params); : "",
context.emit('update', params) updated_at: ruleForm.updated_at
? ruleForm.updated_at.join(",")
: "",
tags: ruleForm.tags ? ruleForm.tags.join(",") : "",
templates_tags: ruleForm.templateTags
? ruleForm.templateTags.join(",")
: "",
};
console.log("values", params);
context.emit("update", params);
}) })
.catch((error) => { .catch((error) => {
console.log('error', error); console.log("error", error);
}); });
}; };
onBeforeMount(()=> { onBeforeMount(() => {
getUsers(); getUsers();
getTagList(); getTagList();
}) getTemplateTagList();
});
return { return {
formRef, formRef,
ruleForm, ruleForm,
@@ -264,13 +335,14 @@ export default defineComponent({
handleCreated, handleCreated,
handleUpdated, handleUpdated,
statusOptions, statusOptions,
labelCol: { style: { width: '150px' } }, labelCol: { style: { width: "150px" } },
wrapperCol: { span: 14 }, wrapperCol: { span: 14 },
userList, userList,
fetching, fetching,
tagsList, tagsList,
templateTagsList,
countColor, countColor,
} };
}, },
}) });
</script> </script>

View File

@@ -109,11 +109,47 @@
<!-- </div> --> <!-- </div> -->
</div> </div>
</template> </template>
<template #templateTag="{ record }">
<div
v-for="item in record.template_tags"
:key="item.id"
style="display: inline-block"
>
<!-- <div v-for="it in record.tag" :key="it.id" style="display:inline-block;"> -->
<a-tooltip
v-if="record.template_tags.length > 2"
placement="right"
:title="record.titles"
>
<div style="display: flex; flex-direction: row">
<div
:title="item.title"
:style="countColor(item.color)"
class="tagStyle"
>
{{ item.title }}
</div>
<div class="tagOmit" v-if="record.template_tags.length == 1">...</div>
</div>
</a-tooltip>
<div
v-else
:title="item.title"
:style="countColor(item.color)"
class="tagStyle"
>
{{ item.title }}
</div>
<!-- </div> -->
</div>
</template>
<template #titles="{ record }"> <template #titles="{ record }">
<a-tooltip placement="right" :title="record.remarks || ''"> <a-tooltip placement="right" :title="record.remarks || ''">
<div> <div>
<span>{{ record.project_name }}</span> <span>{{ record.project_name }}</span>
<span class="table-sell" v-if="record.template_tag">#{{ record.template_tag }}</span> <span class="table-sell" v-if="record.template_tag"
>#{{ record.template_tag }}</span
>
</div> </div>
</a-tooltip> </a-tooltip>
</template> </template>
@@ -272,7 +308,17 @@ const columns = [
dataIndex: "tag[0].title", dataIndex: "tag[0].title",
align: "center", align: "center",
slots: { slots: {
customRender: "tag", customRender: "templateTag",
},
width: 200,
},
{
title: "模板标签",
key: "template_tags[0].title",
dataIndex: "template_tags[0].title",
align: "center",
slots: {
customRender: "templateTag",
}, },
width: 200, width: 200,
}, },
@@ -833,7 +879,7 @@ export default defineComponent({
.ant-table-title { .ant-table-title {
padding: 0 !important; padding: 0 !important;
} }
.table-sell{ .table-sell {
color: $yili-default-color; color: $yili-default-color;
word-break: keep-all; word-break: keep-all;
} }