Initial commit

This commit is contained in:
南宁网宿科技
2024-04-24 16:36:46 +08:00
commit 121348e011
991 changed files with 158700 additions and 0 deletions

View File

@@ -0,0 +1,387 @@
<!-- 编辑弹窗 -->
<template>
<ele-modal
:width="1000"
:visible="visible"
:maskClosable="false"
:maxable="true"
:title="isUpdate ? '编辑页面' : '添加页面'"
:body-style="{ paddingBottom: '28px' }"
@update:visible="updateVisible"
@ok="save"
>
<a-form
ref="formRef"
:model="form"
:rules="rules"
:label-col="styleResponsive ? { md: 2, sm: 5, xs: 24 } : { flex: '90px' }"
:wrapper-col="
styleResponsive ? { md: 21, sm: 19, xs: 24 } : { flex: '1' }
"
>
<a-form-item label="页面名称" name="name">
<a-input
allow-clear
:maxlength="100"
placeholder="关于我们"
v-model:value="form.name"
/>
</a-form-item>
<a-form-item label="路由地址" name="path" :extra="form.path ? `${form.path}` : ''">
<a-input
allow-clear
:maxlength="100"
placeholder="/about"
v-model:value="form.path"
/>
</a-form-item>
<a-form-item label="组件路径" name="component" :extra="form.component ? `@/views${form.component}` : ''">
<a-input
allow-clear
:maxlength="100"
placeholder="请输入组件路径"
v-model:value="form.component"
/>
</a-form-item>
<a-form-item label="Banner" name="photo">
<SelectFile
:placeholder="`请选择图片`"
:limit="1"
:data="images"
@done="chooseFile"
@del="onDeleteItem"
/>
<!-- <ele-image-upload-->
<!-- v-model:value="images"-->
<!-- :limit="1"-->
<!-- :drag="true"-->
<!-- :upload-handler="uploadHandler"-->
<!-- @upload="onUpload"-->
<!-- />-->
</a-form-item>
<a-form-item label="页面内容" name="content">
<!-- 编辑器 -->
<div class="content">
<tinymce-editor
v-model:value="content"
:disabled="disabled"
:init="config"
placeholder="图片直接粘贴自动上传"
@paste="onPaste"
/>
</div>
</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} from 'ele-admin-pro';
import { addDesign, updateDesign } from '@/api/cms/design';
import { Design } from '@/api/cms/design/model';
import { useThemeStore } from '@/store/modules/theme';
import { storeToRefs } from 'pinia';
import { FormInstance, RuleObject } from 'ant-design-vue/es/form';
import { ItemType } from 'ele-admin-pro/es/ele-image-upload/types';
import {uploadFile, uploadOss} from '@/api/system/file';
import TinymceEditor from "@/components/TinymceEditor/index.vue";
import useFormData from "@/utils/use-form-data";
import type {Article} from "@/api/cms/article/model";
import {ArticleCategory} from "@/api/cms/category/model";
import {removeSiteInfoCache} from "@/api/cms/website";
import success from "@/views/result/success/index.vue";
import {FileRecord} from "@/api/system/file/model";
// 是否是修改
const isUpdate = ref(false);
const useForm = Form.useForm;
// 是否开启响应式布局
const themeStore = useThemeStore();
const { styleResponsive } = storeToRefs(themeStore);
const disabled = ref(false);
// 编辑器内容,双向绑定
const content = ref<any>('');
const props = defineProps<{
// 弹窗是否打开
visible: boolean;
// 修改回显的数据
data?: Design | null;
}>();
const emit = defineEmits<{
(e: 'done'): void;
(e: 'update:visible', visible: boolean): void;
}>();
// 提交状态
const loading = ref(false);
// 已上传数据
const images = ref<ItemType[]>([]);
// 表格选中数据
const formRef = ref<FormInstance | null>(null);
// 表单数据
const { form, resetFields, assignFields } = useFormData<Design>({
pageId: undefined,
name: '',
images: '',
path: '',
component: '/about/index',
content: '',
type: '',
status: 0,
comments: '',
sortNumber: 100
});
const editorRef = ref<InstanceType<typeof TinymceEditor> | null>(null);
const config = ref({
height: 500,
images_upload_handler: (blobInfo, success, error) => {
const file = blobInfo.blob();
const formData = new FormData();
formData.append('file', file, file.name);
uploadOss(file).then(res => {
success(res.url)
}).catch((msg) => {
error(msg);
})
return false;
},
// 自定义文件上传(这里使用把选择的文件转成 blob 演示)
file_picker_callback: (callback: any, _value: any, meta: any) => {
const input = document.createElement('input');
input.setAttribute('type', 'file');
// 设定文件可选类型
if (meta.filetype === 'image') {
input.setAttribute('accept', 'image/*');
} else if (meta.filetype === 'media') {
input.setAttribute('accept', 'video/*,.pdf');
}
input.onchange = () => {
const file = input.files?.[0];
if (!file) {
return;
}
if (meta.filetype === 'media') {
if (file.size / 1024 / 1024 > 200) {
editorRef.value?.alert({ content: '大小不能超过 200MB' });
return;
}
if (!file.type.startsWith('video/')) {
editorRef.value?.alert({ content: '只能选择视频文件' });
return;
}
uploadOss(file).then(res => {
callback(res.downloadUrl);
})
}
};
input.click();
}
});
/* 粘贴图片上传服务器并插入编辑器 */
const onPaste = (e) => {
const items = (e.clipboardData || e.originalEvent.clipboardData).items;
let hasFile = false;
for (let i = 0; i < items.length; i++) {
if (items[i].type.indexOf('image') !== -1) {
let file = items[i].getAsFile();
const item: ItemType = {
file,
uid: (file as any).lastModified,
name: file.name
};
uploadFile(<File>item.file)
.then((result) => {
const addPath = `<p><img class="content-img" src="${result.url}"></p>`;
content.value = content.value + addPath
})
.catch((e) => {
message.error(e.message);
});
hasFile = true;
}
}
if (hasFile) {
e.preventDefault();
}
}
/* 更新visible */
const updateVisible = (value: boolean) => {
emit('update:visible', value);
};
// 表单验证规则
const rules = reactive({
name: [
{
required: true,
type: 'string',
message: '请填写页面名称',
trigger: 'blur'
}
],
path: [
{
required: true,
type: 'string',
message: '请填写路由地址',
trigger: 'blur'
}
],
component: [
{
required: true,
type: 'string',
message: '请填写组件路径',
trigger: 'blur'
}
]
});
/* 上传事件 */
const uploadHandler = (file: File) => {
const item: ItemType = {
file,
uid: (file as any).uid,
name: file.name
};
if (file.type.startsWith('video')) {
if (file.size / 1024 / 1024 > 200) {
message.error('大小不能超过 200MB');
return;
}
}
if (file.type.startsWith('image')) {
if (file.size / 1024 / 1024 > 5) {
message.error('大小不能超过 5MB');
return;
}
}
onUpload(item);
};
// 上传文件
const onUpload = (item: any) => {
const { file } = item;
uploadFile(file)
.then((data) => {
form.photo = data.path;
images.value.push({
uid: data.id,
url:
file.type == 'video/mp4'
? 'https://oss.wsdns.cn/20240301/6e4e32cb808245d4be336b9486961145.png'
: data.path,
status: 'done'
});
})
.catch((e) => {
message.error(e.message);
});
};
const chooseFile = (data: FileRecord) => {
images.value.push({
uid: data.id,
url: data.downloadUrl,
status: 'done'
});
form.photo = data.downloadUrl;
}
const onDeleteItem = (index: number) => {
images.value.splice(index,1)
form.photo = '';
}
/* 保存编辑 */
const save = () => {
if (!formRef.value) {
return;
}
formRef.value
.validate()
.then(() => {
loading.value = true;
const formData = {
...form,
content: content.value
};
const saveOrUpdate = isUpdate.value ? updateDesign : addDesign;
saveOrUpdate(formData)
.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) {
content.value = ''
images.value = []
if (props.data) {
assignFields(props.data);
if(props.data.content){
content.value = props.data.content
}
if(props.data.photo){
images.value.push({
uid: uuid(),
url: props.data.photo,
status: 'done'
})
}
isUpdate.value = true;
} else {
isUpdate.value = false;
content.value = '';
}
} else {
resetFields();
formRef.value?.clearValidate();
}
},
{ immediate: true }
);
</script>
<style lang="less">
.sdf{
display: none;
}
</style>

