feat(advert): 广告管理页面增删改查

This commit is contained in:
有来技术
2021-12-26 12:56:21 +08:00
parent 42decdb662
commit 811a1ee652
5 changed files with 419 additions and 33 deletions

View File

@@ -0,0 +1,314 @@
<template>
<div class="app-container">
<!-- 搜索表单 -->
<el-form
ref="queryForm"
:model="queryParams"
:inline="true"
size="mini"
>
<el-form-item>
<el-button type="success" :icon="Plus" @click="handleAdd">新增</el-button>
<el-button type="danger" :icon="Delete" :disabled="multiple" @click="handleDelete">删除</el-button>
</el-form-item>
<el-form-item>
<el-input
v-model="queryParams.name"
placeholder="广告名称"
clearable
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item>
<el-button type="primary" :icon="Search" @click="handleQuery">搜索</el-button>
<el-button :icon="Refresh" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<el-table
ref="dataTable"
v-loading="loading"
:data="pageList"
@selection-change="handleSelectionChange"
border
>
<el-table-column type="selection" min-width="5" align="center"/>
<el-table-column type="index" label="序号" width="50" align="center"/>
<el-table-column prop="title" label="广告标题" min-width="10"/>
<el-table-column label="广告图片" min-width="10">
<template #default="scope">
<el-popover
placement="right"
title=""
trigger="hover">
<img :src="scope.row.picUrl"/>
<img slot="reference"
:src="scope.row.picUrl"
:alt="scope.row.picUrl"
style="max-height: 60px;max-width: 60px"
>
</el-popover>
</template>
</el-table-column>
<el-table-column prop="beginDate" label="开始时间" min-width="10"/>
<el-table-column prop="endTime" label="到期时间" min-width="10"/>
<el-table-column prop="status" label="状态" min-width="6">
<template #default="scope">
<el-tag v-if="scope.row.status===1" type="success" size="mini">开启</el-tag>
<el-tag v-else type="info" size="mini">关闭</el-tag>
</template>
</el-table-column>
<el-table-column prop="sort" label="排序" min-width="6"/>
<el-table-column label="操作" align="center" min-width="10" class-name="small-padding fixed-width">
<template #default="scope">
<el-button
type="primary"
:icon="Edit"
size="mini"
circle
plain
@click.stop="handleUpdate(scope.row)"
/>
<el-button
type="danger"
:icon="Delete"
size="mini"
circle
plain
@click.stop="handleDelete(scope.row)"
/>
</template>
</el-table-column>
</el-table>
<!-- 分页工具条 -->
<pagination
v-show="total>0"
:total="total"
v-model:page="queryParams.pageNum"
v-model:limit="queryParams.pageSize"
@pagination="handleQuery"
/>
<!-- 表单弹窗 -->
<el-dialog
:title="dialog.title"
v-model="dialog.visible"
width="700px"
>
<el-form
ref="dataForm"
:model="formData"
:rules="rules"
label-width="100px"
>
<el-form-item label="广告标题" required prop="title">
<el-input v-model="formData.title"/>
</el-form-item>
<el-form-item label="有效期" required prop="beginTime">
<el-date-picker
v-model="formData.beginTime"
value-format="yyyy-MM-dd"
placeholder="开始日期"
/>
~
<el-date-picker
v-model="formData.endTime"
value-format="yyyy-MM-dd"
placeholder="结束日期"
/>
</el-form-item>
<el-form-item label="广告图片" prop="picUrl">
<single-upload v-model="formData.picUrl"/>
</el-form-item>
<el-form-item label="排序" prop="sort">
<el-input v-model="formData.sort" style="width: 200px"/>
</el-form-item>
<el-form-item label="状态" prop="status">
<el-radio-group v-model="formData.status">
<el-radio :label="1">开启</el-radio>
<el-radio :label="0">关闭</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="跳转链接" prop="url">
<el-input v-model="formData.url"/>
</el-form-item>
<el-form-item label="备注" prop="remark">
<el-input type="textarea" v-model="formData.remark"/>
</el-form-item>
</el-form>
<template #footer>
<div class="dialog-footer">
<el-button type="primary" @click="submitForm"> </el-button>
<el-button @click="cancel"> </el-button>
</div>
</template>
</el-dialog>
</div>
</template>
<script setup lang="ts">
import {listAdvertsWithPage, getAdvertDetail, updateAdvert, addAdvert, deleteAdverts} from '@/api/sms/advert'
import SingleUpload from "@/components/Upload/SingleUpload.vue";
import {onMounted, reactive, ref, toRefs, unref} from "vue";
import {ElForm, ElMessage, ElMessageBox} from "element-plus";
import {Search, Plus, Edit, Refresh, Delete} from '@element-plus/icons'
const dataForm = ref(ElForm) // 属性名必须和元素的ref属性值一致
const state = reactive({
loading: true,
// 选中ID数组
ids: [],
// 非单个禁用
single: true,
// 非多个禁用
multiple: true,
queryParams: {
pageNum: 1,
pageSize: 10,
title: undefined
},
pageList: [],
total: 0,
dialog: {
title: '',
visible: false
},
formData: {
id: undefined,
title: '',
picUrl: '',
beginTime: undefined,
endTime: undefined,
status: 1,
sort: 100,
url: undefined,
remark: undefined
},
rules: {
name: [
{required: true, message: '请输入广告名称', trigger: 'blur'}
],
pic: [
{required: true, message: '请上传广告图片', trigger: 'blur'}
]
}
})
const {loading, single, multiple, queryParams, pageList, total, dialog, formData, rules} = toRefs(state)
function handleQuery() {
state.loading = true
listAdvertsWithPage(state.queryParams).then(response => {
const {data, total} = response as any
state.pageList = data
state.total = total
state.loading = false
})
}
function resetQuery() {
state.queryParams = {
pageNum: 1,
pageSize: 10,
title: undefined
}
handleQuery()
}
function handleSelectionChange(selection: any) {
state.ids = selection.map((item: any) => item.id)
state.single = selection.length !== 1
state.multiple = !selection.length
}
function handleAdd() {
resetForm()
state.dialog = {
title: '添加广告',
visible: true
}
}
function handleUpdate(row: any) {
resetForm()
state.dialog = {
title: '修改广告',
visible: true,
}
const advertId = row.id || state.ids
getAdvertDetail(advertId).then((response) => {
state.formData = response.data
})
}
function submitForm() {
const form = unref(dataForm)
form.validate((valid: any) => {
if (valid) {
if (state.formData.id) {
updateAdvert(state.formData.id as any, state.formData).then(response => {
ElMessage.success('修改成功')
state.dialog.visible = false
handleQuery()
})
} else {
addAdvert(state.formData).then(response => {
ElMessage.success('新增成功')
state.dialog.visible = false
handleQuery()
})
}
}
})
}
function resetForm() {
state.formData = {
id: undefined,
title: '',
picUrl: '',
beginTime: undefined,
endTime: undefined,
status: 1,
sort: 100,
url: undefined,
remark: undefined
}
}
function cancel() {
resetForm()
state.dialog.visible = false
}
function handleDelete(row: any) {
const ids = [row.id || state.ids].join(',')
ElMessageBox.confirm('确认删除已选中的数据项?', '警告', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
deleteAdverts(ids).then(() => {
ElMessage.success('删除成功')
handleQuery()
})
}).catch(() =>
ElMessage.info('已取消删除')
)
}
onMounted(() => {
handleQuery()
})
</script>

