2022-08-26 20:15:36 +08:00
|
|
|
|
<template>
|
2025-04-18 22:07:37 +08:00
|
|
|
|
<div class="h-full">
|
2024-11-20 22:43:53 +08:00
|
|
|
|
<page-table
|
|
|
|
|
|
ref="pageTableRef"
|
|
|
|
|
|
:search-items="searchItems"
|
|
|
|
|
|
:page-api="configApi.list"
|
|
|
|
|
|
:columns="columns"
|
|
|
|
|
|
v-model:query-form="query"
|
|
|
|
|
|
:data-handler-fn="handleData"
|
|
|
|
|
|
>
|
2023-12-12 23:31:53 +08:00
|
|
|
|
<template #tableHeader>
|
2025-05-24 16:22:54 +08:00
|
|
|
|
<el-button v-auth="perms.saveConfig" type="primary" icon="plus" @click="onEditConfig(false)">{{ $t('common.create') }}</el-button>
|
2023-06-28 21:35:03 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<template #status="{ data }">
|
2024-11-20 22:43:53 +08:00
|
|
|
|
<el-tag v-if="data.status == 1" type="success">{{ $t('common.enable') }}</el-tag>
|
|
|
|
|
|
<el-tag v-if="data.status == -1" type="danger">{{ $t('common.disable') }}</el-tag>
|
2023-06-28 21:35:03 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<template #action="{ data }">
|
2024-11-20 22:43:53 +08:00
|
|
|
|
<el-button :disabled="data.status == -1" type="warning" @click="showSetConfigDialog(data)" link>{{ $t('system.sysconf.conf') }}</el-button>
|
2025-05-24 16:22:54 +08:00
|
|
|
|
<el-button v-if="actionBtns[perms.saveConfig]" @click="onEditConfig(data)" type="primary" link>{{ $t('common.edit') }}</el-button>
|
2023-06-28 21:35:03 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
</page-table>
|
2022-08-26 20:15:36 +08:00
|
|
|
|
|
2025-05-24 16:22:54 +08:00
|
|
|
|
<el-dialog @close="onCloseSetConfigDialog" :title="$t('system.sysconf.confItemSetting')" v-model="paramsDialog.visible" width="700px">
|
2023-12-09 16:17:26 +08:00
|
|
|
|
<dynamic-form
|
|
|
|
|
|
ref="paramsFormRef"
|
|
|
|
|
|
v-if="paramsDialog.paramsFormItem.length > 0"
|
|
|
|
|
|
:form-items="paramsDialog.paramsFormItem"
|
|
|
|
|
|
v-model="paramsDialog.params"
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
2023-07-03 21:42:04 +08:00
|
|
|
|
<el-form v-else ref="paramsFormRef" label-width="auto">
|
2024-11-20 22:43:53 +08:00
|
|
|
|
<el-form-item :label="$t('system.sysconf.confValue')" required>
|
2023-07-06 20:59:22 +08:00
|
|
|
|
<el-input v-model="paramsDialog.params" :placeholder="paramsDialog.config.remark" autocomplete="off" clearable></el-input>
|
2022-10-26 20:49:29 +08:00
|
|
|
|
</el-form-item>
|
|
|
|
|
|
</el-form>
|
2023-12-09 16:17:26 +08:00
|
|
|
|
|
2022-10-26 20:49:29 +08:00
|
|
|
|
<template #footer>
|
|
|
|
|
|
<span class="dialog-footer">
|
2025-05-24 16:22:54 +08:00
|
|
|
|
<el-button @click="onCloseSetConfigDialog()">{{ $t('common.cancel') }}</el-button>
|
2024-11-20 22:43:53 +08:00
|
|
|
|
<el-button v-auth="'config:save'" type="primary" @click="setConfig()">{{ $t('common.confirm') }}</el-button>
|
2022-10-26 20:49:29 +08:00
|
|
|
|
</span>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-dialog>
|
|
|
|
|
|
|
2025-05-24 16:22:54 +08:00
|
|
|
|
<config-edit :title="$t(configEdit.title)" v-model:visible="configEdit.visible" :data="configEdit.config" @val-change="onConfigEditChange" />
|
2022-08-26 20:15:36 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
2022-10-29 20:08:15 +08:00
|
|
|
|
<script lang="ts" setup>
|
2023-12-11 01:00:09 +08:00
|
|
|
|
import { ref, toRefs, reactive, onMounted, Ref } from 'vue';
|
2022-08-26 20:15:36 +08:00
|
|
|
|
import ConfigEdit from './ConfigEdit.vue';
|
|
|
|
|
|
import { configApi } from '../api';
|
2023-07-06 20:59:22 +08:00
|
|
|
|
import PageTable from '@/components/pagetable/PageTable.vue';
|
2023-06-28 21:35:03 +08:00
|
|
|
|
import { TableColumn } from '@/components/pagetable';
|
2023-07-02 17:06:00 +08:00
|
|
|
|
import { hasPerms } from '@/components/auth/auth';
|
2023-12-09 16:17:26 +08:00
|
|
|
|
import { DynamicForm } from '@/components/dynamic-form';
|
2024-03-07 17:26:11 +08:00
|
|
|
|
import { SearchItem } from '@/components/SearchForm';
|
2024-11-20 22:43:53 +08:00
|
|
|
|
import { useI18n } from 'vue-i18n';
|
|
|
|
|
|
import { useI18nSaveSuccessMsg } from '@/hooks/useI18n';
|
|
|
|
|
|
|
|
|
|
|
|
const { t } = useI18n();
|
2023-07-02 17:06:00 +08:00
|
|
|
|
|
|
|
|
|
|
const perms = {
|
2023-07-06 20:59:22 +08:00
|
|
|
|
saveConfig: 'config:save',
|
|
|
|
|
|
};
|
2024-03-07 17:26:11 +08:00
|
|
|
|
|
2024-11-20 22:43:53 +08:00
|
|
|
|
const searchItems = [SearchItem.input('key', 'system.sysconf.confKey')];
|
2024-03-07 17:26:11 +08:00
|
|
|
|
|
2023-07-03 21:42:04 +08:00
|
|
|
|
const columns = ref([
|
2024-11-20 22:43:53 +08:00
|
|
|
|
TableColumn.new('i18nName', 'system.sysconf.confItem'),
|
|
|
|
|
|
TableColumn.new('key', 'system.sysconf.confKey'),
|
|
|
|
|
|
TableColumn.new('value', 'system.sysconf.confValue').canBeautify(),
|
|
|
|
|
|
TableColumn.new('i18nRemark', 'common.remark'),
|
|
|
|
|
|
TableColumn.new('modifier', 'common.modifier'),
|
|
|
|
|
|
TableColumn.new('updateTime', 'common.updateTime').isTime(),
|
2023-07-06 20:59:22 +08:00
|
|
|
|
]);
|
2024-11-20 22:43:53 +08:00
|
|
|
|
const actionColumn = TableColumn.new('action', 'common.operation').isSlot().fixedRight().setMinWidth(130).noShowOverflowTooltip().alignCenter();
|
2023-07-06 20:59:22 +08:00
|
|
|
|
const actionBtns = hasPerms([perms.saveConfig]);
|
|
|
|
|
|
|
2023-12-11 01:00:09 +08:00
|
|
|
|
const pageTableRef: Ref<any> = ref(null);
|
2023-07-06 20:59:22 +08:00
|
|
|
|
const paramsFormRef: any = ref(null);
|
2023-12-11 01:00:09 +08:00
|
|
|
|
|
2022-10-29 20:08:15 +08:00
|
|
|
|
const state = reactive({
|
|
|
|
|
|
query: {
|
|
|
|
|
|
pageNum: 1,
|
2023-11-29 17:34:54 +08:00
|
|
|
|
pageSize: 0,
|
2022-10-29 20:08:15 +08:00
|
|
|
|
name: null,
|
2022-08-26 20:15:36 +08:00
|
|
|
|
},
|
2023-07-01 14:34:42 +08:00
|
|
|
|
selectionData: [],
|
2022-10-29 20:08:15 +08:00
|
|
|
|
paramsDialog: {
|
|
|
|
|
|
visible: false,
|
|
|
|
|
|
config: null as any,
|
|
|
|
|
|
params: {},
|
|
|
|
|
|
paramsFormItem: [] as any,
|
|
|
|
|
|
},
|
|
|
|
|
|
configEdit: {
|
2024-11-20 22:43:53 +08:00
|
|
|
|
title: 'common.edit',
|
2022-10-29 20:08:15 +08:00
|
|
|
|
visible: false,
|
|
|
|
|
|
config: {},
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|
2022-10-26 20:49:29 +08:00
|
|
|
|
|
2024-03-07 17:26:11 +08:00
|
|
|
|
const { query, paramsDialog, configEdit } = toRefs(state);
|
2022-10-29 20:08:15 +08:00
|
|
|
|
|
|
|
|
|
|
onMounted(() => {
|
2023-07-02 17:06:00 +08:00
|
|
|
|
if (Object.keys(actionBtns).length > 0) {
|
2023-07-03 21:42:04 +08:00
|
|
|
|
columns.value.push(actionColumn);
|
2023-07-02 17:06:00 +08:00
|
|
|
|
}
|
2022-10-29 20:08:15 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const search = async () => {
|
2023-12-11 01:00:09 +08:00
|
|
|
|
pageTableRef.value.search();
|
2022-10-29 20:08:15 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2024-11-20 22:43:53 +08:00
|
|
|
|
const handleData = (res: any) => {
|
|
|
|
|
|
const dataList = res.list;
|
|
|
|
|
|
// 内容国际化
|
|
|
|
|
|
for (let x of dataList) {
|
|
|
|
|
|
x.i18nName = t(x.name);
|
|
|
|
|
|
x.i18nRemark = t(x.remark);
|
|
|
|
|
|
}
|
|
|
|
|
|
return res;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2022-10-29 20:08:15 +08:00
|
|
|
|
const showSetConfigDialog = (row: any) => {
|
|
|
|
|
|
state.paramsDialog.config = row;
|
|
|
|
|
|
// 存在配置项则弹窗提示输入对应的配置项
|
|
|
|
|
|
if (row.params) {
|
|
|
|
|
|
state.paramsDialog.paramsFormItem = JSON.parse(row.params);
|
|
|
|
|
|
if (state.paramsDialog.paramsFormItem && state.paramsDialog.paramsFormItem.length > 0) {
|
|
|
|
|
|
if (row.value) {
|
|
|
|
|
|
state.paramsDialog.params = JSON.parse(row.value);
|
2022-08-26 20:15:36 +08:00
|
|
|
|
}
|
2023-02-13 21:11:16 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
state.paramsDialog.params = row.value;
|
2022-10-29 20:08:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
state.paramsDialog.params = row.value;
|
|
|
|
|
|
}
|
|
|
|
|
|
state.paramsDialog.visible = true;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-05-24 16:22:54 +08:00
|
|
|
|
const onCloseSetConfigDialog = () => {
|
2022-10-29 20:08:15 +08:00
|
|
|
|
state.paramsDialog.visible = false;
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
state.paramsDialog.config = {};
|
|
|
|
|
|
state.paramsDialog.params = {};
|
|
|
|
|
|
state.paramsDialog.paramsFormItem = [];
|
|
|
|
|
|
}, 300);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const setConfig = async () => {
|
2024-11-20 22:43:53 +08:00
|
|
|
|
let paramsValue: any = state.paramsDialog.params;
|
2023-06-28 21:35:03 +08:00
|
|
|
|
if (state.paramsDialog.paramsFormItem.length > 0) {
|
2023-12-09 16:17:26 +08:00
|
|
|
|
await paramsFormRef.value.validate((valid: boolean) => {
|
2023-06-28 21:35:03 +08:00
|
|
|
|
if (!valid) {
|
|
|
|
|
|
paramsValue = null as any;
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (state.paramsDialog.paramsFormItem.length > 0) {
|
|
|
|
|
|
// 如果配置项删除,则需要将value中对应的字段移除
|
|
|
|
|
|
for (let paramKey in paramsValue) {
|
|
|
|
|
|
if (!hasParam(paramKey, state.paramsDialog.paramsFormItem)) {
|
|
|
|
|
|
delete paramsValue[paramKey];
|
|
|
|
|
|
}
|
2023-06-17 15:15:03 +08:00
|
|
|
|
}
|
2023-06-28 21:35:03 +08:00
|
|
|
|
paramsValue = JSON.stringify(paramsValue);
|
2022-08-26 20:15:36 +08:00
|
|
|
|
}
|
2023-06-17 15:15:03 +08:00
|
|
|
|
});
|
2023-06-28 21:35:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
// 说明校验失败
|
|
|
|
|
|
if (paramsValue == null) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
await configApi.save.request({
|
|
|
|
|
|
id: state.paramsDialog.config.id,
|
|
|
|
|
|
key: state.paramsDialog.config.key,
|
|
|
|
|
|
name: state.paramsDialog.config.name,
|
|
|
|
|
|
value: paramsValue,
|
2022-10-29 20:08:15 +08:00
|
|
|
|
});
|
2024-11-20 22:43:53 +08:00
|
|
|
|
useI18nSaveSuccessMsg();
|
2025-05-24 16:22:54 +08:00
|
|
|
|
onCloseSetConfigDialog();
|
2023-06-28 21:35:03 +08:00
|
|
|
|
search();
|
2022-10-29 20:08:15 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const hasParam = (paramKey: string, paramItems: any) => {
|
|
|
|
|
|
for (let paramItem of paramItems) {
|
|
|
|
|
|
if (paramItem.model == paramKey) {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-05-24 16:22:54 +08:00
|
|
|
|
const onConfigEditChange = () => {
|
2024-11-20 22:43:53 +08:00
|
|
|
|
useI18nSaveSuccessMsg();
|
2022-10-29 20:08:15 +08:00
|
|
|
|
search();
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-05-24 16:22:54 +08:00
|
|
|
|
const onEditConfig = (data: any) => {
|
2022-10-29 20:08:15 +08:00
|
|
|
|
if (data) {
|
2024-11-20 22:43:53 +08:00
|
|
|
|
state.configEdit.title = 'common.edit';
|
2022-10-29 20:08:15 +08:00
|
|
|
|
state.configEdit.config = data;
|
|
|
|
|
|
} else {
|
2024-11-20 22:43:53 +08:00
|
|
|
|
state.configEdit.title = 'common.create';
|
2022-10-29 20:08:15 +08:00
|
|
|
|
state.configEdit.config = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
state.configEdit.visible = true;
|
|
|
|
|
|
};
|
2022-08-26 20:15:36 +08:00
|
|
|
|
</script>
|
2023-06-17 15:15:03 +08:00
|
|
|
|
<style lang="scss"></style>
|