View File

@@ -0,0 +1,42 @@
<!-- 搜索表单 -->
<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>
</template>
<script lang="ts" setup>
import { PlusOutlined } from '@ant-design/icons-vue';
import type { GradeParam } from '@/api/user/grade/model';
import { watch } from 'vue';
const props = withDefaults(
defineProps<{
// 选中的角色
selection?: [];
}>(),
{}
);
const emit = defineEmits<{
(e: 'search', where?: GradeParam): void;
(e: 'add'): void;
(e: 'remove'): void;
(e: 'batchMove'): void;
}>();
// 新增
const add = () => {
emit('add');
};
watch(
() => props.selection,
() => {}
);
</script>

View File

@@ -0,0 +1,174 @@
<template>
<a-page-header
v-if="siteInfo"
:title="form.name"
:style="{ padding: screenWidth > 480 ? '16px 24px' : '0' }"
@back="() => $router.go(-1)"
>
<template #extra>
<a-button key="1" type="primary" @click="save">保存</a-button>
<a-button key="2" @click="openPreview(`${form.path}`)">预览</a-button>
</template>
<a-spin :spinning="spinning">
<div class="ele-cell ele-cell-align-top">
<!-- 设计画布 -->
<div class="body ele-cell-content ele-bg-white">
{{ form }}
<a-divider />
layout: {{ layout }}
<template v-for="(item, index) in layout" :key="index">
<template v-if="item.name == 'header'">
<!-- <DesignHeader :data="item" @done="onDone" />-->
</template>
<template v-if="item.name == 'banner'">
<!-- <DesignHeader :data="item" @done="onDone" />-->
<!-- <DesignBanner :data="item" @done="onDone" />-->
</template>
</template>
</div>
<!-- 中间间隙 -->
<div v-if="showTools" style="width: 20px"></div>
<div v-else style="width: 10px"></div>
<!-- 设计工具 -->
<DesignTools
v-model:visible="showTools"
:data="form"
@update="openTools"
@done="doTools"
/>
</div>
</a-spin>
</a-page-header>
</template>
<script lang="ts" setup>
import { reactive, ref, unref, watch } from 'vue';
import { useRouter } from 'vue-router';
import { useThemeStore } from '@/store/modules/theme';
import { storeToRefs } from 'pinia';
import useFormData from '@/utils/use-form-data';
import { getDesign, updateDesign } from '@/api/cms/design';
import { Design } from '@/api/cms/design/model';
import { message } from 'ant-design-vue';
import { FormInstance } from 'ant-design-vue/es/form';
import { openPreview } from '@/utils/common';
import { getSiteInfo } from '@/api/layout';
import { Website } from '@/api/cms/website/model';
import { Layout } from '@/api/layout/model';
// 表格选中数据
const formRef = ref<FormInstance | null>(null);
const { currentRoute } = useRouter();
const { query } = unref(currentRoute);
// 是否开启响应式布局
const themeStore = useThemeStore();
const { screenWidth } = storeToRefs(themeStore);
const current = ref<any>(null);
const spinning = ref(true);
const showTools = ref(true);
const siteInfo = ref<Website>();
const layout = ref<Layout>();
// 服务器信息
const { form, assignFields, resetFields } = useFormData<Design>({
pageId: undefined,
name: '',
images: '',
path: '',
component: '',
content: '',
type: undefined,
status: 0,
comments: '',
sortNumber: 100,
layout: undefined,
home: undefined
});
const openTools = (e) => {
showTools.value = !showTools.value;
};
const onDone = (item) => {
current.value = item;
};
const doTools = (item: any) => {
console.log(item, 'doTools');
current.value = item;
};
/* 保存编辑 */
const save = () => {
const formData = {
...form,
layout: JSON.stringify(form.layout)
};
updateDesign(formData)
.then((msg) => {
message.success('保存成功');
})
.catch((e) => {
message.error(e.message);
});
};
const { contentWidth } = storeToRefs(themeStore);
// 使用 watch 监听 contentWidth 改变
watch(contentWidth, (e) => {
console.log(e);
});
/**
* 加载数据
*/
const reload = (id: number) => {
// 加载网站信息
getSiteInfo().then((data) => {
siteInfo.value = data;
});
getDesign(id).then((data) => {
if (data) {
spinning.value = false;
if (data.layout) {
try {
layout.value = JSON.parse(data.layout);
} catch (e) {
console.log('JSON格式有误');
}
}
assignFields(data);
}
});
};
watch(
() => query.id,
(id) => {
if (id) {
reload(Number(id));
} else {
resetFields();
formRef.value?.clearValidate();
}
},
{ immediate: true }
);
</script>
<script lang="ts">
export default {
name: 'DesignDetail'
};
</script>
<style lang="less">
.body {
width: 80vw;
box-shadow: 0 0 6px rgba(0, 0, 0, 0.15);
}
.header {
height: 120px;
}
</style>

