|  |  |  | 
|---|
|  |  |  | <template> | 
|---|
|  |  |  | <LoadingLayout :loading="state.loading"> | 
|---|
|  |  |  | <AppContainer> | 
|---|
|  |  |  | <ProTableQueryFilterBar @on-reset="reset"> | 
|---|
|  |  |  | <ProTableQueryFilterBar @on-reset="handleReset"> | 
|---|
|  |  |  | <template #query> | 
|---|
|  |  |  | <QueryFilterItem> | 
|---|
|  |  |  | <FieldSelect | 
|---|
|  |  |  | v-model="extraParamState.searchType" | 
|---|
|  |  |  | v-model="extraParamState.categoryId" | 
|---|
|  |  |  | @change="getList()" | 
|---|
|  |  |  | :value-enum="SearchTypeText" | 
|---|
|  |  |  | :value-enum="dictionaryCategoryList" | 
|---|
|  |  |  | placeholder="请选择所属类别" | 
|---|
|  |  |  | ></FieldSelect> | 
|---|
|  |  |  | </QueryFilterItem> | 
|---|
|  |  |  | <QueryFilterItem v-if="extraParamState.searchType === SearchType.Position"> | 
|---|
|  |  |  | <FieldSelect | 
|---|
|  |  |  | v-model="extraParamState.parentId" | 
|---|
|  |  |  | @change="getList()" | 
|---|
|  |  |  | :value-enum="typeList" | 
|---|
|  |  |  | enum-label-key="name" | 
|---|
|  |  |  | enum-value-key="id" | 
|---|
|  |  |  | placeholder="请选择行业类型" | 
|---|
|  |  |  | clearable | 
|---|
|  |  |  | ></FieldSelect> | 
|---|
|  |  |  | </QueryFilterItem> | 
|---|
|  |  |  | <QueryFilterItem> | 
|---|
|  |  |  | <SearchInput | 
|---|
|  |  |  | v-model="extraParamState.name" | 
|---|
|  |  |  | v-model="extraParamState.keywords" | 
|---|
|  |  |  | style="width: 200px" | 
|---|
|  |  |  | placeholder="请输入名称" | 
|---|
|  |  |  | @on-click-search="getList" | 
|---|
|  |  |  | 
|---|
|  |  |  | </template> | 
|---|
|  |  |  | </ProTableQueryFilterBar> | 
|---|
|  |  |  | <ProTableV2 v-bind="proTableProps" :columns="column" :operationBtns="operationBtns"> | 
|---|
|  |  |  | <template #columns="{ row, column }"> | 
|---|
|  |  |  | <template v-if="column.property === 'status'"> | 
|---|
|  |  |  | <FieldSwitch | 
|---|
|  |  |  | v-model="row.status" | 
|---|
|  |  |  | active-text="显示" | 
|---|
|  |  |  | inactive-text="隐藏" | 
|---|
|  |  |  | :before-change="() => setCategoryVis(row)" | 
|---|
|  |  |  | /> | 
|---|
|  |  |  | </template> | 
|---|
|  |  |  | <template #isDisabled="{ row }"> | 
|---|
|  |  |  | <FieldSwitch | 
|---|
|  |  |  | v-model="row.isDisabled" | 
|---|
|  |  |  | active-text="启用" | 
|---|
|  |  |  | inactive-text="禁用" | 
|---|
|  |  |  | :active-value="false" | 
|---|
|  |  |  | :inactive-value="true" | 
|---|
|  |  |  | :before-change="() => setCategoryVis(row)" | 
|---|
|  |  |  | /> | 
|---|
|  |  |  | </template> | 
|---|
|  |  |  | </ProTableV2> | 
|---|
|  |  |  | </AppContainer> | 
|---|
|  |  |  | <AddOrEditSearchSetting v-bind="dialogProps" :typeList="typeList" /> | 
|---|
|  |  |  | <AddOrEditDictionaryDialog v-bind="dialogProps" /> | 
|---|
|  |  |  | </LoadingLayout> | 
|---|
|  |  |  | </template> | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | UploadUserFile, | 
|---|
|  |  |  | FieldSwitch, | 
|---|
|  |  |  | FieldSelect, | 
|---|
|  |  |  | FieldRadio, | 
|---|
|  |  |  | } from '@bole-core/components'; | 
|---|
|  |  |  | import { useAccess } from '@/hooks'; | 
|---|
|  |  |  | import { | 
|---|
|  |  |  | SearchType, | 
|---|
|  |  |  | SearchTypeText, | 
|---|
|  |  |  | // BelongType, | 
|---|
|  |  |  | // BelongTypeText, | 
|---|
|  |  |  | BooleanOptions, | 
|---|
|  |  |  | } from '@/constants'; | 
|---|
|  |  |  | import { OrderInputType, Message } from '@bole-core/core'; | 
|---|
|  |  |  | import AddOrEditSearchSetting from './components/AddOrEditSearchSetting.vue'; | 
|---|
|  |  |  | import { convertApi2FormUrl } from '@/utils'; | 
|---|
|  |  |  | import { useQueryClient } from '@tanstack/vue-query'; | 
|---|
|  |  |  | import { useAccess, useDictionaryDataSelect, useGetDictionaryCategorySelect } from '@/hooks'; | 
|---|
|  |  |  | import { Message } from '@bole-core/core'; | 
|---|
|  |  |  | import AddOrEditDictionaryDialog from './components/AddOrEditDictionaryDialog.vue'; | 
|---|
|  |  |  | import { convertApi2FormUrl, convertApi2FormUrlOnlyOne } from '@/utils'; | 
|---|
|  |  |  | import * as dictionaryServices from '@/services/api/dictionary'; | 
|---|
|  |  |  | import { CategoryCode } from '@/constants'; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | defineOptions({ | 
|---|
|  |  |  | name: 'DataDictionary', | 
|---|
|  |  |  | 
|---|
|  |  |  | operationBtnMap, | 
|---|
|  |  |  | }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const { dictionaryCategoryList, ensureQueryData } = useGetDictionaryCategorySelect(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const { getDictionaryDataNameByCode, updateDictionaryDataSelect } = useDictionaryDataSelect({ | 
|---|
|  |  |  | categoryCode: CategoryCode.IndustryCategory, | 
|---|
|  |  |  | }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const BaseState = { | 
|---|
|  |  |  | loading: true, | 
|---|
|  |  |  | }; | 
|---|
|  |  |  | const queryClient = useQueryClient(); | 
|---|
|  |  |  | const typeList = ref([]); | 
|---|
|  |  |  | const state = reactive({ ...BaseState }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | onMounted(async () => { | 
|---|
|  |  |  | const dictionaryCategoryList = await ensureQueryData(); | 
|---|
|  |  |  | if (dictionaryCategoryList.length > 0) { | 
|---|
|  |  |  | extraParamState.categoryId = dictionaryCategoryList[0].value; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | await getList(); | 
|---|
|  |  |  | state.loading = false; | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | 
|---|
|  |  |  | } = useTable( | 
|---|
|  |  |  | async ({ pageIndex, pageSize }, extraParamState) => { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | let params: API.GetSearchSettingListInput = { | 
|---|
|  |  |  | let params: API.GetDictionaryDatasQuery = { | 
|---|
|  |  |  | pageModel: { | 
|---|
|  |  |  | rows: pageSize, | 
|---|
|  |  |  | page: pageIndex, | 
|---|
|  |  |  | orderInput: extraParamState.orderInput, | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | name: extraParamState.name, | 
|---|
|  |  |  | // belongType: Number(extraParamState.belongType), | 
|---|
|  |  |  | searchType: Number(extraParamState.searchType), | 
|---|
|  |  |  | status: extraParamState.status, | 
|---|
|  |  |  | categoryId: extraParamState.categoryId, | 
|---|
|  |  |  | keywords: extraParamState.keywords, | 
|---|
|  |  |  | }; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (extraParamState.searchType === SearchType.Position) { | 
|---|
|  |  |  | params.isRecommend = extraParamState.isRecommend; | 
|---|
|  |  |  | params.parentId = extraParamState.parentId; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | let res = await searchSettingServices.getSearchSettingList(params, { | 
|---|
|  |  |  | let res = await dictionaryServices.getDictionaryDatas(params, { | 
|---|
|  |  |  | showLoading: !state.loading, | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | return res; | 
|---|
|  |  |  | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | { | 
|---|
|  |  |  | defaultExtraParams: { | 
|---|
|  |  |  | name: '', | 
|---|
|  |  |  | searchType: SearchType.Identity, | 
|---|
|  |  |  | orderInput: [{ property: 'sort', order: OrderInputType.Asc }], | 
|---|
|  |  |  | status: '' as any as boolean, | 
|---|
|  |  |  | isRecommend: '' as any as boolean, | 
|---|
|  |  |  | parentId: '', | 
|---|
|  |  |  | categoryId: '', | 
|---|
|  |  |  | keywords: '', | 
|---|
|  |  |  | orderInput: [{ property: 'sort', order: EnumPagedListOrder.Asc }], | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | queryKey: ['searchSettingServices/getSearchSettingList'], | 
|---|
|  |  |  | queryKey: ['dictionaryServices/getDictionaryDatas'], | 
|---|
|  |  |  | columnsRenderProps: { | 
|---|
|  |  |  | searchType: { type: 'enum', valueEnum: SearchTypeText }, | 
|---|
|  |  |  | field1: { | 
|---|
|  |  |  | formatter(row: API.GetDictionaryDatasQueryResultItem) { | 
|---|
|  |  |  | return row.categoryCode == CategoryCode.Position | 
|---|
|  |  |  | ? getDictionaryDataNameByCode(row.field1) | 
|---|
|  |  |  | : ''; | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | } | 
|---|
|  |  |  | ); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | function openDialog(row?: API.GetSearchSettingList) { | 
|---|
|  |  |  | function openDialog(row?: API.GetDictionaryDatasQueryResultItem) { | 
|---|
|  |  |  | if (row) { | 
|---|
|  |  |  | handleEdit({ | 
|---|
|  |  |  | id: row.id, | 
|---|
|  |  |  | searchType: extraParamState.searchType, | 
|---|
|  |  |  | name: row.name, | 
|---|
|  |  |  | categoryId: row.categoryId, | 
|---|
|  |  |  | code: row.code, | 
|---|
|  |  |  | content: row.content, | 
|---|
|  |  |  | sort: row.sort, | 
|---|
|  |  |  | status: row.status, | 
|---|
|  |  |  | src: row.src?.length ? [convertApi2FormUrl(row.src)] : [], | 
|---|
|  |  |  | parentId: row.parentId ?? '', | 
|---|
|  |  |  | isDisabled: row.isDisabled, | 
|---|
|  |  |  | field1: row.field1, | 
|---|
|  |  |  | field3: row.field3, | 
|---|
|  |  |  | field2: convertApi2FormUrlOnlyOne(row.field2), | 
|---|
|  |  |  | field4: row.field4, | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | handleAdd({ | 
|---|
|  |  |  | searchType: extraParamState.searchType, | 
|---|
|  |  |  | categoryId: extraParamState.categoryId, | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | onConfirm: handleAddOrEdit, | 
|---|
|  |  |  | defaultFormParams: { | 
|---|
|  |  |  | id: '', | 
|---|
|  |  |  | searchType: SearchType.Identity, | 
|---|
|  |  |  | name: '', | 
|---|
|  |  |  | categoryId: '', | 
|---|
|  |  |  | code: '', | 
|---|
|  |  |  | content: '', | 
|---|
|  |  |  | sort: 0, | 
|---|
|  |  |  | status: true, | 
|---|
|  |  |  | src: [] as UploadUserFile[], | 
|---|
|  |  |  | parentId: '', | 
|---|
|  |  |  | isDisabled: false, | 
|---|
|  |  |  | field1: '', | 
|---|
|  |  |  | field2: [] as UploadUserFile[], | 
|---|
|  |  |  | field3: '', | 
|---|
|  |  |  | field4: '', | 
|---|
|  |  |  | title: '新增字典', | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | editTitle: '编辑字典', | 
|---|
|  |  |  | }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | async function handleAddOrEdit() { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | let params: API.CreateOrEditSearchInput = { | 
|---|
|  |  |  | searchType: extraParamState.searchType, | 
|---|
|  |  |  | name: editForm.name, | 
|---|
|  |  |  | let params: API.SaveDictionaryDataCommand = { | 
|---|
|  |  |  | categoryId: editForm.categoryId, | 
|---|
|  |  |  | code: editForm.code, | 
|---|
|  |  |  | sort: editForm.sort, | 
|---|
|  |  |  | status: editForm.status, | 
|---|
|  |  |  | src: editForm.src?.[0]?.path ?? '', | 
|---|
|  |  |  | parentId: editForm.parentId ?? '', | 
|---|
|  |  |  | content: editForm.content, | 
|---|
|  |  |  | isDisabled: editForm.isDisabled, | 
|---|
|  |  |  | field1: editForm.field1, | 
|---|
|  |  |  | field2: editForm.field2?.[0]?.path ?? '', | 
|---|
|  |  |  | field3: editForm.field3, | 
|---|
|  |  |  | field4: editForm.field4, | 
|---|
|  |  |  | }; | 
|---|
|  |  |  | if (editForm.id) { | 
|---|
|  |  |  | params.id = editForm.id; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | let res = await searchSettingServices.createOrEditSearchSetting(params); | 
|---|
|  |  |  | let res = await dictionaryServices.saveDictionaryData(params); | 
|---|
|  |  |  | if (res) { | 
|---|
|  |  |  | Message.successMessage('操作成功'); | 
|---|
|  |  |  | updateDictionaryDataSelect(editForm.categoryId); | 
|---|
|  |  |  | getList(paginationState.pageIndex); | 
|---|
|  |  |  | dialogState.dialogVisible = false; | 
|---|
|  |  |  | updateCategoryMenu(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (error) {} | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | function updateCategoryMenu() { | 
|---|
|  |  |  | queryClient.invalidateQueries({ | 
|---|
|  |  |  | queryKey: [ | 
|---|
|  |  |  | 'searchSettingServices/getTypeSearchSettingList', | 
|---|
|  |  |  | { searchType: extraParamState.searchType, belongType: null }, | 
|---|
|  |  |  | ], | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | async function setCategoryVis(row: API.GetSearchSettingList) { | 
|---|
|  |  |  | async function setCategoryVis(row: API.GetDictionaryDatasQueryResultItem) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | let params: API.EnableSearchSettingInput = { | 
|---|
|  |  |  | id: row.id, | 
|---|
|  |  |  | status: !row.status, | 
|---|
|  |  |  | await Message.tipMessage(`确认要${row.isDisabled ? '启用' : '禁用'}吗?`); | 
|---|
|  |  |  | let params: API.SetDictionaryDataIsDisabledCommand = { | 
|---|
|  |  |  | ids: [row.id], | 
|---|
|  |  |  | isDisabled: !row.isDisabled, | 
|---|
|  |  |  | }; | 
|---|
|  |  |  | let res = await searchSettingServices.enableSearchSetting(params); | 
|---|
|  |  |  | updateCategoryMenu(); | 
|---|
|  |  |  | let res = await dictionaryServices.setDictionaryDataIsDisabled(params); | 
|---|
|  |  |  | updateDictionaryDataSelect(row.categoryId); | 
|---|
|  |  |  | getList(paginationState.pageIndex); | 
|---|
|  |  |  | return !!res; | 
|---|
|  |  |  | } catch (error) {} | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | async function handleReset() { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | const dictionaryCategoryList = await ensureQueryData(); | 
|---|
|  |  |  | reset({ categoryId: dictionaryCategoryList[0].value }); | 
|---|
|  |  |  | } catch (error) {} | 
|---|
|  |  |  | } | 
|---|
|  |  |  | </script> | 
|---|