签入版本
This commit is contained in:
@@ -1,69 +0,0 @@
|
|||||||
import { h } from 'vue';
|
|
||||||
import { NTag } from 'naive-ui';
|
|
||||||
|
|
||||||
export const columns = [
|
|
||||||
{
|
|
||||||
type: 'selection',
|
|
||||||
width: 50,
|
|
||||||
fixed: 'left',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: 'ID',
|
|
||||||
key: 'id',
|
|
||||||
fixed: 'left',
|
|
||||||
width: 50,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: '位置描述',
|
|
||||||
key: 'description',
|
|
||||||
width: 250,
|
|
||||||
render(record) {
|
|
||||||
return record.layoutDescription + '>>' + record.layoutLocation;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: '推荐类型',
|
|
||||||
key: 'typeText',
|
|
||||||
width: 100,
|
|
||||||
render(record) {
|
|
||||||
return h(
|
|
||||||
NTag,
|
|
||||||
{
|
|
||||||
style: {
|
|
||||||
marginRight: '6px',
|
|
||||||
},
|
|
||||||
bordered: false,
|
|
||||||
type: 'info',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
default: () => record.typeText,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: '推荐ID',
|
|
||||||
key: 'typeId',
|
|
||||||
width: 100,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: '推荐标题',
|
|
||||||
key: 'typeTitle',
|
|
||||||
width: 200,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: '排序',
|
|
||||||
key: 'sort',
|
|
||||||
width: 100,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: '创建人',
|
|
||||||
key: 'createUser',
|
|
||||||
width: 100,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: '创建时间',
|
|
||||||
key: 'createTime',
|
|
||||||
width: 180,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
@@ -1,248 +0,0 @@
|
|||||||
<template>
|
|
||||||
<n-drawer v-model:show="isDrawer" width="800">
|
|
||||||
<n-drawer-content :title="props.layoutId ? '编辑' : '新增'" closable>
|
|
||||||
<template #default>
|
|
||||||
<n-form
|
|
||||||
class="ls-form"
|
|
||||||
ref="formRef"
|
|
||||||
:model="formData"
|
|
||||||
label-placement="left"
|
|
||||||
label-width="85px"
|
|
||||||
>
|
|
||||||
<n-form-item
|
|
||||||
label="页面布局"
|
|
||||||
path="layoutId"
|
|
||||||
class="flex-1"
|
|
||||||
:rule="{ type: 'number', required: true, message: '请选择页面布局', trigger: 'change' }"
|
|
||||||
>
|
|
||||||
<n-select
|
|
||||||
v-model:value="formData.layoutId"
|
|
||||||
class="flex-1"
|
|
||||||
clearable
|
|
||||||
placeholder="请选择页面布局"
|
|
||||||
:options="layoutList"
|
|
||||||
label-field="description"
|
|
||||||
value-field="id"
|
|
||||||
/>
|
|
||||||
</n-form-item>
|
|
||||||
<n-form-item
|
|
||||||
label="页面类型"
|
|
||||||
path="type"
|
|
||||||
:rule="{ type: 'number', required: true, message: '请选择页面类型', trigger: 'change' }"
|
|
||||||
>
|
|
||||||
<n-select
|
|
||||||
v-model:value="formData.type"
|
|
||||||
placeholder="请选择页面类型"
|
|
||||||
@update:value="handleType"
|
|
||||||
:options="typeList"
|
|
||||||
/>
|
|
||||||
</n-form-item>
|
|
||||||
<n-form-item
|
|
||||||
label="推荐内容"
|
|
||||||
path="typeId"
|
|
||||||
:rule="{
|
|
||||||
key: 'typeId',
|
|
||||||
type: 'number',
|
|
||||||
required: true,
|
|
||||||
message: '请选择推荐内容',
|
|
||||||
trigger: 'blur',
|
|
||||||
}"
|
|
||||||
>
|
|
||||||
<n-input
|
|
||||||
v-model:value="formData.typeText"
|
|
||||||
placeholder="请选择推荐内容"
|
|
||||||
@click="getLayoutItem"
|
|
||||||
/>
|
|
||||||
</n-form-item>
|
|
||||||
<n-form-item label="图片路径" path="image">
|
|
||||||
<UploadImg
|
|
||||||
:fileType="['image/jpeg', 'image/png', 'image/jpg', 'image/gif']"
|
|
||||||
name="article"
|
|
||||||
:fileSize="200"
|
|
||||||
v-model:image-url="formData.image"
|
|
||||||
>
|
|
||||||
<template #tip>支持扩展名: jpg png jpeg;文件大小不超过200M</template>
|
|
||||||
</UploadImg>
|
|
||||||
</n-form-item>
|
|
||||||
<n-form-item label="排序" path="sort">
|
|
||||||
<n-input-number v-model:value="formData.sort" />
|
|
||||||
</n-form-item>
|
|
||||||
</n-form>
|
|
||||||
</template>
|
|
||||||
<template #footer>
|
|
||||||
<n-space>
|
|
||||||
<n-button @click="handleClose">取消</n-button>
|
|
||||||
<n-button :loading="subLoading" type="primary" @click="submit"> 确定 </n-button>
|
|
||||||
</n-space>
|
|
||||||
</template>
|
|
||||||
</n-drawer-content>
|
|
||||||
<chooseArticle
|
|
||||||
v-if="chooseVisible"
|
|
||||||
v-model:visible="chooseVisible"
|
|
||||||
:type="formData.type"
|
|
||||||
ref="articleRef"
|
|
||||||
@success="selectedCallback"
|
|
||||||
/>
|
|
||||||
</n-drawer>
|
|
||||||
</template>
|
|
||||||
<script lang="ts" setup>
|
|
||||||
import { getLayoutDetail, layoutAdd, layoutUpdate } from '@/api/content/layoutItem';
|
|
||||||
import { getLayoutAllList } from '@/api/content/layout';
|
|
||||||
import { onMounted, reactive, ref, nextTick } from 'vue';
|
|
||||||
import { useMessage } from 'naive-ui';
|
|
||||||
import UploadImg from '@/components/Upload/Image.vue';
|
|
||||||
import chooseArticle from './layout/index.vue';
|
|
||||||
import { useLockFn } from '@/utils/useLockFn';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 定义参数
|
|
||||||
*/
|
|
||||||
const emit = defineEmits(['success']);
|
|
||||||
const formRef = ref();
|
|
||||||
const articleRef = ref();
|
|
||||||
const message = useMessage();
|
|
||||||
const chooseVisible = ref(false);
|
|
||||||
const isDrawer = ref(false);
|
|
||||||
const layoutList = ref([]);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 定义表单参数
|
|
||||||
*/
|
|
||||||
const formData = reactive({
|
|
||||||
id: '',
|
|
||||||
layoutId: null,
|
|
||||||
type: null,
|
|
||||||
typeText: '',
|
|
||||||
typeId: '',
|
|
||||||
image: '',
|
|
||||||
sort: 0,
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 定义接收的参数
|
|
||||||
*/
|
|
||||||
const props = defineProps({
|
|
||||||
layoutId: {
|
|
||||||
type: Number,
|
|
||||||
required: true,
|
|
||||||
default: 0,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
/**
|
|
||||||
* 定义数据
|
|
||||||
*/
|
|
||||||
const typeList = [
|
|
||||||
{ label: 'CMS文章', value: 1 },
|
|
||||||
{ label: '通知公告', value: 2 },
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取推荐类型
|
|
||||||
*/
|
|
||||||
const getLayoutItem = async () => {
|
|
||||||
if (!formData.type) {
|
|
||||||
message.warning('请选择页面类型');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
chooseVisible.value = true;
|
|
||||||
await nextTick();
|
|
||||||
articleRef.value.openModal();
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 执行选择类型
|
|
||||||
*/
|
|
||||||
const handleType = () => {
|
|
||||||
formData.typeId = '';
|
|
||||||
formData.typeText = '';
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 执行提交
|
|
||||||
*/
|
|
||||||
const handleSubmit = async () => {
|
|
||||||
formRef.value
|
|
||||||
.validate()
|
|
||||||
.then(async () => {
|
|
||||||
props.layoutId ? await layoutUpdate(formData) : await layoutAdd(formData);
|
|
||||||
message.success('操作成功');
|
|
||||||
isDrawer.value = false;
|
|
||||||
emit('success');
|
|
||||||
})
|
|
||||||
.catch((error) => {});
|
|
||||||
};
|
|
||||||
const { isLock: subLoading, lockFn: submit } = useLockFn(handleSubmit);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 打开窗体
|
|
||||||
*/
|
|
||||||
const openDrawer = async (layoutId) => {
|
|
||||||
isDrawer.value = true;
|
|
||||||
getAllDict();
|
|
||||||
for (const key in formData) {
|
|
||||||
formData[key] = '';
|
|
||||||
}
|
|
||||||
formData.layoutId = null;
|
|
||||||
formData.type = null;
|
|
||||||
formData.sort = 0;
|
|
||||||
if (layoutId) {
|
|
||||||
setFormData(layoutId);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
* 关闭窗体
|
|
||||||
*/
|
|
||||||
const handleClose = () => {
|
|
||||||
isDrawer.value = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 执行更新
|
|
||||||
* @param show 参数
|
|
||||||
*/
|
|
||||||
const handleUpdate = (show) => {
|
|
||||||
if (!show) {
|
|
||||||
handleClose();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
* 设置表单数据
|
|
||||||
*/
|
|
||||||
const setFormData = async (layoutId) => {
|
|
||||||
const data = await getLayoutDetail(layoutId);
|
|
||||||
for (const key in formData) {
|
|
||||||
if (data[key] != null && data[key] != undefined) {
|
|
||||||
//@ts-ignore
|
|
||||||
formData[key] = data[key];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 选择推荐内容成功回调事件
|
|
||||||
*/
|
|
||||||
const selectedCallback = (row) => {
|
|
||||||
console.log(row);
|
|
||||||
formData.typeText = row.title;
|
|
||||||
formData.typeId = row.id;
|
|
||||||
formRef.value?.validate(
|
|
||||||
(errors) => {},
|
|
||||||
(rule) => {
|
|
||||||
return rule?.key === 'typeId';
|
|
||||||
},
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取全部字典数据
|
|
||||||
*/
|
|
||||||
const getAllDict = async () => {
|
|
||||||
let list = await getLayoutAllList();
|
|
||||||
layoutList.value = list ? list : [];
|
|
||||||
};
|
|
||||||
|
|
||||||
defineExpose({
|
|
||||||
openDrawer,
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
@@ -1,214 +0,0 @@
|
|||||||
<template>
|
|
||||||
<div>
|
|
||||||
<n-card :bordered="false" class="pt-3 mb-3 proCard">
|
|
||||||
<BasicForm @register="register" @submit="handleSubmit" @reset="handleReset">
|
|
||||||
<template #statusSlot="{ model, field }">
|
|
||||||
<n-input v-model:value="model[field]" />
|
|
||||||
</template>
|
|
||||||
</BasicForm>
|
|
||||||
</n-card>
|
|
||||||
<n-card :bordered="false" class="proCard">
|
|
||||||
<BasicTable
|
|
||||||
:columns="columns"
|
|
||||||
:request="loadDataTable"
|
|
||||||
:row-key="(row) => row.id"
|
|
||||||
ref="basicTableRef"
|
|
||||||
:actionColumn="actionColumn"
|
|
||||||
@update:checked-row-keys="onCheckedRow"
|
|
||||||
:autoScrollX="true"
|
|
||||||
>
|
|
||||||
<template #tableTitle>
|
|
||||||
<n-space>
|
|
||||||
<n-button type="primary" @click="handleAdd" v-perm="['sys:layoutItem:add']">
|
|
||||||
<template #icon>
|
|
||||||
<n-icon>
|
|
||||||
<PlusOutlined />
|
|
||||||
</n-icon>
|
|
||||||
</template>
|
|
||||||
新建
|
|
||||||
</n-button>
|
|
||||||
<n-button
|
|
||||||
type="error"
|
|
||||||
@click="handleDelete"
|
|
||||||
:disabled="!rowKeys.length"
|
|
||||||
v-perm="['sys:layoutItem:batchDelete']"
|
|
||||||
>
|
|
||||||
<template #icon>
|
|
||||||
<n-icon>
|
|
||||||
<DeleteOutlined />
|
|
||||||
</n-icon>
|
|
||||||
</template>
|
|
||||||
删除
|
|
||||||
</n-button>
|
|
||||||
</n-space>
|
|
||||||
</template>
|
|
||||||
</BasicTable>
|
|
||||||
</n-card>
|
|
||||||
<editDialog ref="createModalRef" :layoutId="layoutId" @success="reloadTable('noRefresh')" />
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script lang="ts" setup>
|
|
||||||
import { h, nextTick, reactive, ref, unref } from 'vue';
|
|
||||||
import { useMessage, useDialog } from 'naive-ui';
|
|
||||||
import { TableAction } from '@/components/Table';
|
|
||||||
import { BasicForm, useForm } from '@/components/Form/index';
|
|
||||||
import { getLayoutList, layoutDelete, layoutBatchDelete } from '@/api/content/layoutItem';
|
|
||||||
import { columns } from './columns';
|
|
||||||
import { PlusOutlined, DeleteOutlined, FormOutlined } from '@vicons/antd';
|
|
||||||
import editDialog from './edit.vue';
|
|
||||||
import { schemas } from './querySchemas';
|
|
||||||
import { renderIcon } from '@/utils';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 定义参数
|
|
||||||
*/
|
|
||||||
const message = useMessage();
|
|
||||||
const dialog = useDialog();
|
|
||||||
const basicTableRef = ref();
|
|
||||||
const createModalRef = ref();
|
|
||||||
const editVisible = ref(false);
|
|
||||||
const layoutId = ref(0);
|
|
||||||
const rowKeys = ref([]);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 定义查询参数
|
|
||||||
*/
|
|
||||||
const formParams = reactive({
|
|
||||||
layoutId: '',
|
|
||||||
type: '',
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 定义操作栏
|
|
||||||
*/
|
|
||||||
const actionColumn = reactive({
|
|
||||||
width: 200,
|
|
||||||
title: '操作',
|
|
||||||
align: 'center',
|
|
||||||
key: 'action',
|
|
||||||
fixed: 'right',
|
|
||||||
render(record) {
|
|
||||||
return h(TableAction as any, {
|
|
||||||
style: 'button',
|
|
||||||
actions: [
|
|
||||||
{
|
|
||||||
label: '编辑',
|
|
||||||
icon: renderIcon(FormOutlined),
|
|
||||||
type: 'info',
|
|
||||||
onClick: handleEdit.bind(null, record),
|
|
||||||
auth: ['sys:layoutItem:update'],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: '删除',
|
|
||||||
icon: renderIcon(DeleteOutlined),
|
|
||||||
type: 'error',
|
|
||||||
onClick: handleDelete.bind(null, record),
|
|
||||||
auth: ['sys:layoutItem:delete'],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 加载数据列表
|
|
||||||
* @param res 参数
|
|
||||||
*/
|
|
||||||
const loadDataTable = async (res) => {
|
|
||||||
rowKeys.value = [];
|
|
||||||
const result = await getLayoutList({ ...formParams, ...res });
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 数据行选中事件
|
|
||||||
* @param keys 参数
|
|
||||||
*/
|
|
||||||
function onCheckedRow(keys) {
|
|
||||||
rowKeys.value = keys;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 刷新数据列表
|
|
||||||
* @param noRefresh 参数
|
|
||||||
*/
|
|
||||||
function reloadTable(noRefresh = '') {
|
|
||||||
basicTableRef.value.reload(noRefresh ? {} : { pageNo: 1 });
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 执行提交表单
|
|
||||||
* @param values 参数
|
|
||||||
*/
|
|
||||||
function handleSubmit(values: Recordable) {
|
|
||||||
for (const key in formParams) {
|
|
||||||
formParams[key] = '';
|
|
||||||
}
|
|
||||||
for (const key in values) {
|
|
||||||
formParams[key] = values[key];
|
|
||||||
}
|
|
||||||
reloadTable();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 执行重置
|
|
||||||
* @param values 参数
|
|
||||||
*/
|
|
||||||
function handleReset(values: Recordable) {
|
|
||||||
for (const key in formParams) {
|
|
||||||
formParams[key] = '';
|
|
||||||
}
|
|
||||||
for (const key in values) {
|
|
||||||
formParams[key] = values[key];
|
|
||||||
}
|
|
||||||
reloadTable();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 执行注册
|
|
||||||
*/
|
|
||||||
const [register, {}] = useForm({
|
|
||||||
gridProps: { cols: '1 s:1 m:2 l:3 xl:4 2xl:4' },
|
|
||||||
labelWidth: 80,
|
|
||||||
schemas,
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 执行添加
|
|
||||||
*/
|
|
||||||
const handleAdd = async () => {
|
|
||||||
layoutId.value = 0;
|
|
||||||
const { openDrawer } = createModalRef.value;
|
|
||||||
openDrawer();
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 执行编辑
|
|
||||||
*/
|
|
||||||
async function handleEdit(record: Recordable) {
|
|
||||||
layoutId.value = record.id;
|
|
||||||
const { openDrawer } = createModalRef.value;
|
|
||||||
openDrawer(layoutId.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 执行删除
|
|
||||||
* @param id 参数
|
|
||||||
*/
|
|
||||||
async function handleDelete(record) {
|
|
||||||
dialog.warning({
|
|
||||||
title: '提示',
|
|
||||||
content: '确定要删除?',
|
|
||||||
positiveText: '确定',
|
|
||||||
negativeText: '取消',
|
|
||||||
onPositiveClick: async () => {
|
|
||||||
record.id ? await layoutDelete(record.id) : await layoutBatchDelete(rowKeys.value);
|
|
||||||
message.success('删除成功');
|
|
||||||
reloadTable();
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style lang="less" scoped></style>
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
import { h } from 'vue';
|
|
||||||
|
|
||||||
export const columns = [
|
|
||||||
{
|
|
||||||
type: 'selection',
|
|
||||||
width: 50,
|
|
||||||
fixed: 'left',
|
|
||||||
multiple: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: 'ID',
|
|
||||||
key: 'id',
|
|
||||||
width: 50,
|
|
||||||
fixed: 'left',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: '文章标题',
|
|
||||||
key: 'title',
|
|
||||||
width: 300,
|
|
||||||
ren(record) {
|
|
||||||
return h(
|
|
||||||
'a',
|
|
||||||
{
|
|
||||||
href: 'http://www.djangoadmin.cn',
|
|
||||||
target: '_blank',
|
|
||||||
},
|
|
||||||
record.title,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: '文章分类',
|
|
||||||
key: 'categoryName',
|
|
||||||
width: 100,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: '文章状态',
|
|
||||||
key: 'status',
|
|
||||||
render(record) {
|
|
||||||
return h('span', record.status === 1 ? '下架' : '正常');
|
|
||||||
},
|
|
||||||
width: 100,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: '创建人',
|
|
||||||
key: 'createUser',
|
|
||||||
width: 100,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: '创建时间',
|
|
||||||
key: 'createTime',
|
|
||||||
width: 180,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
import { FormSchema } from '@/components/Form/index';
|
|
||||||
export const schemas: FormSchema[] = [
|
|
||||||
{
|
|
||||||
field: 'title',
|
|
||||||
component: 'NInput',
|
|
||||||
label: '文章标题',
|
|
||||||
componentProps: {
|
|
||||||
placeholder: '请输入文章标题',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
field: 'status',
|
|
||||||
component: 'NSelect',
|
|
||||||
label: '文章状态',
|
|
||||||
componentProps: {
|
|
||||||
placeholder: '请选择文章状态',
|
|
||||||
clearable: true,
|
|
||||||
options: [
|
|
||||||
{
|
|
||||||
label: '下架',
|
|
||||||
value: '1',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: '正常',
|
|
||||||
value: '0',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
];
|
|
||||||
@@ -1,205 +0,0 @@
|
|||||||
<template>
|
|
||||||
<basicModal
|
|
||||||
@register="modalRegister"
|
|
||||||
ref="modalRef"
|
|
||||||
class="basicModal basicFormModal"
|
|
||||||
@on-ok="handleSubmits"
|
|
||||||
@on-close="handleClose"
|
|
||||||
>
|
|
||||||
<template #default>
|
|
||||||
<BasicForm @register="register" @submit="handleSubmit" @reset="handleReset">
|
|
||||||
<template #statusSlot="{ model, field }">
|
|
||||||
<n-input v-model:value="model[field]" />
|
|
||||||
</template>
|
|
||||||
</BasicForm>
|
|
||||||
<BasicTable
|
|
||||||
:columns="columnsType()"
|
|
||||||
:request="loadDataTable"
|
|
||||||
ref="tableRef"
|
|
||||||
:autoScrollX="true"
|
|
||||||
:row-key="(row) => row.id"
|
|
||||||
@update:checked-row-keys="rowClick"
|
|
||||||
:row-props="rowProps"
|
|
||||||
v-model:checked-row-keys="checkedKeys"
|
|
||||||
:showTableSetting="false"
|
|
||||||
/>
|
|
||||||
</template>
|
|
||||||
</basicModal>
|
|
||||||
</template>
|
|
||||||
<script lang="ts" setup>
|
|
||||||
import { getArticleList } from '@/api/content/article';
|
|
||||||
import { BasicForm, useForm } from '@/components/Form/index';
|
|
||||||
import { getNoticeList } from '@/api/data/notice';
|
|
||||||
import { onMounted, reactive, ref } from 'vue';
|
|
||||||
import { useModal } from '@/components/Modal';
|
|
||||||
import { useMessage } from 'naive-ui';
|
|
||||||
import { columns } from './article/columns';
|
|
||||||
import { schemas } from './article/querySchemas';
|
|
||||||
import { columns2 } from './notice/columns';
|
|
||||||
import { schemas2 } from './notice/querySchemas';
|
|
||||||
|
|
||||||
const emit = defineEmits(['success', 'update:visible', 'update:checked-row-keys']);
|
|
||||||
const message = useMessage();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 定义接收的参数
|
|
||||||
*/
|
|
||||||
const props = defineProps({
|
|
||||||
visible: {
|
|
||||||
type: Boolean,
|
|
||||||
required: true,
|
|
||||||
default: false,
|
|
||||||
},
|
|
||||||
type: {
|
|
||||||
type: Number,
|
|
||||||
required: true,
|
|
||||||
default: 1,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
const selectRow = ref({});
|
|
||||||
const tableRef = ref();
|
|
||||||
const checkedKeys = ref([]);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 定义模态
|
|
||||||
*/
|
|
||||||
const [modalRegister, { openModal, setSubLoading }] = useModal({
|
|
||||||
title: props.type == 1 ? 'CMS文章' : '通知公告',
|
|
||||||
width: 1000,
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 定义查询参数
|
|
||||||
*/
|
|
||||||
const formParams = reactive({
|
|
||||||
title: '',
|
|
||||||
status: '',
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 定义列类型
|
|
||||||
*/
|
|
||||||
const columnsType = () => {
|
|
||||||
if (props.type == 1) {
|
|
||||||
// 文章
|
|
||||||
return columns;
|
|
||||||
} else if (props.type == 2) {
|
|
||||||
// 通知公告
|
|
||||||
return columns2;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 执行提交表单
|
|
||||||
*/
|
|
||||||
const handleSubmits = async () => {
|
|
||||||
if (!selectRow.value.id) {
|
|
||||||
setSubLoading(false);
|
|
||||||
return message.error('请选择文章');
|
|
||||||
}
|
|
||||||
setSubLoading(false);
|
|
||||||
emit('update:visible', false);
|
|
||||||
emit('success', selectRow.value);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 关闭窗体
|
|
||||||
*/
|
|
||||||
const handleClose = () => {
|
|
||||||
emit('update:visible', false);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 加载数据列表
|
|
||||||
* @param res 参数
|
|
||||||
*/
|
|
||||||
const loadDataTable = async (res: any) => {
|
|
||||||
let result = [];
|
|
||||||
if (props.type == 1) {
|
|
||||||
result = await getArticleList({ ...formParams, ...res });
|
|
||||||
} else {
|
|
||||||
result = await getNoticeList({ ...formParams, ...res });
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 刷新数据列表
|
|
||||||
* @param noRefresh 参数
|
|
||||||
*/
|
|
||||||
function reloadTable(noRefresh = '') {
|
|
||||||
tableRef.value.reload(noRefresh ? {} : { pageNo: 1 });
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 执行注册
|
|
||||||
*/
|
|
||||||
const [register, {}] = useForm({
|
|
||||||
gridProps: { cols: '1 s:1 m:2 l:3 xl:4 2xl:4' },
|
|
||||||
labelWidth: 80,
|
|
||||||
schemas: props.type == 1 ? schemas : schemas2,
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 执行提交表单
|
|
||||||
* @param values 参数
|
|
||||||
*/
|
|
||||||
function handleSubmit(values) {
|
|
||||||
for (const key in formParams) {
|
|
||||||
formParams[key] = '';
|
|
||||||
}
|
|
||||||
for (const key in values) {
|
|
||||||
formParams[key] = values[key];
|
|
||||||
}
|
|
||||||
reloadTable();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 执行重置
|
|
||||||
*/
|
|
||||||
function handleReset() {
|
|
||||||
for (const key in formParams) {
|
|
||||||
formParams[key] = '';
|
|
||||||
}
|
|
||||||
reloadTable();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 数据行点击事件
|
|
||||||
* @param record 参数
|
|
||||||
*/
|
|
||||||
const rowProps = (row) => {
|
|
||||||
console.log(row);
|
|
||||||
return {
|
|
||||||
style: 'cursor: pointer;',
|
|
||||||
onClick: () => {
|
|
||||||
checkedKeys.value = [row.id];
|
|
||||||
selectRow.value = row;
|
|
||||||
},
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 行点击事件
|
|
||||||
* @param record 数据记录
|
|
||||||
* @param row 数据行
|
|
||||||
*/
|
|
||||||
const rowClick = (record, row) => {
|
|
||||||
console.log(record);
|
|
||||||
checkedKeys.value = record;
|
|
||||||
selectRow.value = row[0];
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 钩子函数
|
|
||||||
*/
|
|
||||||
onMounted(() => {});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 定义函数
|
|
||||||
*/
|
|
||||||
defineExpose({
|
|
||||||
openModal,
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
import { h } from 'vue';
|
|
||||||
import { NTag } from 'naive-ui';
|
|
||||||
|
|
||||||
export const columns2 = [
|
|
||||||
{
|
|
||||||
type: 'selection',
|
|
||||||
width: 50,
|
|
||||||
fixed: 'left',
|
|
||||||
multiple: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: 'ID',
|
|
||||||
key: 'id',
|
|
||||||
width: 50,
|
|
||||||
fixed: 'left',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: '通知标题',
|
|
||||||
key: 'title',
|
|
||||||
width: 300,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: '通知类型',
|
|
||||||
key: 'type',
|
|
||||||
width: 100,
|
|
||||||
render(record) {
|
|
||||||
return h(
|
|
||||||
NTag,
|
|
||||||
{
|
|
||||||
type: record.type == 1 ? 'info' : 'success',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
default: () => (record.type == 1 ? '通知' : '公告'),
|
|
||||||
},
|
|
||||||
);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: '通知状态',
|
|
||||||
key: 'status',
|
|
||||||
render(record) {
|
|
||||||
return h(
|
|
||||||
NTag,
|
|
||||||
{
|
|
||||||
type: record.status == 1 ? 'success' : 'error',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
default: () => (record.status == 1 ? '正常' : '禁用'),
|
|
||||||
},
|
|
||||||
);
|
|
||||||
},
|
|
||||||
width: 100,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: '点击率',
|
|
||||||
key: 'clickNum',
|
|
||||||
width: 100,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: '创建人',
|
|
||||||
key: 'createUser',
|
|
||||||
width: 100,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: '创建时间',
|
|
||||||
key: 'createTime',
|
|
||||||
width: 180,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
import { FormSchema } from '@/components/Form/index';
|
|
||||||
export const schemas2: FormSchema[] = [
|
|
||||||
{
|
|
||||||
field: 'title',
|
|
||||||
component: 'NInput',
|
|
||||||
label: '通知标题',
|
|
||||||
componentProps: {
|
|
||||||
placeholder: '请输入通知标题',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
field: 'type',
|
|
||||||
component: 'NSelect',
|
|
||||||
label: '通知类型',
|
|
||||||
componentProps: {
|
|
||||||
placeholder: '请选择通知类型',
|
|
||||||
clearable: true,
|
|
||||||
options: [
|
|
||||||
{
|
|
||||||
label: '通知',
|
|
||||||
value: '1',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: '公告',
|
|
||||||
value: '2',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
field: 'status',
|
|
||||||
component: 'NSelect',
|
|
||||||
label: '通知状态',
|
|
||||||
componentProps: {
|
|
||||||
placeholder: '请选择通知状态',
|
|
||||||
clearable: true,
|
|
||||||
options: [
|
|
||||||
{
|
|
||||||
label: '正常',
|
|
||||||
value: '1',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: '关闭',
|
|
||||||
value: '2',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
];
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
import { FormSchema } from '@/components/Form/index';
|
|
||||||
import { getLayoutAllList } from '@/api/content/layout';
|
|
||||||
export const loadSelectData = async (res) => {
|
|
||||||
//这里可以进行数据转换处理
|
|
||||||
return (await getLayoutAllList({ ...res })).map((item, index) => {
|
|
||||||
return {
|
|
||||||
...item,
|
|
||||||
label: item.description,
|
|
||||||
value: item.id,
|
|
||||||
index,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
};
|
|
||||||
export const schemas: FormSchema[] = [
|
|
||||||
{
|
|
||||||
field: 'layoutId',
|
|
||||||
component: 'BasicSelect',
|
|
||||||
label: '页面布局',
|
|
||||||
componentProps: {
|
|
||||||
placeholder: '请选择页面布局',
|
|
||||||
clearable: true,
|
|
||||||
block: true,
|
|
||||||
request: loadSelectData,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
field: 'type',
|
|
||||||
component: 'NSelect',
|
|
||||||
label: '页面类型',
|
|
||||||
componentProps: {
|
|
||||||
placeholder: '请选择页面类型',
|
|
||||||
clearable: true,
|
|
||||||
options: [
|
|
||||||
{
|
|
||||||
label: 'CMS文章',
|
|
||||||
value: '1',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: '通知公告',
|
|
||||||
value: '2',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
];
|
|
||||||
Reference in New Issue
Block a user