Parcourir la source

新增横幅模块

tags/v1.0.0
余菲 il y a 2 ans
Parent
révision
8aa4534a3c
6 fichiers modifiés avec 350 ajouts et 4 suppressions
  1. +1
    -1
      .env.localhost
  2. +5
    -2
      src/utils/ui/theme.js
  3. +145
    -0
      src/views/system-manage/banner-manage/BannerModal.vue
  4. +47
    -1
      src/views/system-manage/banner-manage/index.vue
  5. +19
    -0
      src/views/system-manage/banner-manage/tool/search.js
  6. +133
    -0
      src/views/system-manage/banner-manage/tool/table.js

+ 1
- 1
.env.localhost Voir le fichier

@@ -5,7 +5,7 @@ VITE_PUBLIC_PATH = '/'
VITE_APP_USE_MOCK = false

# proxy
VITE_PROXY = [["/api-local","http://127.0.0.1:8002/api"],["/api-mock","http://127.0.0.1:8003"]]
VITE_PROXY = [["/api-local","http://127.0.0.1:8002"],["/api-mock","http://127.0.0.1:8003"]]

# base api
VITE_APP_GLOB_BASE_API = '/api-local'

+ 5
- 2
src/utils/ui/theme.js Voir le fichier

@@ -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 = {

+ 145
- 0
src/views/system-manage/banner-manage/BannerModal.vue Voir le fichier

@@ -0,0 +1,145 @@
<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 } from 'vue'
import Modal from '@/components/Modal/index.vue'
import UploadOss from '@/components/UploadOss/index.vue'
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: props.cover,
rules: {
cover: [{ required: true, message: '请选择横幅图片', type: 'string', trigger: 'blur' }]
}
})

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() {
console.log('dadasdadsadadsd')
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
}
// if (params.id) {
// /* 编辑 */
// editUser(params)
// .then(res => {
// if (res.code === 0) {
// emit('reload')
// handleClose()
// }
// })
// } else {
// /* 新增 */
// addUser(params)
// .then(res => {
// if (res.code === 0) {
// emit('reload')
// handleClose()
// }
// })
// }
} else {
$message.error('图片上传失败,请稍后重试')
}
})
console.log(data.form)
handleClose()
} else {
$message.error('请完善必填信息')
}
})
}

/* 关闭弹窗 */
const handleClose = () => {
emit('update:visible', false)
}

return {
...toRefs(data),
getModalOptions,
handleUploadStatus,
handleConfirm,
handleClose
}
}
})
</script>

+ 47
- 1
src/views/system-manage/banner-manage/index.vue Voir le fichier

@@ -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"
:data="tableData"
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 { getUserList } from '@/api/system/user/index.js'
export default {
name: 'BannerManage',
components: { dataTable, BannerModal },
setup() {
const data = reactive({
...toRefs(table),
tableData: [{ id: 1, cover: 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcT-xFulkfbTwoQrYR8QcYal2UILdfr5C--enA&usqp=CAU', sort: 1 }]
})
// const loadDataTable = async(res) => {
// const _params = {
// ...unref(data.searchParams),
// ...res
// }
// return await getUserList(_params)
// }

// 新增
function handleModal() {
data.rowData = null
data.modalType = 'create'
data.modalShow = true
}

return {
...toRefs(data),
handleModal
}
}
}


+ 19
- 0
src/views/system-manage/banner-manage/tool/search.js Voir le fichier

@@ -0,0 +1,19 @@
import { reactive } from 'vue'
export const search = reactive({
search: [
{
label: '用户账号',
key: 'username',
props: {
placeholder: '请输入用户账号'
}
},
{
label: '用户姓名',
key: 'realname',
props: {
placeholder: '请输入用户姓名'
}
}
]
})

+ 133
- 0
src/views/system-manage/banner-manage/tool/table.js Voir le fichier

@@ -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 { deleteUser } from '@/api/system/user/index.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) {
deleteUser(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: 'avatar',
align: 'center',
render(row) {
return h(TableImage, {
images: {
width: 36,
height: 36,
src: row.avatar
}
})
}
},
{
title: '上传人',
key: 'updateName',
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

Chargement…
Annuler
Enregistrer