Initial commit
This commit is contained in:
250
src/views/cms/setting/components/field.vue
Normal file
250
src/views/cms/setting/components/field.vue
Normal file
@@ -0,0 +1,250 @@
|
||||
<!-- 用户编辑弹窗 -->
|
||||
<template>
|
||||
<ele-modal
|
||||
width="500px"
|
||||
:visible="visible"
|
||||
:confirm-loading="loading"
|
||||
:title="title"
|
||||
:body-style="{ paddingBottom: '8px' }"
|
||||
@update:visible="updateVisible"
|
||||
@ok="save"
|
||||
>
|
||||
<a-form layout="horizontal">
|
||||
<template v-for="(value, key) in data" :key="key">
|
||||
<template v-if="field === key">
|
||||
<a-form-item :label="title">
|
||||
<template v-if="field === 'city'">
|
||||
<regions-select
|
||||
v-model:value="city"
|
||||
valueField="label"
|
||||
placeholder="请选择省市区"
|
||||
class="ele-fluid"
|
||||
/>
|
||||
</template>
|
||||
<template v-else-if="field === 'industryParent'">
|
||||
<industry-select
|
||||
v-model:value="industry"
|
||||
valueField="label"
|
||||
placeholder="请选择所属行业"
|
||||
class="ele-fluid"
|
||||
/>
|
||||
</template>
|
||||
<template v-else-if="field === 'websiteType'">
|
||||
<a-select
|
||||
:options="websiteType"
|
||||
:value="form.websiteType"
|
||||
placeholder="请选择主体类型"
|
||||
@change="onWebsiteType"
|
||||
/>
|
||||
</template>
|
||||
<template v-else-if="field === 'websiteType'">
|
||||
<a-select
|
||||
:options="websiteType"
|
||||
:value="form.websiteType"
|
||||
placeholder="请选择应用类型"
|
||||
@change="onAppType"
|
||||
/>
|
||||
</template>
|
||||
<template v-else-if="field === 'comments'">
|
||||
<a-textarea
|
||||
:rows="4"
|
||||
:maxlength="200"
|
||||
placeholder="请输入备注"
|
||||
v-model:value="form.comments"
|
||||
/>
|
||||
</template>
|
||||
<template v-else>
|
||||
<a-input
|
||||
v-model:value="content"
|
||||
@input="onInput"
|
||||
:placeholder="`请输入${title}`"
|
||||
@pressEnter="save"
|
||||
/>
|
||||
</template>
|
||||
</a-form-item>
|
||||
</template>
|
||||
</template>
|
||||
</a-form>
|
||||
</ele-modal>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { ref, reactive, watch } from 'vue';
|
||||
import { Form, message, SelectProps } from 'ant-design-vue';
|
||||
import { assignObject } from 'ele-admin-pro';
|
||||
import {
|
||||
addWebsite,
|
||||
removeSiteInfoCache,
|
||||
updateWebsite
|
||||
} from '@/api/cms/website';
|
||||
import { Website } from '@/api/cms/website/model';
|
||||
|
||||
const useForm = Form.useForm;
|
||||
// 是否是修改
|
||||
const isUpdate = ref(false);
|
||||
const props = defineProps<{
|
||||
// 弹窗是否打开
|
||||
visible: boolean;
|
||||
data?: Website | null;
|
||||
title?: string;
|
||||
field?: string | null;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'done'): void;
|
||||
(e: 'update:visible', visible: boolean): void;
|
||||
}>();
|
||||
|
||||
// 提交状态
|
||||
const loading = ref(false);
|
||||
const content = ref();
|
||||
const placeholder = ref('请输入修改内容');
|
||||
// 用户信息
|
||||
const form = reactive<Website>({
|
||||
websiteId: undefined,
|
||||
websiteName: '',
|
||||
websiteType: undefined,
|
||||
websiteLogo: '',
|
||||
keywords: '',
|
||||
domain: '',
|
||||
phone: '',
|
||||
email: '',
|
||||
address: '',
|
||||
expirationTime: '',
|
||||
templateId: '',
|
||||
country: '',
|
||||
province: '',
|
||||
city: '',
|
||||
region: '',
|
||||
comments: '',
|
||||
industryParent: undefined,
|
||||
industryChild: undefined,
|
||||
icpNo: '',
|
||||
policeNo: '',
|
||||
status: 0,
|
||||
tenantId: undefined,
|
||||
createTime: ''
|
||||
});
|
||||
|
||||
// 省市区
|
||||
const city = ref<string[]>([
|
||||
String(form.province),
|
||||
String(form.city),
|
||||
String(form.region)
|
||||
]);
|
||||
|
||||
const industry = ref<string[]>([
|
||||
String(form.industryParent),
|
||||
String(form.industryChild)
|
||||
]);
|
||||
|
||||
const websiteType = ref<SelectProps['options']>([
|
||||
{
|
||||
value: '企业官网',
|
||||
label: '企业官网'
|
||||
},
|
||||
{
|
||||
value: '小程序商城',
|
||||
label: '小程序商城'
|
||||
},
|
||||
{
|
||||
value: '其他',
|
||||
label: '其他'
|
||||
}
|
||||
]);
|
||||
|
||||
/* 更新visible */
|
||||
const updateVisible = (value: boolean) => {
|
||||
emit('update:visible', value);
|
||||
};
|
||||
|
||||
const { resetFields, validate } = useForm(form);
|
||||
|
||||
const onInput = () => {
|
||||
// 对象赋值
|
||||
Object.keys(form).forEach((key) => {
|
||||
if (key === props.field) {
|
||||
form[key] = content.value;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const onWebsiteType = (e) => {
|
||||
form.websiteType = e;
|
||||
};
|
||||
|
||||
const onAppType = (e) => {
|
||||
form.websiteType = e;
|
||||
};
|
||||
|
||||
/* 保存编辑 */
|
||||
const save = () => {
|
||||
validate()
|
||||
.then(() => {
|
||||
loading.value = true;
|
||||
form.province = city.value[0];
|
||||
form.city = city.value[1];
|
||||
form.region = city.value[2];
|
||||
form.industryParent = industry.value[0];
|
||||
form.industryChild = industry.value[1];
|
||||
form.websiteId = props.data?.websiteId;
|
||||
// form.authoritative = true;
|
||||
const saveOrUpdate = form.websiteId ? updateWebsite : addWebsite;
|
||||
saveOrUpdate(form)
|
||||
.then(() => {
|
||||
loading.value = false;
|
||||
message.success('保存成功');
|
||||
// 清除缓存
|
||||
removeSiteInfoCache('SiteInfo:' + localStorage.getItem('TenantId'));
|
||||
updateVisible(false);
|
||||
emit('done');
|
||||
})
|
||||
.catch((e) => {
|
||||
loading.value = false;
|
||||
message.error(e.message);
|
||||
});
|
||||
})
|
||||
.catch(() => {});
|
||||
};
|
||||
|
||||
watch(
|
||||
() => props.visible,
|
||||
(visible) => {
|
||||
if (visible) {
|
||||
if (props.data) {
|
||||
loading.value = false;
|
||||
console.log(props.data);
|
||||
city.value[0] = String(props.data.province);
|
||||
city.value[1] = String(props.data.city);
|
||||
city.value[2] = String(props.data.region);
|
||||
industry.value[0] = String(props.data.industryParent);
|
||||
industry.value[1] = String(props.data.industryChild);
|
||||
assignObject(form, props.data);
|
||||
// 对象赋值
|
||||
Object.keys(form).forEach((key) => {
|
||||
if (key === props.field) {
|
||||
console.log(key);
|
||||
console.log(form[key]);
|
||||
content.value = form[key];
|
||||
}
|
||||
});
|
||||
isUpdate.value = true;
|
||||
} else {
|
||||
isUpdate.value = false;
|
||||
}
|
||||
} else {
|
||||
resetFields();
|
||||
}
|
||||
|
||||
if (props.field == 'tenantCode') {
|
||||
placeholder.value = '请输入要绑定的主体编号';
|
||||
// content.value = undefined;
|
||||
}
|
||||
}
|
||||
);
|
||||
</script>
|
||||
<style lang="less">
|
||||
.tab-pane {
|
||||
min-height: 300px;
|
||||
}
|
||||
</style>
|
||||
151
src/views/cms/setting/components/website-field-edit.vue
Normal file
151
src/views/cms/setting/components/website-field-edit.vue
Normal file
@@ -0,0 +1,151 @@
|
||||
<!-- 用户编辑弹窗 -->
|
||||
<template>
|
||||
<ele-modal
|
||||
:width="500"
|
||||
:visible="visible"
|
||||
:maskClosable="false"
|
||||
:title="isUpdate ? '编辑字段' : '添加字段'"
|
||||
:body-style="{ paddingBottom: '28px' }"
|
||||
@update:visible="updateVisible"
|
||||
@ok="save"
|
||||
>
|
||||
<a-form
|
||||
ref="formRef"
|
||||
:model="form"
|
||||
:rules="rules"
|
||||
:label-col="{ md: { span: 4 }, sm: { span: 4 }, xs: { span: 24 } }"
|
||||
:wrapper-col="{ md: { span: 21 }, sm: { span: 22 }, xs: { span: 24 } }"
|
||||
>
|
||||
<a-form-item label="键名" name="name">
|
||||
<a-input allow-clear placeholder="KEY" v-model:value="form.name" />
|
||||
</a-form-item>
|
||||
<a-form-item label="参数值" name="value">
|
||||
<a-input allow-clear placeholder="VALUE" v-model:value="form.value" />
|
||||
</a-form-item>
|
||||
<a-form-item label="描述" name="comments">
|
||||
<a-textarea
|
||||
:rows="4"
|
||||
:maxlength="200"
|
||||
placeholder="备注"
|
||||
v-model:value="form.comments"
|
||||
/>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</ele-modal>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { ref, reactive, watch } from 'vue';
|
||||
import { FormInstance, RuleObject } from 'ant-design-vue/es/form';
|
||||
import { WebsiteField } from '@/api/cms/website/field/model';
|
||||
import useFormData from '@/utils/use-form-data';
|
||||
import { addWebsiteField, updateWebsiteField } from '@/api/cms/website/field';
|
||||
import { message } from 'ant-design-vue/es';
|
||||
import { isChinese } from 'ele-admin-pro';
|
||||
import { removeSiteInfoCache } from '@/api/cms/website';
|
||||
|
||||
// 是否是修改
|
||||
const isUpdate = ref(false);
|
||||
|
||||
const props = defineProps<{
|
||||
// 弹窗是否打开
|
||||
visible: boolean;
|
||||
websiteId: number | null | undefined;
|
||||
// 修改回显的数据
|
||||
data?: WebsiteField | null;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'done'): void;
|
||||
(e: 'update:visible', visible: boolean): void;
|
||||
}>();
|
||||
|
||||
// 提交状态
|
||||
const loading = ref(false);
|
||||
|
||||
const formRef = ref<FormInstance | null>(null);
|
||||
|
||||
const { form, resetFields, assignFields } = useFormData<WebsiteField>({
|
||||
id: undefined,
|
||||
websiteId: undefined,
|
||||
name: undefined,
|
||||
value: undefined,
|
||||
comments: '',
|
||||
status: 0,
|
||||
sortNumber: 100
|
||||
});
|
||||
|
||||
// 表单验证规则
|
||||
const rules = reactive({
|
||||
value: [
|
||||
{
|
||||
required: true,
|
||||
type: 'string',
|
||||
message: '请填写参数值'
|
||||
}
|
||||
],
|
||||
name: [
|
||||
{
|
||||
required: true,
|
||||
type: 'string',
|
||||
message: '请输入参数名称(英语)'
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
/* 更新visible */
|
||||
const updateVisible = (value: boolean) => {
|
||||
emit('update:visible', value);
|
||||
};
|
||||
|
||||
/* 保存编辑 */
|
||||
const save = () => {
|
||||
if (!formRef.value) {
|
||||
return;
|
||||
}
|
||||
formRef.value
|
||||
.validate()
|
||||
.then(() => {
|
||||
loading.value = true;
|
||||
const data = {
|
||||
...form,
|
||||
websiteId: props.websiteId
|
||||
};
|
||||
const saveOrUpdate = isUpdate.value
|
||||
? updateWebsiteField
|
||||
: addWebsiteField;
|
||||
console.log(isUpdate.value);
|
||||
saveOrUpdate(data)
|
||||
.then((msg) => {
|
||||
loading.value = false;
|
||||
message.success(msg);
|
||||
updateVisible(false);
|
||||
// 清除缓存
|
||||
removeSiteInfoCache('SiteInfo:' + localStorage.getItem('TenantId'));
|
||||
emit('done');
|
||||
})
|
||||
.catch((e) => {
|
||||
loading.value = false;
|
||||
message.error(e.message);
|
||||
});
|
||||
})
|
||||
.catch(() => {});
|
||||
};
|
||||
|
||||
watch(
|
||||
() => props.visible,
|
||||
(visible) => {
|
||||
if (visible) {
|
||||
if (props.data) {
|
||||
assignFields(props.data);
|
||||
form.comments = props.data.comments;
|
||||
isUpdate.value = true;
|
||||
} else {
|
||||
isUpdate.value = false;
|
||||
}
|
||||
} else {
|
||||
resetFields();
|
||||
}
|
||||
}
|
||||
);
|
||||
</script>
|
||||
13
src/views/cms/setting/components/website-field-search.vue
Normal file
13
src/views/cms/setting/components/website-field-search.vue
Normal file
@@ -0,0 +1,13 @@
|
||||
<template>
|
||||
<a-button @click="add">添加参数</a-button>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
const emit = defineEmits<{
|
||||
(e: 'add'): void;
|
||||
}>();
|
||||
|
||||
const add = () => {
|
||||
emit('add');
|
||||
};
|
||||
</script>
|
||||
189
src/views/cms/setting/components/website-field.vue
Normal file
189
src/views/cms/setting/components/website-field.vue
Normal file
@@ -0,0 +1,189 @@
|
||||
<template>
|
||||
<div class="website-field">
|
||||
<!-- 表格 -->
|
||||
<ele-pro-table
|
||||
ref="tableRef"
|
||||
row-key="websiteId"
|
||||
:columns="columns"
|
||||
:datasource="datasource"
|
||||
:customRow="customRow"
|
||||
tool-class="ele-toolbar-form"
|
||||
class="sys-org-table"
|
||||
>
|
||||
<template #toolbar>
|
||||
<WebsiteFieldSearch @add="openEdit" />
|
||||
</template>
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'comments'">
|
||||
<span class="ele-text-placeholder">{{ record.comments }}</span>
|
||||
</template>
|
||||
<template v-if="column.key === 'action'">
|
||||
<a-space>
|
||||
<a @click="moveUp(record)">上移<ArrowUpOutlined /></a>
|
||||
<a-divider type="vertical" />
|
||||
<a @click="openEdit(record)">编辑</a>
|
||||
<a-divider type="vertical" />
|
||||
<a-popconfirm
|
||||
title="确定要删除此记录吗?"
|
||||
@confirm="remove(record)"
|
||||
>
|
||||
<a class="ele-text-danger">删除</a>
|
||||
</a-popconfirm>
|
||||
</a-space>
|
||||
</template>
|
||||
</template>
|
||||
</ele-pro-table>
|
||||
<!-- 编辑弹窗 -->
|
||||
<WebsiteFieldEdit
|
||||
v-model:visible="showEdit"
|
||||
:website-id="data.websiteId"
|
||||
:data="current"
|
||||
@done="reload"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { ref, watch } from 'vue';
|
||||
import { message } from 'ant-design-vue';
|
||||
import type { EleProTable } from 'ele-admin-pro';
|
||||
import type { DatasourceFunction } from 'ele-admin-pro/es/ele-pro-table/types';
|
||||
import WebsiteFieldSearch from './website-field-search.vue';
|
||||
import { Website } from '@/api/cms/website/model';
|
||||
import WebsiteFieldEdit from './website-field-edit.vue';
|
||||
import {
|
||||
WebsiteField,
|
||||
WebsiteFieldParam
|
||||
} from '@/api/cms/website/field/model';
|
||||
import {
|
||||
pageWebsiteField,
|
||||
removeWebsiteField,
|
||||
updateWebsiteField
|
||||
} from '@/api/cms/website/field';
|
||||
import { ArrowUpOutlined } from '@ant-design/icons-vue';
|
||||
|
||||
const props = defineProps<{
|
||||
websiteId: any;
|
||||
data: Website;
|
||||
}>();
|
||||
|
||||
// 表格实例
|
||||
const tableRef = ref<InstanceType<typeof EleProTable> | null>(null);
|
||||
const selection = ref<any[]>();
|
||||
// 当前编辑数据
|
||||
const current = ref<WebsiteField | null>(null);
|
||||
// 是否显示编辑弹窗
|
||||
const showEdit = ref(false);
|
||||
|
||||
// 表格数据源
|
||||
const datasource: DatasourceFunction = ({ page, limit, where, orders }) => {
|
||||
// 搜索条件
|
||||
where.websiteId = props.websiteId;
|
||||
return pageWebsiteField({
|
||||
...where,
|
||||
...orders,
|
||||
page,
|
||||
limit
|
||||
});
|
||||
};
|
||||
|
||||
// 表格列配置
|
||||
const columns = ref<any[]>([
|
||||
{
|
||||
title: '键名',
|
||||
width: 180,
|
||||
dataIndex: 'name'
|
||||
},
|
||||
{
|
||||
title: '参数值',
|
||||
dataIndex: 'value',
|
||||
key: 'value'
|
||||
},
|
||||
{
|
||||
title: '备注',
|
||||
dataIndex: 'comments',
|
||||
width: 280,
|
||||
key: 'comments'
|
||||
},
|
||||
{
|
||||
title: '排序',
|
||||
dataIndex: 'sortNumber',
|
||||
width: 180,
|
||||
align: 'center'
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
width: 180,
|
||||
align: 'center',
|
||||
hideInSetting: true
|
||||
}
|
||||
]);
|
||||
|
||||
const moveUp = (row?: WebsiteField) => {
|
||||
updateWebsiteField({
|
||||
id: row?.id,
|
||||
sortNumber: Number(row?.sortNumber) + 1
|
||||
}).then((msg) => {
|
||||
message.success(msg);
|
||||
reload();
|
||||
});
|
||||
};
|
||||
|
||||
/* 打开编辑弹窗 */
|
||||
const openEdit = (row?: WebsiteField) => {
|
||||
current.value = row ?? null;
|
||||
showEdit.value = true;
|
||||
};
|
||||
|
||||
/* 搜索 */
|
||||
const reload = (where?: WebsiteFieldParam) => {
|
||||
selection.value = [];
|
||||
tableRef?.value?.reload({ where: where });
|
||||
};
|
||||
|
||||
/* 删除单个 */
|
||||
const remove = (row: WebsiteField) => {
|
||||
const hide = message.loading('请求中..', 0);
|
||||
removeWebsiteField(row.id)
|
||||
.then((msg) => {
|
||||
hide();
|
||||
message.success(msg);
|
||||
reload();
|
||||
})
|
||||
.catch((e) => {
|
||||
hide();
|
||||
message.error(e.message);
|
||||
});
|
||||
};
|
||||
|
||||
/* 自定义行属性 */
|
||||
const customRow = (record: WebsiteField) => {
|
||||
return {
|
||||
// 行点击事件
|
||||
onClick: () => {
|
||||
// console.log(record);
|
||||
},
|
||||
// 行双击事件
|
||||
onDblclick: () => {
|
||||
openEdit(record);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
watch(
|
||||
() => props.websiteId,
|
||||
(websiteId) => {
|
||||
if (websiteId) {
|
||||
reload();
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
export default {
|
||||
name: 'WebsiteFieldIndex'
|
||||
};
|
||||
</script>
|
||||
Reference in New Issue
Block a user