View File

@@ -145,7 +145,7 @@ const {proxy}: any = getCurrentInstance();
const props = defineProps({
menuId: {
type: String,
default: undefined
default: ''
},
menuName: {
type: String,
@@ -158,7 +158,6 @@ watch(() => props.menuId as any, (newVal, oldVal) => {
handleQuery()
})
const state = reactive({
loading: true,
// 选中ID数组
@@ -182,9 +181,9 @@ const state = reactive({
formData: {
id: undefined,
name: undefined,
urlPerm: undefined,
btnPerm: undefined,
menuId: undefined
urlPerm: '',
btnPerm: '',
menuId: ''
},
rules: {
name: [
@@ -332,8 +331,9 @@ function resetForm() {
state.formData = {
id: undefined,
name: undefined,
urlPerm: undefined,
btnPerm: undefined
urlPerm: '',
btnPerm: '',
menuId: ''
}
}

View File

@@ -1,11 +1,11 @@
<template>
<div>
<div class="role-container">
<!-- 搜索表单 -->
<el-form
ref="queryForm"
:model="queryParams"
size="mini"
:inline="true"
size="mini"
>
<el-form-item>
<el-button type="success" :icon="Plus" @click="handleAdd">新增</el-button>
@@ -29,14 +29,14 @@
<!-- 数据表格 -->
<el-table
ref="roleTable"
ref="dataTable"
v-loading="loading"
:data="pageList"
@selection-change="handleSelectionChange"
@row-click="handleRowClick"
border
highlight-current-row
size="mini"
border
>
<el-table-column type="selection" width="55" align="center"/>
<el-table-column label="角色名称" prop="name"/>
@@ -118,14 +118,11 @@
<script setup lang="ts">
import {listRolesWithPage, updateRole, getRoleDetail, addRole, deleteRoles} from '@/api/system/role'
import {defineEmits, defineProps, onMounted, reactive, ref, toRefs, unref} from "vue"
import {add, del, detail, update} from "@api/system/client";
import {ElForm, ElMessage, ElMessageBox} from "element-plus";
import {Search, Plus, Edit, Refresh, Delete} from '@element-plus/icons'
const emit = defineEmits(['roleClick'])
const dataForm = ref(ElForm) // 属性名必须和元素的ref属性值一致
const state = reactive({
loading: true,
// 选中ID数组
@@ -162,7 +159,7 @@ const state = reactive({
}
})
const {loading,single, multiple, queryParams, pageList, total, dialog, formData, rules} = toRefs(state)
const {loading, single, multiple, queryParams, pageList, total, dialog, formData, rules} = toRefs(state)
function handleQuery() {
emit('roleClick', {})
@@ -271,3 +268,9 @@ onMounted(() => {
})
</script>
<style lang="scss" scoped>
.role-container {
width: 100%;
}
</style>