| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711 |
- <template>
- <div class="container">
- <Breadcrumb :items="['menu.overrideRules', 'menu.overrideRules.list']" />
- <a-card class="general-card" :title="$t('menu.overrideRules.list')">
- <a-row>
- <a-col :flex="1">
- <a-form :model="formModel" :label-col-props="{ span: 6 }" :wrapper-col-props="{ span: 18 }"
- label-align="left">
- <a-row :gutter="16">
- <a-col :span="8">
- <a-form-item field="keyword" label="搜索">
- <a-input v-model="formModel.keyword" placeholder="输入关键词搜索" />
- </a-form-item>
- </a-col>
- </a-row>
- </a-form>
- </a-col>
- <a-divider style="height: 38px" direction="vertical" />
- <a-col :flex="'86px'" style="text-align: right">
- <a-space direction="vertical" :size="18">
- <a-button type="primary" @click="search">
- <template #icon>
- <icon-search />
- </template>
- {{ $t('searchTable.form.search') }}
- </a-button>
- </a-space>
- </a-col>
- </a-row>
- <a-divider style="margin-top: 0" />
- <a-row style="margin-bottom: 16px">
- <a-col :span="12">
- <a-space>
- <a-button type="primary" @click="onAdd">
- <template #icon>
- <icon-plus />
- </template>
- {{ $t('searchTable.operation.create') }}
- </a-button>
- </a-space>
- </a-col>
- <a-col :span="12" style="
- display: flex;
- align-items: center;
- justify-content: end;
- ">
- <a-tooltip :content="$t('searchTable.actions.refresh')">
- <div class="action-icon" @click="search"><icon-refresh size="18" /></div>
- </a-tooltip>
- <a-dropdown @select="handleSelectDensity">
- <a-tooltip :content="$t('searchTable.actions.density')">
- <div class="action-icon"><icon-line-height size="18" /></div>
- </a-tooltip>
- <template #content>
- <a-doption v-for="item in densityList" :key="item.value" :value="item.value"
- :class="{ active: item.value === size }">
- <span>{{ item.name }}</span>
- </a-doption>
- </template>
- </a-dropdown>
- <a-tooltip :content="$t('searchTable.actions.columnSetting')">
- <a-popover trigger="click" position="bl" @popup-visible-change="popupVisibleChange">
- <div class="action-icon"><icon-settings size="18" /></div>
- <template #content>
- <div id="tableSetting">
- <div v-for="(item, index) in showColumns" :key="item.dataIndex" class="setting">
- <div style="
- margin-right: 4px;
- cursor: move;
- ">
- <icon-drag-arrow />
- </div>
- <div>
- <a-checkbox v-model="item.checked" @change="
- handleChange(
- $event,
- item as TableColumnData,
- index
- )
- ">
- </a-checkbox>
- </div>
- <div class="title">
- {{
- item.title === '#'
- ? '序列号'
- : item.title
- }}
- </div>
- </div>
- </div>
- </template>
- </a-popover>
- </a-tooltip>
- </a-col>
- </a-row>
- <a-table row-key="id" :loading="loading" :pagination="pagination"
- :columns="(cloneColumns as TableColumnData[])" :data="renderData" :bordered="{ headerCell: true }"
- :size="size" @page-change="onPageChange" @page-size-change="onPageSizeChange">
- <template #index="{ record }">
- {{ record.id }}
- </template>
- <template #platform="{ record }">
- <a-tag color="blue">{{ record.platform }}</a-tag>
- </template>
- <template #original_text="{ record }">
- <a-typography-paragraph :ellipsis="{ rows: 2 }">
- {{ record.original_text }}
- </a-typography-paragraph>
- </template>
- <template #rule="{ record }">
- <a-tag v-if="record.rule === 'keyword'" color="blue">关键词</a-tag>
- <a-tag v-else-if="record.rule === 'regex'" color="orange">正则</a-tag>
- <a-tag v-else-if="record.rule === 'text'" color="green">全文匹配</a-tag>
- <a-tag v-else>{{ record.rule }}</a-tag>
- </template>
- <template #output="{ record }">
- <div>
- <a-tag v-if="record.output_type === 'content'" color="arcoblue">原文处理</a-tag>
- <a-tag v-else-if="record.output_type === 'deeplink'" color="purple">深度链接</a-tag>
- <a-tag v-else-if="record.output_type === 'url'" color="cyan">URL</a-tag>
- <a-tag v-else>{{ record.output_type }}</a-tag>
- </div>
- <a-typography-paragraph :ellipsis="{ rows: 2 }">
- <a-typography-text>
- {{ record.output_text }}
- </a-typography-text>
- </a-typography-paragraph>
- <div>
- <a-tag :color="record.response_success ? 'green' : 'red'" size="small">
- success: {{ record.response_success ? '成功' : '失败' }}
- </a-tag>
- </div>
- <a-typography-text v-if="record.response_message || record.response_reason" type="secondary"
- style="font-size: 12px;">
- <span v-if="record.response_message">message: {{ record.response_message }}</span>
- <span v-if="record.response_message && record.response_reason">;</span>
- <span v-if="record.response_reason">reason: {{ record.response_reason }}</span>
- </a-typography-text>
- </template>
- <template #status="{ record }">
- <a-tag v-if="record.status" bordered color="green">
- <template #icon>
- <icon-check />
- </template>
- 启用
- </a-tag>
- <a-tag v-else bordered color="">
- <template #icon>
- <icon-stop />
- </template>
- 禁用
- </a-tag>
- </template>
- <template #limits="{ record }">
- <div style="font-size: 12px; color: #666;">
- <div>日限: {{ record.current_daily_calls || 0 }}/{{ record.daily_calls_limit }}</div>
- <div>时限: {{ record.current_hourly_calls || 0 }}/{{ record.hourly_calls_limit }}</div>
- <div v-if="record.use_special_text === 1">验证入参: special_text</div>
- <div v-if="record.use_risk_control === 1">启用风控</div>
- </div>
- </template>
- <template #description="{ record }">
- <a-typography-paragraph v-if="record.description" :ellipsis="{ rows: 2 }">
- <a-typography-text type="secondary">
- {{ record.description }}
- </a-typography-text>
- </a-typography-paragraph>
- <span v-else style="color: #ccc;">-</span>
- </template>
- <template #time="{ record }">
- <div style="color:gray;">
- <div>添加:{{ dayjs(record.create_time).format('MM-DD HH:mm') }}</div>
- <div>更新:{{ dayjs(record.last_time).format('MM-DD HH:mm') }}</div>
- </div>
- </template>
- <template #command="{ record }">
- <a-space>
- <a-button type="primary" size="small" @click="onEdit(record)">
- 修改
- </a-button>
- <a-button status="danger" size="small" @click="onDelete(record)">
- 删除
- </a-button>
- </a-space>
- </template>
- </a-table>
- </a-card>
- <a-modal v-model:visible="visible" :title="isEdit ? '修改覆盖规则' : '新建覆盖规则'" @ok="handleSubmit"
- @cancel="handleCancel" width="800px">
- <a-form :model="editForm" layout="vertical">
- <a-row :gutter="24">
- <a-col :span="12">
- <a-form-item label="平台" required>
- <a-input v-model="editForm.platform" placeholder="请输入平台标识,如:tk、jd、pdd" />
- </a-form-item>
- </a-col>
- <a-col :span="12">
- <a-form-item label="规则类型" required>
- <a-select v-model="editForm.rule" :options="ruleOptions" placeholder="请选择规则类型" />
- </a-form-item>
- </a-col>
- <a-col :span="24">
- <a-form-item label="原始文本/参考关键词" required>
- <template #extra>
- <div>如请求传入 query_text 参数,将替代此文本进行匹配</div>
- </template>
- <a-textarea v-model="editForm.original_text" placeholder="请输入原始文本或正则表达式"
- :auto-size="{ minRows: 2, maxRows: 4 }" />
- </a-form-item>
- </a-col>
- <a-col :span="12">
- <a-form-item label="输出类型" required>
- <a-select v-model="editForm.output_type" :options="outputTypeOptions"
- placeholder="请选择输出类型" />
- </a-form-item>
- </a-col>
- <a-col :span="12">
- <a-form-item label="权重(优先级)">
- <a-input-number v-model="editForm.sort" placeholder="数值越大越优先" :min="0"
- style="width: 100%;" />
- </a-form-item>
- </a-col>
- <a-col :span="24">
- <a-form-item label="输出文本" required>
- <template #extra>
- <div>支持占位符:{query_text}、{url:query_text}、{url2:query_text}</div>
- </template>
- <a-textarea v-model="editForm.output_text" placeholder="请输入替换后的文本"
- :auto-size="{ minRows: 2, maxRows: 4 }" />
- </a-form-item>
- </a-col>
- <a-col :span="24">
- <a-divider orientation="left" style="margin-top: 0;">响应字段覆写</a-divider>
- </a-col>
- <a-col :span="8">
- <a-form-item label="响应结果 success" required>
- <a-radio-group v-model="editForm.response_success" type="button">
- <a-radio :value="true">成功</a-radio>
- <a-radio :value="false">失败</a-radio>
- </a-radio-group>
- </a-form-item>
- </a-col>
- <a-col :span="8">
- <a-form-item label="message">
- <a-input v-model="editForm.response_message" placeholder="留空沿用默认值" allow-clear
- :max-length="255" />
- </a-form-item>
- </a-col>
- <a-col :span="8">
- <a-form-item label="reason / sub_message">
- <a-input v-model="editForm.response_reason" placeholder="留空沿用默认值" allow-clear
- :max-length="255" />
- </a-form-item>
- </a-col>
- <a-col :span="24">
- <div style="font-size: 12px; color: #999; margin: -12px 0 16px;">
- 命中本规则后,API 响应及转链日志(后续统计)中的 success/message/reason 将使用此处配置;reason 同时作为 sub_message 输出
- </div>
- </a-col>
- <a-col :span="24">
- <a-form-item label="备注">
- <a-textarea v-model="editForm.description" placeholder="请输入备注说明"
- :auto-size="{ minRows: 2, maxRows: 3 }" />
- </a-form-item>
- </a-col>
- <a-col :span="12">
- <a-form-item label="每日调用限制">
- <a-input-number v-model="editForm.daily_calls_limit" placeholder="0表示不限制" :min="0"
- style="width: 100%;" />
- </a-form-item>
- </a-col>
- <a-col :span="12">
- <a-form-item label="每小时调用限制">
- <a-input-number v-model="editForm.hourly_calls_limit" placeholder="0表示不限制" :min="0"
- style="width: 100%;" />
- </a-form-item>
- </a-col>
- <a-col :span="12">
- <a-form-item label="验证入参 special_text">
- <a-switch v-model="editForm.use_special_text" :checked-value="1" :unchecked-value="0"
- checked-text="是" unchecked-text="否" />
- <div style="font-size: 12px; color: #999; margin-top: 4px;">
- 是否仅在入参 special_text=1 时匹配
- </div>
- </a-form-item>
- </a-col>
- <a-col :span="12">
- <a-form-item label="启用风控">
- <a-switch v-model="editForm.use_risk_control" :checked-value="1" :unchecked-value="0"
- checked-text="是" unchecked-text="否" />
- <div style="font-size: 12px; color: #999; margin-top: 4px;">
- OAID/地区/IP控制
- </div>
- </a-form-item>
- </a-col>
- <a-col :span="12">
- <a-form-item label="状态">
- <a-switch v-model="editForm.status" :checked-value="true" :unchecked-value="false"
- checked-text="启用" unchecked-text="禁用" />
- </a-form-item>
- </a-col>
- </a-row>
- </a-form>
- </a-modal>
- </div>
- </template>
- <script lang="ts" setup>
- import { computed, ref, reactive, watch, nextTick } from 'vue';
- import { useI18n } from 'vue-i18n';
- import dayjs from 'dayjs';
- import useLoading from '@/hooks/loading';
- import { Pagination } from '@/types/global';
- import { Modal, Message } from '@arco-design/web-vue';
- import type { SelectOptionData } from '@arco-design/web-vue/es/select/interface';
- import type { TableColumnData } from '@arco-design/web-vue/es/table/interface';
- import cloneDeep from 'lodash/cloneDeep';
- import Sortable from 'sortablejs';
- import {
- OverrideRuleParams,
- OverrideRuleRecord,
- queryOverrideRuleList,
- updateOverrideRule,
- createOverrideRule,
- deleteOverrideRule
- } from '@/api/overrideRules';
- type SizeProps = 'mini' | 'small' | 'medium' | 'large';
- type Column = TableColumnData & { checked?: true };
- const generateFormModel = () => {
- return {
- keyword: '',
- sort: 'sort',
- order: 'descending',
- };
- };
- const { loading, setLoading } = useLoading(true);
- const { t } = useI18n();
- const renderData = ref<OverrideRuleRecord[]>([]);
- const formModel = ref(generateFormModel());
- const cloneColumns = ref<Column[]>([]);
- const showColumns = ref<Column[]>([]);
- const size = ref<SizeProps>('small');
- const basePagination: Pagination = {
- current: 1,
- pageSize: 50,
- showPageSize: true,
- showTotal: true,
- pageSizeOptions: [20, 50, 100],
- };
- const pagination = reactive({
- ...basePagination,
- });
- const densityList = computed(() => [
- {
- name: t('searchTable.size.mini'),
- value: 'mini',
- },
- {
- name: t('searchTable.size.small'),
- value: 'small',
- },
- {
- name: t('searchTable.size.medium'),
- value: 'medium',
- },
- {
- name: t('searchTable.size.large'),
- value: 'large',
- },
- ]);
- const columns = computed<TableColumnData[]>(() => [
- {
- title: '#',
- dataIndex: 'index',
- slotName: 'index',
- width: 60,
- },
- {
- title: '平台',
- slotName: 'platform',
- width: 100,
- },
- {
- title: '原始文本',
- slotName: 'original_text',
- width: 180,
- },
- {
- title: '规则类型',
- slotName: 'rule',
- width: 120,
- },
- {
- title: '输出',
- slotName: 'output',
- width: 180,
- },
- {
- title: '限制条件',
- slotName: 'limits',
- width: 150,
- },
- {
- title: '备注',
- slotName: 'description',
- width: 150,
- },
- {
- title: '状态',
- slotName: 'status',
- width: 100,
- },
- {
- title: '权重',
- dataIndex: 'sort',
- width: 80,
- },
- {
- title: '时间',
- slotName: 'time',
- width: 170,
- },
- {
- title: '操作',
- slotName: 'command',
- width: 150,
- },
- ]);
- const ruleOptions = computed<SelectOptionData[]>(() => [
- { label: '关键词', value: 'keyword' },
- { label: '正则', value: 'regex' },
- { label: '全文匹配', value: 'text' },
- ]);
- const outputTypeOptions = computed<SelectOptionData[]>(() => [
- { label: '原文处理', value: 'content' },
- { label: '深度链接', value: 'deeplink' },
- { label: 'URL', value: 'url' },
- ]);
- const fetchData = async (
- params: OverrideRuleParams = {
- current: 1,
- pageSize: 50,
- sort: 'sort',
- order: 'descending',
- getTotal: true,
- }
- ) => {
- setLoading(true);
- try {
- const { data } = await queryOverrideRuleList(params);
- if (!data) return;
- renderData.value = data.list;
- pagination.current = data.page;
- pagination.total = data.count;
- } catch (err) {
- console.log(err);
- } finally {
- setLoading(false);
- }
- };
- const search = () => {
- fetchData({
- ...basePagination,
- ...formModel.value,
- } as unknown as OverrideRuleParams);
- };
- const onPageChange = (current: number) => {
- fetchData({
- ...basePagination,
- ...formModel.value,
- current
- } as unknown as OverrideRuleParams);
- };
- const onPageSizeChange = (pageSize: number) => {
- basePagination.pageSize = pageSize;
- pagination.pageSize = pageSize;
- fetchData({
- ...basePagination,
- ...formModel.value,
- current: 1,
- } as unknown as OverrideRuleParams);
- };
- const visible = ref(false);
- const isEdit = ref(false);
- const editForm = ref<Partial<OverrideRuleRecord>>({
- platform: '',
- original_text: '',
- rule: 'keyword',
- output_text: '',
- output_type: 'content',
- status: true,
- sort: 0,
- description: '',
- daily_calls_limit: 0,
- hourly_calls_limit: 0,
- use_special_text: 0,
- use_risk_control: 0,
- response_success: true,
- response_message: '',
- response_reason: '',
- });
- const onEdit = (current: OverrideRuleRecord) => {
- isEdit.value = true;
- editForm.value = {
- ...current,
- status: Boolean(current.status),
- response_success: Boolean(current.response_success ?? true),
- };
- visible.value = true;
- };
- const onAdd = () => {
- isEdit.value = false;
- editForm.value = {
- platform: '',
- original_text: '',
- rule: 'keyword',
- output_text: '',
- output_type: 'content',
- status: true,
- sort: 0,
- description: '',
- daily_calls_limit: 0,
- hourly_calls_limit: 0,
- use_special_text: 0,
- use_risk_control: 0,
- response_success: true,
- response_message: '',
- response_reason: '',
- };
- visible.value = true;
- };
- const onDelete = (current: OverrideRuleRecord) => {
- Modal.confirm({
- title: '确认删除',
- content: '确定要删除这条规则吗?删除后无法恢复。',
- onOk: async () => {
- try {
- const response = await deleteOverrideRule(current.id);
- if (response.data.success) {
- Message.success(response.data.msg || '删除成功');
- fetchData({
- ...basePagination,
- ...formModel.value,
- } as unknown as OverrideRuleParams);
- } else {
- Message.error(response.data.msg || '删除失败');
- }
- } catch (error) {
- Message.error('删除请求失败');
- }
- }
- });
- };
- fetchData();
- const handleSelectDensity = (
- val: string | number | Record<string, any> | undefined,
- e: Event
- ) => {
- size.value = val as SizeProps;
- };
- const handleChange = (
- checked: boolean | (string | boolean | number)[],
- column: Column,
- index: number
- ) => {
- if (!checked) {
- cloneColumns.value = showColumns.value.filter(
- (item) => item.dataIndex !== column.dataIndex
- );
- } else {
- cloneColumns.value.splice(index, 0, column);
- }
- };
- const exchangeArray = <T extends Array<any>>(
- array: T,
- beforeIdx: number,
- newIdx: number,
- isDeep = false
- ): T => {
- const newArray = isDeep ? cloneDeep(array) : array;
- if (beforeIdx > -1 && newIdx > -1) {
- newArray.splice(
- beforeIdx,
- 1,
- newArray.splice(newIdx, 1, newArray[beforeIdx]).pop()
- );
- }
- return newArray;
- };
- const popupVisibleChange = (val: boolean) => {
- if (val) {
- nextTick(() => {
- const el = document.getElementById('tableSetting') as HTMLElement;
- const sortable = new Sortable(el, {
- onEnd(e: any) {
- const { oldIndex, newIndex } = e;
- exchangeArray(cloneColumns.value, oldIndex, newIndex);
- exchangeArray(showColumns.value, oldIndex, newIndex);
- },
- });
- });
- }
- };
- const handleSubmit = async () => {
- try {
- let response;
- if (isEdit.value) {
- response = await updateOverrideRule(editForm.value as OverrideRuleRecord);
- } else {
- response = await createOverrideRule(editForm.value);
- }
- if (response.data.success) {
- Message.success(response.data.msg || '操作成功');
- visible.value = false;
- fetchData({
- ...basePagination,
- ...formModel.value,
- } as unknown as OverrideRuleParams);
- } else {
- Message.error(response.data.msg || '操作失败');
- }
- } catch (error) {
- Message.error('请求失败');
- }
- };
- const handleCancel = () => {
- visible.value = false;
- };
- watch(
- () => columns.value,
- (val) => {
- cloneColumns.value = cloneDeep(val);
- cloneColumns.value.forEach((item, index) => {
- item.checked = true;
- });
- showColumns.value = cloneDeep(cloneColumns.value);
- },
- { deep: true, immediate: true }
- );
- </script>
- <script lang="ts">
- export default {
- name: 'OverrideRules',
- };
- </script>
- <style scoped lang="less">
- .container {
- padding: 0 20px 20px 20px;
- }
- :deep(.arco-table-th) {
- &:last-child {
- .arco-table-th-item-title {
- margin-left: 16px;
- }
- }
- }
- .action-icon {
- margin-left: 12px;
- cursor: pointer;
- }
- .active {
- color: #0960bd;
- background-color: #e3f4fc;
- }
- .setting {
- display: flex;
- align-items: center;
- width: 200px;
- .title {
- margin-left: 12px;
- cursor: pointer;
- }
- }
- </style>
|