View File

@@ -0,0 +1,292 @@
<template>
<div class="page">
<div class="ele-body">
<a-card :bordered="false" :body-style="{ padding: '16px' }">
<ele-pro-table
ref="tableRef"
row-key="designId"
:columns="columns"
:datasource="datasource"
:customRow="customRow"
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 === 'name'">
<a @click="openPreview(record.path)">{{ record.name }}</a>
</template>
<template v-if="column.key === 'path'">
<span class="ele-text-placeholder">{{ record.path }}</span>
</template>
<template v-if="column.key === 'component'">
<span class="ele-text-placeholder">{{ record.component }}</span>
</template>
<template v-if="column.key === 'photo'">
<a-image :src="record.photo" :width="180" />
</template>
<template v-if="column.key === 'status'">
<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 @click="openDesign(record)">设计</a>
<a-divider type="vertical" />
<a @click="openEdit(record)">修改</a>
<a-divider type="vertical" />
<a-popconfirm
title="确定要删除此记录吗?"
:disabled="record.home == 1"
@confirm="remove(record)"
>
<a class="ele-text-danger">删除</a>
</a-popconfirm>
</a-space>
</template>
</template>
</ele-pro-table>
</a-card>
<!-- 编辑弹窗 -->
<DesignEdit v-model:visible="showEdit" :data="current" @done="reload" />
</div>
</div>
</template>
<script lang="ts" setup>
import { createVNode, ref } from 'vue';
import { message, Modal } from 'ant-design-vue';
import { ExclamationCircleOutlined } from '@ant-design/icons-vue';
import type { EleProTable } from 'ele-admin-pro';
import type {
DatasourceFunction,
ColumnItem
} from 'ele-admin-pro/es/ele-pro-table/types';
import Search from './components/search.vue';
import DesignEdit from './components/design-edit.vue';
import {
pageDesign,
removeDesign,
removeBatchDesign
} from '@/api/cms/design';
import type { Design, DesignParam } from '@/api/cms/design/model';
import { useRouter } from 'vue-router';
import { openPreview } from '@/utils/common';
// 表格实例
const tableRef = ref<InstanceType<typeof EleProTable> | null>(null);
// 表格选中数据
const selection = ref<Design[]>([]);
// 当前编辑数据
const current = ref<Design | null>(null);
// 是否显示编辑弹窗
const showEdit = ref(false);
// 是否显示批量移动弹窗
const showMove = ref(false);
const domain = localStorage.getItem('Domain');
// 加载状态
const loading = ref(true);
const { push } = useRouter();
// 表格数据源
const datasource: DatasourceFunction = ({
page,
limit,
where,
orders,
filters
}) => {
if (filters) {
where.status = filters.status;
}
return pageDesign({
...where,
...orders,
page,
limit
});
};
// 表格列配置
const columns = ref<ColumnItem[]>([
{
title: 'ID',
width: 90,
dataIndex: 'pageId'
},
{
title: '页面名称',
dataIndex: 'name',
key: 'name'
},
{
title: '路由地址',
dataIndex: 'path',
key: 'path'
},
{
title: '组件路径',
dataIndex: 'component',
key: 'component'
},
{
title: '配图',
dataIndex: 'photo',
key: 'photo',
width: 220
},
{
title: '状态',
dataIndex: 'status',
width: 120,
align: 'center',
key: 'status'
},
{
title: '排序',
dataIndex: 'sortNumber',
align: 'center',
width: 120,
showSorterTooltip: false
},
{
title: '操作',
key: 'action',
width: 180,
fixed: 'right',
align: 'center',
hideInSetting: true
}
]);
/* 搜索 */
const reload = (where?: DesignParam) => {
selection.value = [];
tableRef?.value?.reload({ where: where });
};
/* 打开编辑弹窗 */
const openEdit = (row?: Design) => {
current.value = row ?? null;
showEdit.value = true;
};
const openDesign = (row?: Design) => {
push({
path: '/cms/design/detail',
query: { id: row?.pageId }
});
};
/* 打开批量移动弹窗 */
const openMove = () => {
showMove.value = true;
};
/* 删除单个 */
const remove = (row: Design) => {
const hide = message.loading('请求中..', 0);
removeDesign(row.pageId)
.then((msg) => {
hide();
message.success(msg);
reload();
})
.catch((e) => {
hide();
message.error(e.message);
});
};
/* 批量删除 */
const removeBatch = () => {
if (!selection.value.length) {
message.error('请至少选择一条数据');
return;
}
Modal.confirm({
title: '提示',
content: '确定要删除选中的记录吗?',
icon: createVNode(ExclamationCircleOutlined),
maskClosable: true,
onOk: () => {
const hide = message.loading('请求中..', 0);
removeBatchDesign(selection.value.map((d) => d.pageId))
.then((msg) => {
hide();
message.success(msg);
reload();
})
.catch((e) => {
hide();
message.error(e.message);
});
}
});
};
/* 查询 */
const query = () => {
loading.value = true;
};
/* 自定义行属性 */
const customRow = (record: Design) => {
return {
// 行点击事件
onClick: () => {
// console.log(record);
},
// 行双击事件
onDblclick: () => {
openEdit(record);
}
};
};
query();
</script>
<script lang="ts">
export default {
name: 'Design'
};
</script>
<style lang="less" scoped>
.sys-org-table :deep(.ant-table-body) {
overflow: auto !important;
overflow: overlay !important;
}
.sys-org-table :deep(.ant-table-pagination.ant-pagination) {
padding: 0 4px;
margin-bottom: 0;
}
.design-item {
margin: auto;
display: flex;
text-align: center;
flex-direction: column;
justify-content: center;
align-items: center;
width: 70px;
height: 70px;
border-radius: 70px;
background: url('data:image/svg+xml;charset=utf8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20xmlns%3Axlink%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxlink%22%20version%3D%221.1%22%3E%3Cdefs%3E%3ClinearGradient%20id%3D%221%22%20x1%3D%220%22%20x2%3D%221%22%20y1%3D%220%22%20y2%3D%220%22%20gradientTransform%3D%22matrix(6.123233995736766e-17%2C%201%2C%20-0.024693877551020406%2C%206.123233995736766e-17%2C%200.5%2C%200)%22%3E%3Cstop%20stop-color%3D%22%230a060d%22%20stop-opacity%3D%221%22%20offset%3D%220%22%3E%3C%2Fstop%3E%3Cstop%20stop-color%3D%22%23660061%22%20stop-opacity%3D%221%22%20offset%3D%220.95%22%3E%3C%2Fstop%3E%3C%2FlinearGradient%3E%3C%2Fdefs%3E%3Crect%20width%3D%22100%25%22%20height%3D%22100%25%22%20fill%3D%22url(%231)%22%3E%3C%2Frect%3E%3C%2Fsvg%3E');
}
:deep(.ant-image-img) {
max-height: 80px;
}
</style>