generated from Leo_Ding/web-template
banner图
This commit is contained in:
parent
0b89202de5
commit
b085e15b46
14
src/apis/modules/imgmgt.js
Normal file
14
src/apis/modules/imgmgt.js
Normal file
@ -0,0 +1,14 @@
|
||||
/**
|
||||
* 图片管理接口
|
||||
*/
|
||||
import request from '@/utils/request'
|
||||
// 获取菜单列表
|
||||
export const getDataList = (params) => request.basic.get('/api/v1/banners', params)
|
||||
// 获取菜单条数据
|
||||
export const getMenu = (id) => request.basic.get(`/api/v1/banners/${id}`)
|
||||
// 添加菜单
|
||||
export const createMenu = (params) => request.basic.post('/api/v1/banners', params)
|
||||
// 更新菜单
|
||||
export const updateMenu = (id, params) => request.basic.put(`/api/v1/banners/${id}`, params)
|
||||
// 删除菜单
|
||||
export const delMenu = (id) => request.basic.delete(`/api/v1/banners/${id}`)
|
||||
@ -97,5 +97,6 @@ export default {
|
||||
ycyllvs: '医疗绿色通道',
|
||||
ycparentChild: '亲子权益',
|
||||
ycbirth: '生日礼遇',
|
||||
activityOrder:'活动报名列表'
|
||||
activityOrder:'活动报名列表',
|
||||
banner:'首页轮播图'
|
||||
}
|
||||
|
||||
@ -12,6 +12,17 @@ export default [
|
||||
keepAlive: true,
|
||||
permission: '*',
|
||||
}
|
||||
|
||||
},
|
||||
{
|
||||
path: 'banner/index',
|
||||
name: 'banner',
|
||||
component: 'banner/index.vue',
|
||||
meta: {
|
||||
icon: SolutionOutlined,
|
||||
title: '轮播图列表',
|
||||
isMenu: true,
|
||||
keepAlive: true,
|
||||
permission: '*',
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
183
src/views/banner/components/EditDialog.vue
Normal file
183
src/views/banner/components/EditDialog.vue
Normal file
@ -0,0 +1,183 @@
|
||||
<template>
|
||||
<a-modal :open="modal.open" :title="modal.title" :width="640" :confirm-loading="modal.confirmLoading"
|
||||
:after-close="onAfterClose" :cancel-text="cancelText" :ok-text="okText" @ok="handleOk" @cancel="handleCancel">
|
||||
<a-form ref="formRef" :model="formData" :rules="formRules">
|
||||
<a-card class="mb-8-2">
|
||||
<a-row :gutter="12">
|
||||
<a-col :span="24">
|
||||
<a-form-item :label="'名称'" name="name">
|
||||
<a-input :placeholder="'请输入名称'" v-model:value="formData.name"></a-input>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :span="24">
|
||||
<a-form-item :label="'顺序'" name="sequence">
|
||||
<a-input-number :placeholder="'请输入顺序'" v-model:value="formData.sequence"></a-input-number>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :span="24">
|
||||
<a-form-item :label="'状态'" name="status">
|
||||
<a-radio-group v-model:value="formData.status" :options="[
|
||||
{ label: '启用', value: 'enabled' },
|
||||
{ label: '停用', value: 'disabled' },
|
||||
]"></a-radio-group>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :span="24">
|
||||
<a-form-item :label="'图片'" name="img">
|
||||
<gx-upload v-model="formData.img" accept-types=".jpg,.png,.webp" :fileNumber="1" />
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
</a-row>
|
||||
</a-card>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { cloneDeep } from 'lodash-es'
|
||||
import { ref } from 'vue'
|
||||
import { config } from '@/config'
|
||||
import apis from '@/apis'
|
||||
import { useForm, useModal } from '@/hooks'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import dayjs from 'dayjs'
|
||||
import { spliceUrl } from "@/utils/util.js"
|
||||
const emit = defineEmits(['ok'])
|
||||
const { t } = useI18n() // 解构出t方法
|
||||
const { modal, showModal, hideModal, showLoading, hideLoading } = useModal()
|
||||
const { formRecord, formData, formRef, formRules, resetForm } = useForm()
|
||||
const cancelText = ref(t('button.cancel'))
|
||||
const okText = ref(t('button.confirm'))
|
||||
const rolesValue = ref([])
|
||||
const roles = ref([])
|
||||
const img = ref('')
|
||||
formRules.value = {
|
||||
name: { required: true, message: '请输入名称' },
|
||||
status: [{ required: true, message: '请选择状态', trigger: 'change' }],
|
||||
sequence: [{ required: true, message: '请选择顺序', trigger: 'change' }],
|
||||
img: [{ required: true, message: '请上传图片', trigger: 'change' }],
|
||||
}
|
||||
/**
|
||||
* 新建
|
||||
*/
|
||||
function handleCreate() {
|
||||
showModal({
|
||||
type: 'create',
|
||||
// 80对应about
|
||||
title: '添加',
|
||||
})
|
||||
formData.value.status = 'enabled'
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*/
|
||||
async function handleEdit(record = {}) {
|
||||
showModal({
|
||||
type: 'edit',
|
||||
title: t('pages.system.user.edit'),
|
||||
})
|
||||
const { data, success } = await apis.imgmgt.getMenu(record.id).catch()
|
||||
if (!success) {
|
||||
hideModal()
|
||||
return
|
||||
}
|
||||
formData.value = { ...data }
|
||||
formData.value.pushAt=dayjs(data.pushAt)
|
||||
formData.value.img=data.img?[config('http.apiBasic') + data.img]:[]
|
||||
}
|
||||
|
||||
/**
|
||||
* 确定
|
||||
*/
|
||||
function handleOk() {
|
||||
formRef.value.validateFields().then(async (values) => {
|
||||
console.log(values)
|
||||
try {
|
||||
showLoading()
|
||||
const params = {
|
||||
...values,
|
||||
img: formData.value.img?spliceUrl(formData.value.img[0]):'',
|
||||
}
|
||||
let result = null
|
||||
console.log(modal.value.type)
|
||||
switch (modal.value.type) {
|
||||
case 'create':
|
||||
result = await apis.imgmgt.createMenu(params).catch(() => {
|
||||
throw new Error()
|
||||
})
|
||||
break
|
||||
case 'edit':
|
||||
// result = await apis.imgmgt.updateMenu(formData.value.id, params).catch(() => {
|
||||
result = await apis.imgmgt.updateMenu(formData.value.id, params).catch(() => {
|
||||
throw new Error()
|
||||
})
|
||||
break
|
||||
}
|
||||
hideLoading()
|
||||
if (config('http.code.success') === result?.success) {
|
||||
hideModal()
|
||||
emit('ok')
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
hideLoading()
|
||||
}
|
||||
})
|
||||
.catch((e) => {
|
||||
console.log(e)
|
||||
hideLoading()
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 对权限组 过数据格式
|
||||
*/
|
||||
function formatArr(data, type = '') {
|
||||
const rolesArr = []
|
||||
data.forEach((item) => {
|
||||
roles.value.forEach((r) => {
|
||||
if (type === 'edit') {
|
||||
if (item.role_id === r.value) {
|
||||
rolesArr.push({
|
||||
value: item.role_id,
|
||||
label: r.label,
|
||||
})
|
||||
return
|
||||
}
|
||||
} else if (r.value === item) {
|
||||
rolesArr.push({
|
||||
role_id: item,
|
||||
role_name: r.label,
|
||||
})
|
||||
return
|
||||
}
|
||||
})
|
||||
})
|
||||
return rolesArr
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消
|
||||
*/
|
||||
function handleCancel() {
|
||||
img.value = ''
|
||||
hideModal()
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭后
|
||||
*/
|
||||
function onAfterClose() {
|
||||
resetForm()
|
||||
hideLoading()
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
handleCreate,
|
||||
handleEdit,
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped></style>
|
||||
169
src/views/banner/index.vue
Normal file
169
src/views/banner/index.vue
Normal file
@ -0,0 +1,169 @@
|
||||
<template>
|
||||
<a-row :gutter="8" :wrap="false">
|
||||
<a-col flex="auto">
|
||||
<a-card type="flex">
|
||||
<x-action-bar class="mb-8-2">
|
||||
<a-button type="primary" @click="$refs.editDialogRef.handleCreate()">
|
||||
<template #icon>
|
||||
<plus-outlined></plus-outlined>
|
||||
</template>
|
||||
新增
|
||||
</a-button>
|
||||
</x-action-bar>
|
||||
<a-table :columns="columns" :data-source="listData" bordered="true" :loading="loading"
|
||||
:pagination="paginationState" :scroll="{ x: 1000 }" @change="onTableChange">
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="'img' === column.dataIndex">
|
||||
<!-- <a-image :width="60" :src="record.img || $imageErr.imgErr" />-->
|
||||
<a-image :width="60" :src="config('http.apiBasic') + record.img || $imageErr.imgErr" />
|
||||
</template>
|
||||
<template v-if="column.dataIndex === 'name'">
|
||||
<a-tooltip :title="record.name">
|
||||
<span>{{ record.name }}</span>
|
||||
</a-tooltip>
|
||||
</template>
|
||||
|
||||
<template v-if="'status' === column.dataIndex">
|
||||
<a-tag v-if="record.status === 'enabled'" :color="'green'">启用</a-tag>
|
||||
<a-tag v-if="record.status === 'disabled'" :color="'red'">停用</a-tag>
|
||||
</template>
|
||||
<template v-if="'action' === column.key">
|
||||
<x-action-button @click="$refs.editDialogRef.handleEdit(record)">
|
||||
<a-tooltip>
|
||||
<template #title> {{ $t('pages.system.user.edit') }}</template>
|
||||
<edit-outlined /> </a-tooltip></x-action-button>
|
||||
<x-action-button @click="handleDelete(record)">
|
||||
<a-tooltip>
|
||||
<template #title>{{ $t('pages.system.delete') }}</template>
|
||||
<delete-outlined style="color: #ff4d4f" /> </a-tooltip></x-action-button>
|
||||
</template>
|
||||
</template>
|
||||
</a-table>
|
||||
</a-card>
|
||||
</a-col>
|
||||
</a-row>
|
||||
|
||||
<edit-dialog ref="editDialogRef" @ok="onOk"></edit-dialog>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { message, Modal } from 'ant-design-vue'
|
||||
import { ref } from 'vue'
|
||||
import apis from '@/apis'
|
||||
import { formatUtcDateTime } from '@/utils/util'
|
||||
import { config } from '@/config'
|
||||
import { statusUserTypeEnum } from '@/enums/system'
|
||||
import { usePagination } from '@/hooks'
|
||||
|
||||
import EditDialog from './components/EditDialog.vue'
|
||||
import { PlusOutlined, EditOutlined, DeleteOutlined } from '@ant-design/icons-vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { delMenu, getDataList } from '@/apis/modules/imgmgt'
|
||||
defineOptions({
|
||||
name: 'banner',
|
||||
})
|
||||
const { t } = useI18n() // 解构出t方法
|
||||
const columns = [
|
||||
{ title: '图片', dataIndex: 'img', width: 100, align: 'center' },
|
||||
{ title: '名称', dataIndex: 'name', key: 'name' },
|
||||
{ title: '状态', dataIndex: 'status', width: 120, align: 'center' },
|
||||
{ title: '顺序', dataIndex: 'sequence', width: 100, align: 'center' },
|
||||
{ title: t('button.action'), key: 'action', fixed: 'right', width: 100, align: 'center' },
|
||||
]
|
||||
|
||||
const { listData, loading, showLoading, hideLoading, paginationState, resetPagination, searchFormData } =
|
||||
usePagination()
|
||||
|
||||
const editDialogRef = ref()
|
||||
getPageList()
|
||||
/**
|
||||
* 获取用户列表
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
|
||||
async function getPageList() {
|
||||
try {
|
||||
showLoading()
|
||||
const { pageSize, current } = paginationState
|
||||
const { success, data, total } = await apis.imgmgt
|
||||
.getDataList({
|
||||
pageSize,
|
||||
current:current,
|
||||
...searchFormData.value,
|
||||
})
|
||||
.catch(() => {
|
||||
throw new Error()
|
||||
})
|
||||
hideLoading()
|
||||
if (config('http.code.success') === success) {
|
||||
//筛选type的值80对应about
|
||||
listData.value = data
|
||||
paginationState.total = total
|
||||
}
|
||||
} catch (error) {
|
||||
hideLoading()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
function handleDelete({ id }) {
|
||||
Modal.confirm({
|
||||
title: t('pages.system.user.delTip'),
|
||||
content: t('button.confirm'),
|
||||
okText: t('button.confirm'),
|
||||
onOk: () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
; (async () => {
|
||||
try {
|
||||
const { success } = await apis.imgmgt.delMenu(id).catch(() => {
|
||||
throw new Error()
|
||||
})
|
||||
if (config('http.code.success') === success) {
|
||||
resolve()
|
||||
message.success(t('component.message.success.delete'))
|
||||
await getPageList()
|
||||
}
|
||||
} catch (error) {
|
||||
reject()
|
||||
}
|
||||
})()
|
||||
})
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页
|
||||
*/
|
||||
function onTableChange({ current, pageSize }) {
|
||||
paginationState.current = current
|
||||
paginationState.pageSize = pageSize
|
||||
getPageList()
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索
|
||||
*/
|
||||
function handleSearch() {
|
||||
resetPagination()
|
||||
getPageList()
|
||||
}
|
||||
/**
|
||||
* 重置
|
||||
*/
|
||||
function handleResetSearch() {
|
||||
searchFormData.value = {}
|
||||
resetPagination()
|
||||
getPageList()
|
||||
}
|
||||
/**
|
||||
* 编辑完成
|
||||
*/
|
||||
async function onOk() {
|
||||
await getPageList()
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped></style>
|
||||
Loading…
x
Reference in New Issue
Block a user