123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334 |
- <script setup lang="ts">
- import FormSearch from "@/components/opts/form-search.vue";
- import TableButtons from "@/components/opts/btns2.vue";
- import ConfigEdit from "./modules/config-edit.vue";
- import { PureTable } from "@pureadmin/table";
- import { reactive, ref } from "vue";
- import { configTypeOptions } from "@/constants/constants";
- import * as $configApi from "@/api/sys/config";
- import { onMounted } from "vue";
- import { hasAuth } from "@/router/utils";
- import message from "@/utils/message";
- const configEditRef = ref();
- const pageData: any = reactive({
- permission: {
- query: ["sys:config:query"],
- save: ["sys:config:save"],
- update: ["sys:config:update"],
- del: ["sys:config:del"],
- refreshCache: ["sys:config:refresh"]
- },
- searchParam: {
- searchState: true,
- searchForm: {},
- formFields: [
- {
- type: "select",
- label: "配置类型",
- prop: "type",
- placeholder: "请选择配置类型",
- dataSourceKey: "configTypeOptions",
- options: {
- clearable: true,
- filterable: true,
- keys: {
- prop: "value",
- value: "value",
- label: "label"
- }
- }
- },
- {
- type: "input",
- label: "配置项",
- prop: "code",
- placeholder: "请输入配置项",
- options: {
- clearable: true
- }
- }
- ]
- },
- dataSource: {
- configTypeOptions: configTypeOptions
- },
- btnOpts: {
- size: "small",
- left: [
- {
- key: "add",
- label: "新增",
- type: "primary",
- icon: "ep:plus",
- state: true,
- permission: ["sys:config:save"]
- }
- // {
- // key: "update",
- // label: "修改",
- // type: "success",
- // icon: "ep:edit",
- // state: false,
- // permission: ["sys:config:update"]
- // }
- ],
- right: [
- {
- key: "search",
- label: "查询",
- icon: "ep:search",
- state: true,
- options: {
- circle: true
- }
- },
- {
- key: "refresh",
- label: "刷新",
- icon: "ep:refresh",
- state: true,
- options: {
- circle: true
- }
- }
- ]
- },
- tableParam: {
- columns: [
- {
- label: "配置类型",
- prop: "typeName"
- },
- {
- label: "配置项",
- prop: "code"
- },
- {
- label: "配置值",
- prop: "value"
- },
- {
- label: "备注",
- prop: "memo"
- },
- {
- label: "创建时间",
- prop: "createTime"
- },
- {
- label: "更新时间",
- prop: "updateTime"
- },
- {
- label: "操作",
- fixed: "right",
- slot: "operation"
- }
- ],
- list: [],
- loading: false,
- pagination: {
- pageSize: 10,
- defaultPageSize: 10,
- currentPage: 1,
- background: true,
- total: 0
- }
- }
- });
- const handleBtnClick = (val: string) => {
- switch (val) {
- case "add":
- configEditRef.value!.open({}, pageData.dataSource, "add");
- break;
- case "update":
- break;
- case "search":
- _updateSearchState();
- break;
- case "refresh":
- _loadData();
- break;
- }
- };
- /**
- * 更新搜索表单
- * @param data .
- */
- const _updateSearchFormData = (data: any) => {
- pageData.searchParam.searchForm = data;
- };
- /**
- * 点击搜索按钮
- */
- const _searchForm = (data: any) => {
- pageData.searchParam.searchForm = data;
- _loadData();
- };
- /**
- * 重置
- */
- const _resetSearchForm = (data?: any) => {
- pageData.searchParam.searchForm = data;
- };
- /**
- * 更新搜索表达的状态
- */
- const _updateSearchState = () => {
- pageData.searchParam.searchState = !pageData.searchParam.searchState;
- };
- const handleChangePageSize = (val: any) => {
- pageData.tableParam.pagination.pageSize = val;
- _loadData();
- };
- const handleChangeCurrentPage = (val: any) => {
- pageData.tableParam.pagination.currentPage = val;
- _loadData();
- };
- const getQueryParams = () => {
- const sqp = {};
- const param = Object.assign(sqp, pageData.searchParam.searchForm);
- param.current = pageData.tableParam.pagination.currentPage;
- param.size = pageData.tableParam.pagination.pageSize;
- return param;
- };
- /**
- * 查询数据
- */
- const _loadData = (page?: number) => {
- pageData.tableParam.loading = true;
- const query = getQueryParams();
- if (page) {
- query.current = page;
- }
- $configApi
- .queryPage(query)
- .then((res: any) => {
- if (res.success) {
- pageData.tableParam.list = res.result.records;
- pageData.tableParam.pagination.total = Number(res.result.total);
- }
- })
- .finally(() => {
- pageData.tableParam.loading = false;
- });
- };
- const handleEdit = (row: any) => {
- configEditRef.value!.open(row, pageData.dataSource, "update");
- };
- const handleDel = (row: any) => {
- message.confirm("是否删除当前数据").then(() => {
- _batchDel([row.id]);
- });
- };
- const _batchDel = (ids: string[]) => {
- pageData.tableParam.loading = true;
- $configApi
- .delByIds(ids)
- .then((res: any) => {
- if (res.success) {
- message.success("删除成功");
- _loadData();
- }
- })
- .finally(() => {
- pageData.tableParam.loading = false;
- });
- };
- const handleRefreshCache = (row: any) => {
- message
- .confirm("是否刷新缓存")
- .then(() => {
- _refreshCache(row.id);
- })
- .catch(() => {});
- };
- const _refreshCache = (id: string) => {
- pageData.tableParam.loading = true;
- $configApi
- .refreshCache(id)
- .then((res: any) => {
- if (res.success) {
- message.success("刷新成功");
- _loadData();
- }
- })
- .finally(() => {
- pageData.tableParam.loading = false;
- });
- };
- onMounted(() => {
- _loadData();
- });
- defineOptions({
- name: "SysConfig"
- });
- </script>
- <template>
- <div>
- <el-card :shadow="'never'">
- <template #default>
- <!--form search-->
- <FormSearch
- :show="pageData.searchParam.searchState"
- :size="'default'"
- :form-field="pageData.searchParam.formFields"
- :query-permission="pageData.permission.query"
- :data-source="pageData.dataSource"
- @search-form="_updateSearchFormData"
- @search="_searchForm"
- @reset="_resetSearchForm"
- />
- <table-buttons
- :size="pageData.btnOpts.size"
- :left-btns="pageData.btnOpts.left"
- :right-btns="pageData.btnOpts.right"
- @click="handleBtnClick"
- />
- <pure-table
- :columns="pageData.tableParam.columns"
- :data="pageData.tableParam.list"
- :border="true"
- :stripe="true"
- :loading="pageData.tableParam.loading"
- :pagination="pageData.tableParam.pagination"
- :header-row-class-name="'table-header'"
- @page-current-change="handleChangeCurrentPage"
- @page-size-change="handleChangePageSize"
- >
- <!---->
- <template #operation="{ row }">
- <el-link
- v-show="hasAuth(pageData.permission.update)"
- type="primary"
- @click="handleEdit(row)"
- >编辑</el-link
- >
- <el-divider
- direction="vertical"
- v-show="hasAuth(pageData.permission.refreshCache)"
- />
- <el-link
- v-show="hasAuth(pageData.permission.refreshCache)"
- type="primary"
- @click="handleRefreshCache(row)"
- >刷新缓存</el-link
- >
- <el-divider
- v-show="hasAuth(pageData.permission.del)"
- direction="vertical"
- />
- <el-link
- v-show="hasAuth(pageData.permission.del)"
- type="primary"
- @click="handleDel(row)"
- >删除</el-link
- >
- </template>
- </pure-table>
- </template>
- </el-card>
- <config-edit ref="configEditRef" @confirm="_loadData()" />
- </div>
- </template>
|