diff --git a/.gitignore b/.gitignore index 53f7466..bee578d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ node_modules .DS_Store dist dist-ssr -*.local \ No newline at end of file +*.localhost \ No newline at end of file diff --git a/src/api/setting/advertising.js b/src/api/setting/advertising.js index c2d57df..c5f36da 100644 --- a/src/api/setting/advertising.js +++ b/src/api/setting/advertising.js @@ -45,4 +45,3 @@ export function advertisingDelete(ids) { method: 'delete' }) } - diff --git a/src/api/setting/notice.js b/src/api/setting/notice.js new file mode 100644 index 0000000..d70700c --- /dev/null +++ b/src/api/setting/notice.js @@ -0,0 +1,71 @@ +import { defAxios as request } from '@/utils/http' + +/** + * @description: 分页查询广告列表 + * @return {*} + */ +export function fetchNoticeList(params) { + return request({ + url: '/notice/index', + method: 'get', + params + }) +} +/** + * @description: 创建广告 + * @return {*} + */ +export function noticeCreate(data) { + return request({ + url: '/notice/add', + method: 'post', + data + }) +} + +/** + * @description: 更新通知公告 + * @return {*} + */ +export function noticeUpdate(data) { + return request({ + url: `/notice/edit`, + method: 'put', + data + }) +} + +/** + * @description: 更新通知公告 + * @return {*} + */ +export function isTopUpdate(data) { + return request({ + url: `/notice/setIsTop`, + method: 'put', + data + }) +} + +/** + * @description: 更新通知公告 + * @return {*} + */ +export function statusUpdate(data) { + return request({ + url: `/notice/status`, + method: 'put', + data + }) +} + +/** + * @description: 删除广告 + * @return {*} + */ +export function noticeDelete(ids) { + return request({ + url: `/notice/delete/${ids}`, + method: 'delete' + }) +} diff --git a/src/utils/dictionary.js b/src/utils/dictionary.js index fc848cd..992fb08 100644 --- a/src/utils/dictionary.js +++ b/src/utils/dictionary.js @@ -45,3 +45,8 @@ export const ADVERTISING_STATUS = [ { label: '正常', value: 1, color: { color: '#e6f7ff', textColor: '#096dd9', borderColor: '#91d5ff' }}, { label: '停用', value: 2, color: { color: '#fff1f0', textColor: '#cf1322', borderColor: '#ffa39e' }} ] + +export const NOTICE_SOURCE = [ + { label: '内部通知', value: 1, color: { color: '#f6ffed', textColor: '#389e0d', borderColor: '#b7eb8f' }}, + { label: '外部新闻', value: 2, color: { color: '#fff7e6', textColor: '#d46b08', borderColor: '#ffd591' }} +] diff --git a/src/views/setting/advertising/components/AdvertisingModal.vue b/src/views/setting/advertising/components/AdvertisingModal.vue index ccf1e0c..0e27ca7 100644 --- a/src/views/setting/advertising/components/AdvertisingModal.vue +++ b/src/views/setting/advertising/components/AdvertisingModal.vue @@ -28,7 +28,7 @@ - + diff --git a/src/views/setting/advertising/tools/form.js b/src/views/setting/advertising/tools/form.js index 7968a1f..10571db 100644 --- a/src/views/setting/advertising/tools/form.js +++ b/src/views/setting/advertising/tools/form.js @@ -22,7 +22,7 @@ export const form = reactive({ sort: [{ required: true, type: 'number', message: '请输入排序号', trigger: 'blur' }] }, formItem: [ - { type: 'oss', refIndex: 0, key: 'imageStatus', file: 'cover', label: '广告图片', props: { maxlength: '20', placeholder: '请输入部门编号', clearable: true }}, + { type: 'oss', refIndex: 0, key: 'imageStatus', file: 'cover', label: '广告图片' }, { type: 'input', key: 'title', label: '广告标题', props: { maxlength: '20', placeholder: '请输入广告标题', clearable: true }}, { type: 'input', key: 'description', label: '广告描述', props: { maxlength: '20', placeholder: '请输入广告描述', clearable: true }}, @@ -31,7 +31,7 @@ export const form = reactive({ { type: 'select', key: 'platform', label: '投放平台', props: { options: ADVERTISING_PLATFORM, placeholder: '请选择投放平台' }}, { type: 'input', key: 'url', label: '广告URL', props: { maxlength: '20', placeholder: '请输入广告URL', clearable: true }}, - { type: 'radio', key: 'status', label: '广告状态', options: ADVERTISING_STATUS, mode: ['config'] }, + { type: 'radio', key: 'status', label: '广告状态', options: ADVERTISING_STATUS }, { type: 'number', key: 'width', label: '广告宽度', props: { min: 0, placeholder: '请输入广告宽度', showButton: false, clearable: true }}, { type: 'number', key: 'height', label: '广告高度', props: { min: 0, placeholder: '请输入广告高度', showButton: false, clearable: true }}, diff --git a/src/views/setting/advertising/tools/table.js b/src/views/setting/advertising/tools/table.js index 66cf4a6..c1bb26b 100644 --- a/src/views/setting/advertising/tools/table.js +++ b/src/views/setting/advertising/tools/table.js @@ -193,16 +193,16 @@ const data = reactive({ render(row) { return h(TableAction, { actions: [ - { - label: '添加', - type: 'button', - props: { - type: 'primary', - text: true, - onClick: getRowData.bind(null, row, 'create') - }, - auth: 'basic_list' - }, + // { + // label: '查看', + // type: 'button', + // props: { + // type: 'primary', + // text: true, + // onClick: getRowData.bind(null, row, 'preview') + // }, + // auth: 'basic_list' + // }, { label: '修改', type: 'button', diff --git a/src/views/setting/notice/components/NoticeModal.vue b/src/views/setting/notice/components/NoticeModal.vue new file mode 100644 index 0000000..be9260f --- /dev/null +++ b/src/views/setting/notice/components/NoticeModal.vue @@ -0,0 +1,187 @@ + + + + + diff --git a/src/views/setting/notice/index.vue b/src/views/setting/notice/index.vue index e0047f7..98c8d80 100644 --- a/src/views/setting/notice/index.vue +++ b/src/views/setting/notice/index.vue @@ -1,17 +1,99 @@ diff --git a/src/views/setting/notice/tools/form.js b/src/views/setting/notice/tools/form.js new file mode 100644 index 0000000..fa230b1 --- /dev/null +++ b/src/views/setting/notice/tools/form.js @@ -0,0 +1,31 @@ +import { reactive } from 'vue' +import { NOTICE_SOURCE, ADVERTISING_STATUS } from '@/utils/dictionary.js' + +export const form = reactive({ + noticeForm: { + image: null, + title: null, + source: 1, + status: 1, + url: null, + guide: null, + content: null + }, + noticeRules: { + title: [{ required: true, message: '请输入广告标题', trigger: 'blur' }] + }, + formItem: [ + { type: 'oss', refIndex: 0, key: 'imageStatus', file: 'image', label: '公告图片' }, + + { type: 'input', key: 'title', label: '通知标题', props: { maxlength: '20', placeholder: '请输入通知标题', clearable: true }}, + { type: 'select', key: 'source', label: '通知来源', props: { options: NOTICE_SOURCE, placeholder: '请选择通知来源' }}, + + { type: 'radio', key: 'status', label: '通知状态', options: ADVERTISING_STATUS }, + { type: 'input', key: 'url', label: '外部地址', props: { maxlength: '20', placeholder: '请输入外部地址', clearable: true }}, + + { type: 'input', key: 'guide', label: '公告摘要', props: { maxlength: '20', placeholder: '请输入公告摘要', clearable: true }}, + + { type: 'editor', key: 'content', label: '通知内容', props: { height: 300 }} + ] +}) + diff --git a/src/views/setting/notice/tools/search.js b/src/views/setting/notice/tools/search.js new file mode 100644 index 0000000..ae211af --- /dev/null +++ b/src/views/setting/notice/tools/search.js @@ -0,0 +1,14 @@ +import { reactive } from 'vue' + +const data = reactive([ + { + label: '通知标题', + key: 'title', + props: { + placeholder: '请输入通知标题' + } + } +]) + +export default data + diff --git a/src/views/setting/notice/tools/table.js b/src/views/setting/notice/tools/table.js new file mode 100644 index 0000000..da8c390 --- /dev/null +++ b/src/views/setting/notice/tools/table.js @@ -0,0 +1,234 @@ +import { h, ref, reactive } from 'vue' +import TableImage from '@/components/DataTable/tools/Image.vue' +import TableTags from '@/components/DataTable/tools/Tags.vue' +import TableSwitch from '@/components/DataTable/tools/Switch.vue' +import TableAction from '@/components/DataTable/tools/Action.vue' +import { NOTICE_SOURCE } from '@/utils/dictionary.js' +import { noticeDelete, isTopUpdate, statusUpdate } from '@/api/setting/notice.js' + +/* 注册table */ +const tableRef = ref() +const searchParams = ref() + +function handleSearch(params) { + searchParams.value = { ...params } + tableRef.value.reFetch({ searchParams }) +} + +/** + * @description: 获取数据及操作 + * @param {*} row 单行数据 + * @param {*} type 操作类型 create:创建,preview:预览,edit:编辑 + * @return {*} + */ +function getRowData(row, type) { + data.rowData = type === 'create' ? { pid: row.id } : row + data.modalType = type + data.modalShow = true +} + +// 删除方法 +function deleteData(id) { + noticeDelete(id) + .then((res) => { + if (res.code === 0) { + handleSearch() + } + }) + .catch((e) => { + console.log(e) + }) +} + +/** + * @description: 改变状态 + * @param {*} row 选中数据 + * @return {*} + */ +function handleIsTopChange(row) { + isTopUpdate({ id: row.data.id, isTop: row.value }) + .then((res) => { + if (res.code === 0) { + handleSearch() + } + }) + .catch((e) => { + console.log(e) + }) +} + +/** + * @description: 改变状态 + * @param {*} row 选中数据 + * @return {*} + */ +function handleStatusChange(row) { + statusUpdate({ id: row.data.id, status: row.value }) + .then((res) => { + if (res.code === 0) { + handleSearch() + } + }) + .catch((e) => { + console.log(e) + }) +} + +const data = reactive({ + tableRef, + searchParams, + rowData: {}, + modalType: 'create', + modalShow: false, + handleSearch, + + columns: [ + { + type: 'selection' + }, + { + title: '编号', + key: 'key', + render: (_, index) => { + return `${index + 1}` + }, + align: 'center', + width: 50 + }, + { + title: '通知标题', + key: 'title', + align: 'center', + ellipsis: { + tooltip: true + }, + width: 500 + }, + { + title: '公告图片', + key: 'image', + render(row) { + return h(TableImage, { + images: { + width: 36, + height: 36, + src: row.image + } + }) + }, + align: 'center', + width: 100 + }, + { + title: '通知来源', + key: 'source', + align: 'center', + width: 100, + render(row) { + return h(TableTags, { + data: row.source, + filters: NOTICE_SOURCE, + tags: { + bordered: true + } + }) + } + }, + { + title: '是否置顶', + key: 'isTop', + align: 'center', + width: 100, + render(row) { + return h(TableSwitch, { + data: { id: row.id, isTop: row.isTop }, + rowKey: 'isTop', + checkedValue: 1, + uncheckedValue: 2, + onChange: handleIsTopChange.bind(row) + }) + } + }, + { + title: '状态', + key: 'status', + align: 'center', + width: 100, + render(row) { + return h(TableSwitch, { + data: { id: row.id, status: row.status }, + rowKey: 'status', + checkedValue: 1, + uncheckedValue: 2, + onChange: handleStatusChange.bind(row) + }) + } + }, + { + title: '浏览量', + key: 'browse', + align: 'center', + width: 100 + }, + { + title: '创建时间', + key: 'createTime', + align: 'center', + width: 200 + }, + { + title: '更新时间', + key: 'updateTime', + align: 'center', + width: 200 + }, + { + title: '操作', + align: 'center', + width: 150, + fixed: 'right', + render(row) { + return h(TableAction, { + actions: [ + // { + // label: '查看', + // type: 'button', + // props: { + // type: 'primary', + // text: true, + // onClick: getRowData.bind(null, row, 'preview') + // }, + // auth: 'basic_list' + // }, + { + label: '修改', + type: 'button', + props: { + type: 'primary', + text: true, + onClick: getRowData.bind(null, row, 'update') + }, + auth: 'basic_list' + }, + { + label: '删除', + type: 'popconfirm', + auth: 'basic_list', + tip: '确定删除这条数据吗?', + props: { + onPositiveClick: deleteData.bind(null, [row.id]) + }, + ButtonProps: { + text: true, + type: 'primary' + } + } + ], + align: 'center' + }) + } + } + ] +}) + +export default data