整理商品管理模块

This commit is contained in:
2024-07-25 19:20:53 +08:00
parent 717c89a58e
commit cf0961afdd
48 changed files with 1814 additions and 965 deletions
-227
View File
@@ -1,227 +0,0 @@
<!-- 编辑弹窗 -->
<template>
<ele-modal
:width="isUpdate ? 880 : 500"
:visible="visible"
:maskClosable="false"
:title="isUpdate ? '域名DNS解析验证' : '添加域名'"
:body-style="{ paddingBottom: '28px' }"
@update:visible="updateVisible"
:confirmLoading="loading"
@ok="save"
>
<a-form
ref="formRef"
:model="form"
:rules="rules"
:label-col="styleResponsive ? { md: 5, sm: 7, xs: 24 } : { flex: '90px' }"
:wrapper-col="
styleResponsive ? { md: 18, sm: 19, xs: 24 } : { flex: '1' }
"
>
<a-form-item label="https://" name="domain">
<a-input
allow-clear
:maxlength="100"
placeholder="example.com"
:disabled="isUpdate"
v-model:value="form.domain"
@pressEnter="save"
/>
</a-form-item>
<a-form-item label="添加DNS解析" name="check" v-if="isUpdate">
<a-space direction="vertical">
<div class="ele-text-placeholder" style="line-height: 2.2em"
>请按以下提示,在您的域名控制台添加DNS解析配置</div
>
<table
class="ele-table ele-table-border ele-table-stripe ele-table-medium"
>
<colgroup>
<col width="180" />
<col width="120" />
<col />
</colgroup>
<thead>
<tr>
<th>主机记录</th>
<th>记录类型</th>
<th>记录值</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{ form.hostName }}</td>
<td>CNAME</td>
<td>{{ form.hostValue }}</td>
</tr>
</tbody>
</table>
</a-space>
</a-form-item>
<a-form-item label="排序" name="sortNumber">
<a-input-number
:min="0"
:max="99999"
placeholder="请输入排序号"
v-model:value="form.sortNumber"
/>
</a-form-item>
<a-form-item label="操作" v-if="isUpdate && form.status == 0">
<a-button type="primary" @click="save">验证域名</a-button>
</a-form-item>
</a-form>
</ele-modal>
</template>
<script lang="ts" setup>
import { ref, reactive, watch } from 'vue';
import { message } from 'ant-design-vue';
import { addDomain, resolvable } from '@/api/cms/domain';
import { Domain } from '@/api/cms/domain/model';
import { useThemeStore } from '@/store/modules/theme';
import { storeToRefs } from 'pinia';
import { FormInstance, type Rule } from 'ant-design-vue/es/form';
import useFormData from '@/utils/use-form-data';
import { isUrl } from 'ele-admin-pro';
// 是否是修改
const isUpdate = ref(false);
// 是否开启响应式布局
const themeStore = useThemeStore();
const { styleResponsive } = storeToRefs(themeStore);
const props = defineProps<{
// 弹窗是否打开
visible: boolean;
// 修改回显的数据
data?: Domain | null;
}>();
const emit = defineEmits<{
(e: 'done'): void;
(e: 'update:visible', visible: boolean): void;
}>();
// 提交状态
const loading = ref(false);
const disabled = ref(false);
// 表格选中数据
const formRef = ref<FormInstance | null>(null);
// 表单数据
const { form, resetFields, assignFields } = useFormData<Domain>({
id: undefined,
domain: '',
hostName: '',
hostValue: '',
status: 0,
comments: '',
sortNumber: 100
});
/* 更新visible */
const updateVisible = (value: boolean) => {
emit('update:visible', value);
};
// 表单验证规则
const rules = reactive({
domain: [
{
required: true,
type: 'string',
message: '请输入合法域名',
trigger: 'blur',
validator: (_rule: Rule, value: string) => {
return new Promise<void>((resolve, reject) => {
if (!isUrl(`https://${value}`)) {
if (value.includes('http')) {
return reject('不含http开头');
}
return reject('请输入合法域名');
}
disabled.value = true;
return resolve();
});
}
}
]
});
/* 保存编辑 */
const save = () => {
if (!formRef.value) {
return;
}
formRef.value
.validate()
.then(() => {
loading.value = true;
if (form.domain) {
form.domain = form.domain.trim();
form.domain = form.domain.replace('https://', '');
form.domain = form.domain.replace('http://', '');
const split = form.domain.split('.');
if (split.length == 2) {
form.hostName = '@';
}
if (split.length > 2) {
const suffix = split[split.length - 1];
const name = split[split.length - 2];
form.hostName = form.domain.replace(`.${name}.${suffix}`, '');
}
}
const formData = {
...form
};
if (isUpdate.value) {
setTimeout(() => {
resolvable(Number(form.id))
.then((data) => {
loading.value = false;
message.success(data.message);
updateVisible(false);
emit('done');
})
.catch((res) => {
loading.value = false;
message.error(res.message);
});
}, 1000);
}
if (!isUpdate.value) {
addDomain(formData)
.then((msg) => {
loading.value = false;
message.success(msg);
updateVisible(false);
emit('done');
})
.catch((e) => {
loading.value = false;
message.error(e.message);
});
}
})
.catch(() => {});
};
watch(
() => props.visible,
(visible) => {
if (visible) {
if (props.data) {
assignFields(props.data);
isUpdate.value = true;
} else {
isUpdate.value = false;
}
} else {
resetFields();
formRef.value?.clearValidate();
}
},
{ immediate: true }
);
</script>
+24 -12
View File
@@ -1,36 +1,48 @@
<!-- 搜索表单 -->
<template>
<a-space :size="10" style="flex-wrap: wrap">
<a-button type="primary" class="ele-btn-icon" @click="add">
<template #icon>
<PlusOutlined />
</template>
<span>添加</span>
</a-button>
<a-space style="flex-wrap: wrap">
<!-- <a-button type="primary" class="ele-btn-icon" @click="add">-->
<!-- <template #icon>-->
<!-- <PlusOutlined />-->
<!-- </template>-->
<!-- <span>添加</span>-->
<!-- </a-button>-->
<!-- <a-button class="ele-btn-icon" @click="openUrl(`/mp-pages`)">-->
<!-- <span>页面管理</span>-->
<!-- </a-button>-->
<!-- <a-button class="ele-btn-icon" @click="openUrl(`/mp-field/0`)">-->
<!-- <span>参数配置</span>-->
<!-- </a-button>-->
<!-- <a-button class="ele-btn-icon" @click="openUrl(`/mp-ad`)">-->
<!-- <span>广告管理</span>-->
<!-- </a-button>-->
<!-- <a-button class="ele-btn-icon" @click="openUrl(`/mp-group`)">-->
<!-- <span>卡片管理</span>-->
<!-- </a-button>-->
<!-- <a-button class="ele-btn-icon" @click="openUrl(`/mp-package`)">-->
<!-- <span>分包管理</span>-->
<!-- </a-button>-->
</a-space>
</template>
<script lang="ts" setup>
import { PlusOutlined } from '@ant-design/icons-vue';
import type { GradeParam } from '@/api/user/grade/model';
import { watch } from 'vue';
import { openUrl } from '@/utils/common';
const props = withDefaults(
defineProps<{
// 选中的角色
selection?: [];
count?: 0;
}>(),
{}
);
const emit = defineEmits<{
(e: 'search', where?: GradeParam): void;
(e: 'add'): void;
(e: 'remove'): void;
(e: 'batchMove'): void;
}>();
// 新增
const add = () => {
emit('add');
};
@@ -0,0 +1,325 @@
<!-- 编辑弹窗 -->
<template>
<ele-modal
:width="800"
:visible="visible"
:maskClosable="false"
:maxable="maxable"
:title="isUpdate ? '编辑网站信息' : '添加网站信息'"
:body-style="{ paddingBottom: '28px' }"
@update:visible="updateVisible"
@ok="save"
>
<a-form
ref="formRef"
:model="form"
:rules="rules"
:label-col="styleResponsive ? { md: 4, sm: 5, xs: 24 } : { flex: '90px' }"
:wrapper-col="
styleResponsive ? { md: 19, sm: 19, xs: 24 } : { flex: '1' }
"
>
<a-form-item label="Logo" name="avatar">
<SelectFile
:placeholder="`请选择图片`"
:limit="1"
:data="images"
@done="chooseImage"
@del="onDeleteItem"
/>
</a-form-item>
<a-form-item label="网站名称" name="websiteName">
<a-input
allow-clear
placeholder="请输入网站名称"
v-model:value="form.websiteName"
/>
</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-item label="SEO关键词" name="keywords">
<a-textarea
:rows="4"
:maxlength="200"
placeholder="请输入SEO关键词"
v-model:value="form.keywords"
/>
</a-form-item>
<a-form-item label="网站域名" name="domain">
<a-input v-model:value="form.domain" placeholder="domain.com">
<template #addonBefore>
<a-select v-model:value="form.prefix" style="width: 90px">
<a-select-option value="http://">http://</a-select-option>
<a-select-option value="https://">https://</a-select-option>
</a-select>
</template>
</a-input>
</a-form-item>
<a-form-item label="后台管理" name="adminUrl">
<a-input v-model:value="form.adminUrl" placeholder="admin.domain.com">
<template #addonBefore>
<a-select v-model:value="form.prefix" style="width: 90px">
<a-select-option value="http://">http://</a-select-option>
<a-select-option value="https://">https://</a-select-option>
</a-select>
</template>
</a-input>
</a-form-item>
<a-form-item label="ICP备案号" name="icpNo">
<a-input
allow-clear
placeholder="请输入网站备案"
v-model:value="form.icpNo"
/>
</a-form-item>
<a-form-item label="网站类型" name="websiteType">
<a-select
:options="websiteType"
:value="form.websiteType"
placeholder="请选择主体类型"
@change="onWebsiteType"
/>
</a-form-item>
<a-form-item label="当前版本" name="version">
<span v-if="form.version === 10">免费版</span>
<span v-if="form.version === 20">授权版</span>
<span v-if="form.version === 30">永久授权</span>
</a-form-item>
<a-form-item label="排序" name="sortNumber">
<a-input-number
:min="0"
:max="9999"
class="ele-fluid"
placeholder="请输入排序号"
v-model:value="form.sortNumber"
/>
</a-form-item>
<!-- <a-form-item label="状态" name="status">-->
<!-- <a-radio-group v-model:value="form.status">-->
<!-- <a-radio :value="0">正常</a-radio>-->
<!-- <a-radio :value="1">已过期</a-radio>-->
<!-- </a-radio-group>-->
<!-- </a-form-item>-->
</a-form>
</ele-modal>
</template>
<script lang="ts" setup>
import { ref, reactive, watch } from 'vue';
import { Form, message } from 'ant-design-vue';
import { assignObject, uuid, SelectProps } from 'ele-admin-pro';
import { addWebsite, updateWebsite } from '@/api/cms/website';
import { Website } from '@/api/cms/website/model';
import { useThemeStore } from '@/store/modules/theme';
import { storeToRefs } from 'pinia';
import { ItemType } from 'ele-admin-pro/es/ele-image-upload/types';
import { FormInstance } from 'ant-design-vue/es/form';
import { FileRecord } from '@/api/system/file/model';
// 是否是修改
const isUpdate = ref(false);
const useForm = Form.useForm;
// 是否开启响应式布局
const themeStore = useThemeStore();
const { styleResponsive } = storeToRefs(themeStore);
const props = defineProps<{
// 弹窗是否打开
visible: boolean;
// 修改回显的数据
data?: Website | null;
}>();
const emit = defineEmits<{
(e: 'done'): void;
(e: 'update:visible', visible: boolean): void;
}>();
// 提交状态
const loading = ref(false);
// 是否显示最大化切换按钮
const maxable = ref(true);
// 表格选中数据
const formRef = ref<FormInstance | null>(null);
const images = ref<ItemType[]>([]);
const websiteQrcode = ref<ItemType[]>([]);
// 用户信息
const form = reactive<Website>({
websiteId: undefined,
websiteLogo: undefined,
websiteName: undefined,
keywords: '',
prefix: '',
domain: '',
adminUrl: '',
icpNo: undefined,
email: undefined,
version: undefined,
websiteType: '',
expirationTime: undefined,
sortNumber: undefined,
comments: undefined,
status: undefined
});
const websiteType = ref<SelectProps['options']>([
{
value: '企业官网',
label: '企业官网'
},
{
value: '门户网站',
label: '门户网站'
},
{
value: '电子商城',
label: '电子商城'
}
]);
/* 更新visible */
const updateVisible = (value: boolean) => {
emit('update:visible', value);
};
// 表单验证规则
const rules = reactive({
comments: [
{
required: true,
type: 'string',
message: '请填写网站描述',
trigger: 'blur'
}
],
keywords: [
{
required: true,
type: 'string',
message: '请填写SEO关键词',
trigger: 'blur'
}
],
domain: [
{
required: true,
type: 'string',
message: '请填写网站域名',
trigger: 'blur'
}
],
adminUrl: [
{
required: true,
type: 'string',
message: '请填写网站后台管理地址',
trigger: 'blur'
}
],
icpNo: [
{
required: true,
type: 'string',
message: '请填写ICP备案号',
trigger: 'blur'
}
],
appSecret: [
{
required: true,
type: 'string',
message: '请填写网站秘钥',
trigger: 'blur'
}
],
websiteName: [
{
required: true,
type: 'string',
message: '请填写网站信息名称',
trigger: 'blur'
}
]
});
const chooseImage = (data: FileRecord) => {
images.value.push({
uid: data.id,
url: data.path,
status: 'done'
});
form.websiteLogo = data.downloadUrl;
};
const onDeleteItem = (index: number) => {
images.value.splice(index, 1);
form.websiteLogo = '';
};
const onWebsiteType = (text: string) => {
form.websiteType = text;
};
const { resetFields } = useForm(form, rules);
/* 保存编辑 */
const save = () => {
if (!formRef.value) {
return;
}
formRef.value
.validate()
.then(() => {
loading.value = true;
const formData = {
...form
};
const saveOrUpdate = isUpdate.value ? updateWebsite : addWebsite;
saveOrUpdate(formData)
.then((msg) => {
loading.value = false;
message.success(msg);
updateVisible(false);
emit('done');
})
.catch((e) => {
loading.value = false;
message.error(e.message);
});
})
.catch(() => {});
};
watch(
() => props.visible,
(visible) => {
if (visible) {
images.value = [];
websiteQrcode.value = [];
if (props.data) {
assignObject(form, props.data);
if (props.data.websiteLogo) {
images.value.push({
uid: uuid(),
url: props.data.websiteLogo,
status: 'done'
});
}
isUpdate.value = true;
} else {
isUpdate.value = false;
}
} else {
resetFields();
}
},
{ immediate: true }
);
</script>
+111 -56
View File
@@ -4,51 +4,55 @@
<a-card :bordered="false" :body-style="{ padding: '16px' }">
<ele-pro-table
ref="tableRef"
row-key="id"
row-key="websiteId"
:columns="columns"
:datasource="datasource"
:customRow="customRow"
:need-page="false"
tool-class="ele-toolbar-form"
class="sys-org-table"
>
<template #toolbar>
<search
@search="reload"
:selection="selection"
@add="openEdit"
@remove="removeBatch"
@batchMove="openMove"
/>
</template>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'websiteName'">
<a-space class="ele-cell">
<a-avatar
:src="record.websiteLogo"
size="small"
shape="square"
/>
<span class="ele-text-secondary">{{ record.websiteName }}</span>
</a-space>
<template v-if="column.key === 'websiteLogo'">
<a-image :src="record.websiteLogo" :width="50" />
</template>
<template v-if="column.key === 'hostName'">
<span class="ele-text-placeholder">{{ record.hostName }}</span>
<template v-if="column.key === 'domain'">
<a-button
type="link"
@click="openUrl(`${record.prefix}${record.domain}`)"
>{{ record.domain }}</a-button
>
</template>
<template v-if="column.key === 'hostType'">
<span class="ele-text-placeholder">CNAME</span>
<template v-if="column.key === 'type'">
<a-tag v-if="record.type === 1" color="green">是</a-tag>
<a-tag
v-if="record.type === 0"
@click="updateType(record)"
class="cursor-pointer"
>否</a-tag
>
</template>
<template v-if="column.key === 'hostValue'">
<span class="ele-text-placeholder">{{ record.hostValue }}</span>
</template>
<template v-if="column.key === 'photo'">
<a-image :src="record.photo" />
<template v-if="column.key === 'version'">
<a-tag v-if="record.version === 10">免费版</a-tag>
<a-tag v-if="record.version === 20">授权版</a-tag>
<a-tag v-if="record.version === 30">永久授权</a-tag>
</template>
<template v-if="column.key === 'status'">
<a-switch
v-model:checked="record.status"
@change="updateStatus(record)"
/>
<a-tag v-if="record.status === 0" color="green">正常</a-tag>
<a-tag v-if="record.status === 1" color="red">已过期</a-tag>
</template>
<template v-if="column.key === 'action'">
<a-space>
<a-button @click="openEdit(record)" size="small">管理</a-button>
<a-popconfirm
title="确定要删除此域名吗?"
:disabled="record.home == 1"
@confirm="remove(record)"
>
<a-button size="small">删除</a-button>
</a-popconfirm>
<a-button type="primary" ghost @click="openUrl(`${record.prefix}${record.adminUrl}`)">进入后台</a-button>
</a-space>
</template>
</template>
@@ -56,7 +60,7 @@
</a-card>
<!-- 编辑弹窗 -->
<Edit v-model:visible="showEdit" :data="current" @done="reload" />
<WebsiteEdit v-model:visible="showEdit" :data="current" @done="reload" />
</div>
</div>
</template>
@@ -66,12 +70,13 @@
import { message, Modal } from 'ant-design-vue';
import { ExclamationCircleOutlined } from '@ant-design/icons-vue';
import type { EleProTable } from 'ele-admin-pro';
import { toDateString } from 'ele-admin-pro';
import type {
DatasourceFunction,
ColumnItem
} from 'ele-admin-pro/es/ele-pro-table/types';
// import Search from './components/search.vue';
import Edit from './components/edit.vue';
import Search from './components/search.vue';
import WebsiteEdit from './components/websiteEdit.vue';
import {
pageWebsite,
removeWebsite,
@@ -79,9 +84,7 @@
updateWebsite
} from '@/api/cms/website';
import type { Website, WebsiteParam } from '@/api/cms/website/model';
import { openPreview } from '@/utils/common';
import type { Payment } from '@/api/system/payment/model';
import { updatePayment } from '@/api/system/payment';
import { openUrl } from '@/utils/common';
// 表格实例
const tableRef = ref<InstanceType<typeof EleProTable> | null>(null);
@@ -94,6 +97,8 @@
const showEdit = ref(false);
// 是否显示批量移动弹窗
const showMove = ref(false);
// 加载状态
const loading = ref(true);
// 表格数据源
const datasource: DatasourceFunction = ({
@@ -103,6 +108,9 @@
orders,
filters
}) => {
if (filters) {
where.status = filters.status;
}
return pageWebsite({
...where,
...orders,
@@ -116,26 +124,53 @@
{
title: '网站名称',
dataIndex: 'websiteName',
width: 240,
key: 'websiteName'
key: 'websiteName',
align: 'center'
},
{
title: '主机类型',
dataIndex: 'websiteType',
align: 'center',
key: 'websiteType'
title: 'Logo',
dataIndex: 'websiteLogo',
key: 'websiteLogo',
align: 'center'
},
{
title: '是否启用',
title: '主域名',
dataIndex: 'domain',
key: 'domain',
align: 'center'
},
{
title: '网站描述',
dataIndex: 'comments',
key: 'comments',
align: 'center'
},
{
title: '当前版本',
dataIndex: 'version',
key: 'version',
align: 'center'
},
{
title: '状态',
dataIndex: 'status',
width: 120,
key: 'status',
align: 'center'
},
{
title: '创建时间',
dataIndex: 'createTime',
key: 'createTime',
align: 'center',
key: 'status'
sorter: true,
ellipsis: true,
customRender: ({ text }) => toDateString(text, 'yyyy-MM-dd')
},
{
title: '操作',
key: 'action',
width: 120,
fixed: 'right',
align: 'center',
hideInSetting: true
}
@@ -158,20 +193,17 @@
showMove.value = true;
};
const updateStatus = (item: Website) => {
updateWebsite(item)
.then((msg) => {
message.success(msg);
})
.catch((msg) => {
message.error(msg);
});
const updateType = (row: Website) => {
updateWebsite(row).then((msg) => {
message.success(msg);
reload();
});
};
/* 删除单个 */
const remove = (row: Website) => {
const hide = message.loading('请求中..', 0);
removeWebsite(row.id)
removeWebsite(row.websiteId)
.then((msg) => {
hide();
message.success(msg);
@@ -196,7 +228,7 @@
maskClosable: true,
onOk: () => {
const hide = message.loading('请求中..', 0);
removeBatchWebsite(selection.value.map((d) => d.id))
removeBatchWebsite(selection.value.map((d) => d.websiteId))
.then((msg) => {
hide();
message.success(msg);
@@ -209,9 +241,32 @@
}
});
};
/* 查询 */
const query = () => {
loading.value = true;
};
/* 自定义行属性 */
const customRow = (record: Website) => {
return {
// 行点击事件
onClick: () => {
// console.log(record);
},
// 行双击事件
onDblclick: () => {
openEdit(record);
}
};
};
query();
</script>
<script lang="ts">
export default {
name: 'Website'
};
</script>
<style lang="less" scoped></style>