@@ -0,0 +1,47 @@ | |||
import { defAxios as request } from '@/utils/http' | |||
/** | |||
* 获取云盒列表(分页) | |||
* @param {Object} | |||
* @returns | |||
*/ | |||
export function bannerPage(params) { | |||
return request({ | |||
url: '/pilotAd/index', | |||
method: 'get', | |||
params | |||
}) | |||
} | |||
/** | |||
* 创建盒子 | |||
* @returns | |||
*/ | |||
export function bannerCreate(data) { | |||
return request({ | |||
url: '/pilotAd/add', | |||
method: 'post', | |||
data | |||
}) | |||
} | |||
/** | |||
* 编辑盒子 | |||
* @returns | |||
*/ | |||
export function bannerUpdate(data) { | |||
return request({ | |||
url: '/pilotAd/edit', | |||
method: 'put', | |||
data | |||
}) | |||
} | |||
/** | |||
* 删除盒子 | |||
* @returns | |||
*/ | |||
export function bannerDelete(ids) { | |||
return request({ | |||
url: `/pilotAd/delete/${ids}`, | |||
method: 'delete' | |||
}) | |||
} |
@@ -1,7 +1,10 @@ | |||
const common = { | |||
primaryColor: '#36ad6a', | |||
primaryColor: 'rgba(24, 144, 255, 1)', | |||
textColor: 'rgba(51, 51, 51, 1)', | |||
whiteColor: 'rgba(255, 255, 255, 1)' | |||
whiteColor: 'rgba(255, 255, 255, 1)', | |||
errorColor: '#ff3333', | |||
primaryColorHover: 'rgba(24, 144, 255, 0.8)', | |||
primaryColorPressed: 'rgba(24, 144, 255, 1)' | |||
} | |||
const themeOverrides = { |
@@ -0,0 +1,158 @@ | |||
<template> | |||
<Modal | |||
:options="getModalOptions" | |||
:on-positive-click="handleConfirm" | |||
:on-negative-click="handleClose" | |||
:on-close="handleClose" | |||
> | |||
<template #Context> | |||
<n-form | |||
ref="formRef" | |||
:model="form" | |||
:rules="rules" | |||
:label-width="80" | |||
label-placement="left" | |||
require-mark-placement="left" | |||
> | |||
<n-form-item label="横幅图片" path="cover"> | |||
<UploadOss ref="ossRefs" :default-list="initUpload" @upload-status="handleUploadStatus" /> | |||
</n-form-item> | |||
<!-- <n-form-item label="排序" path="sort"> | |||
<n-input-number v-model:value="form.sort" clearable /> | |||
</n-form-item> --> | |||
</n-form> | |||
</template> | |||
</Modal> | |||
</template> | |||
<script> | |||
import { defineComponent, ref, reactive, computed, toRefs, watch } from 'vue' | |||
import Modal from '@/components/Modal/index.vue' | |||
import UploadOss from '@/components/UploadOss/index.vue' | |||
import { bannerCreate, bannerUpdate } from '@/api/system/banner.js' | |||
export default defineComponent({ | |||
name: 'BannerModal', | |||
components: { Modal, UploadOss }, | |||
props: { | |||
visible: { | |||
type: Boolean, | |||
default: false | |||
}, | |||
type: { | |||
type: String, | |||
default: 'create' | |||
}, | |||
data: { | |||
type: Object, | |||
default: () => null | |||
} | |||
}, | |||
emits: { | |||
'update:visible': null, | |||
'reload': null | |||
}, | |||
setup(props, { emit }) { | |||
const MODAL_TYPE = { | |||
'create': '新建横幅', | |||
'preview': '横幅详情', | |||
'update': '编辑横幅' | |||
} | |||
const data = reactive({ | |||
form: { ...props.data }, | |||
initUpload: '', | |||
rules: { | |||
cover: [{ required: true, message: '请选择横幅图片', type: 'string', trigger: 'blur' }] | |||
} | |||
}) | |||
watch(() => props.visible, (value) => { | |||
if (value) { | |||
if (props.data) { | |||
data.initUpload = props.data.cover | |||
} | |||
} else { | |||
data.initUpload = '' | |||
} | |||
}) | |||
const getModalOptions = computed(() => { | |||
return { | |||
show: props.visible, | |||
title: MODAL_TYPE[props.type], | |||
negativeText: '取消', | |||
positiveText: '确认' | |||
} | |||
}) | |||
function handleUploadStatus(status) { | |||
data.form.cover = status | |||
} | |||
const formRef = ref() | |||
const ossRefs = ref() | |||
function handleConfirm() { | |||
if (props.type !== 'preview') { | |||
formRef.value?.validate((errors) => { | |||
if (!errors) { | |||
const uploads = ossRefs.value.map((item, index) => { | |||
return item.startUpload() | |||
}) | |||
Promise.all(uploads) | |||
.then(response => { | |||
const isError = response.map((item) => { | |||
return item.includes('error') | |||
}) | |||
if (!isError.includes(true)) { | |||
const imageStr = response.join() | |||
const params = { | |||
...data.form, | |||
cover: imageStr[0] | |||
} | |||
if (params.id) { | |||
/* 编辑 */ | |||
bannerUpdate(params) | |||
.then(res => { | |||
if (res.code === 0) { | |||
emit('reload') | |||
handleClose() | |||
} | |||
}) | |||
} else { | |||
/* 新增 */ | |||
bannerCreate(params) | |||
.then(res => { | |||
if (res.code === 0) { | |||
emit('reload') | |||
handleClose() | |||
} | |||
}) | |||
} | |||
} else { | |||
$message.error('图片上传失败,请稍后重试') | |||
} | |||
}) | |||
handleClose() | |||
} else { | |||
$message.error('请完善必填信息') | |||
} | |||
}) | |||
} else { | |||
handleClose() | |||
} | |||
} | |||
/* 关闭弹窗 */ | |||
const handleClose = () => { | |||
emit('update:visible', false) | |||
} | |||
return { | |||
...toRefs(data), | |||
getModalOptions, | |||
handleUploadStatus, | |||
handleConfirm, | |||
handleClose | |||
} | |||
} | |||
}) | |||
</script> |
@@ -1,14 +1,60 @@ | |||
<template> | |||
<div> | |||
移动端横幅管理 | |||
<n-card> | |||
<!-- <headSearch :info="search" @search="handleSearch" @reset="handleSearch" /> --> | |||
<data-table | |||
ref="tableRef" | |||
:columns="columns" | |||
:row-key="(row) => row.id" | |||
:request="loadDataTable" | |||
size="large" | |||
@update:checked-row-keys="handleCheck" | |||
> | |||
<template #tableTitle> | |||
<n-button type="primary" @click="handleModal"> 新建 </n-button> | |||
</template> | |||
</data-table> | |||
</n-card> | |||
</div> | |||
<!-- 新增、编辑弹窗 --> | |||
<BannerModal v-if="modalShow" v-model:visible="modalShow" :type="modalType" :data="rowData" @reload="handleSearch" /> | |||
</template> | |||
<script> | |||
import { unref, toRefs, reactive } from 'vue' | |||
// import headSearch from '@/components/Search/index.vue' | |||
import table from './tool/table.js' | |||
import dataTable from '@/components/DataTable/index.vue' | |||
import BannerModal from './BannerModal.vue' | |||
import { bannerPage } from '@/api/system/banner.js' | |||
export default { | |||
name: 'BannerManage', | |||
components: { dataTable, BannerModal }, | |||
setup() { | |||
const data = reactive({ | |||
...toRefs(table) | |||
}) | |||
const loadDataTable = async(res) => { | |||
const _params = { | |||
...unref(data.searchParams), | |||
...res | |||
} | |||
return await bannerPage(_params) | |||
} | |||
// 新增 | |||
function handleModal() { | |||
data.rowData = null | |||
data.modalType = 'create' | |||
data.modalShow = true | |||
} | |||
return { | |||
...toRefs(data), | |||
loadDataTable, | |||
handleModal | |||
} | |||
} | |||
} | |||
@@ -0,0 +1,19 @@ | |||
import { reactive } from 'vue' | |||
export const search = reactive({ | |||
search: [ | |||
{ | |||
label: '用户账号', | |||
key: 'username', | |||
props: { | |||
placeholder: '请输入用户账号' | |||
} | |||
}, | |||
{ | |||
label: '用户姓名', | |||
key: 'realname', | |||
props: { | |||
placeholder: '请输入用户姓名' | |||
} | |||
} | |||
] | |||
}) |
@@ -0,0 +1,133 @@ | |||
import { h, ref, reactive } from 'vue' | |||
import TableImage from '@/components/DataTable/tools/Image.vue' | |||
import TableAction from '@/components/DataTable/tools/Action.vue' | |||
import { bannerDelete } from '@/api/system/banner.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 = row | |||
data.modalType = type | |||
data.modalShow = true | |||
} | |||
/** | |||
* @description: 删除用户接口 | |||
* @param {Array} ids 用户id集合 | |||
* @return {*} | |||
*/ | |||
function deleteData(ids) { | |||
bannerDelete(ids).then((res) => { | |||
if (res.code === 0) { | |||
handleSearch() | |||
} | |||
}).catch(e => { | |||
console.log(e) | |||
}) | |||
} | |||
const data = reactive({ | |||
tableRef, | |||
searchParams, | |||
rowData: {}, | |||
modalType: 'create', | |||
modalShow: false, | |||
handleSearch, | |||
deleteData, | |||
columns: [ | |||
{ | |||
title: '序号', | |||
key: 'key', | |||
render: (_, index) => { | |||
return `${index + 1}` | |||
}, | |||
align: 'center' | |||
}, | |||
{ | |||
title: '横幅图片', | |||
key: 'cover', | |||
align: 'center', | |||
render(row) { | |||
return h(TableImage, { | |||
images: { | |||
width: 36, | |||
height: 36, | |||
src: row.cover | |||
} | |||
}) | |||
} | |||
}, | |||
{ | |||
title: '上传人', | |||
key: 'updateUser', | |||
align: 'center', | |||
width: 160 | |||
}, | |||
{ | |||
title: '上传时间', | |||
key: 'updateTime', | |||
align: 'center', | |||
width: 160 | |||
}, | |||
{ | |||
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: 'error' | |||
} | |||
} | |||
], | |||
align: 'center' | |||
}) | |||
} | |||
} | |||
] | |||
}) | |||
export default data |