完善功能
This commit is contained in:
131
src/views/gallery/carousel/edit.vue
Normal file
131
src/views/gallery/carousel/edit.vue
Normal file
@ -0,0 +1,131 @@
|
||||
<template>
|
||||
<div class="edit-popup">
|
||||
<popup ref="popupRef" :title="popupTitle" :async="true" width="550px" @confirm="handleSubmit"
|
||||
@close="handleClose">
|
||||
<el-form ref="formRef" :model="formData" label-width="90px" :rules="formRules">
|
||||
<el-form-item label="标题" prop="title">
|
||||
<el-input v-model="formData.title" clearable placeholder="请输入标题" />
|
||||
</el-form-item>
|
||||
<el-form-item label="图片地址" prop="address">
|
||||
<material-picker v-model="formData.address" :limit="1" />
|
||||
</el-form-item>
|
||||
<el-form-item label="状态" prop="status">
|
||||
<el-select v-model="formData.status" clearable placeholder="请选择状态">
|
||||
<el-option label="启用" :value="1" />
|
||||
<el-option label="禁用" :value="0" />
|
||||
</el-select>
|
||||
<!-- <el-input v-model="formData.status" clearable placeholder="请输入状态" /> -->
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</popup>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup name="carouselEdit">
|
||||
import type { FormInstance } from 'element-plus'
|
||||
import Popup from '@/components/popup/index.vue'
|
||||
import { apiCarouselAdd, apiCarouselEdit, apiCarouselDetail } from '@/api/carousel'
|
||||
import { removeImageUrlPrefix } from '@/utils/util'
|
||||
import type { PropType } from 'vue'
|
||||
|
||||
defineProps({
|
||||
dictData: {
|
||||
type: Object as PropType<Record<string, any[]>>,
|
||||
default: () => ({})
|
||||
}
|
||||
})
|
||||
const emit = defineEmits(['success', 'close'])
|
||||
const formRef = shallowRef<FormInstance>()
|
||||
const popupRef = shallowRef<InstanceType<typeof Popup>>()
|
||||
const mode = ref('add')
|
||||
|
||||
|
||||
// 弹窗标题
|
||||
const popupTitle = computed(() => {
|
||||
return mode.value == 'edit' ? '编辑轮播图' : '新增轮播图'
|
||||
})
|
||||
|
||||
// 表单数据
|
||||
const formData = reactive({
|
||||
id: '',
|
||||
title: '',
|
||||
address: '',
|
||||
status: '',
|
||||
})
|
||||
|
||||
|
||||
// 表单验证
|
||||
const formRules = reactive<any>({
|
||||
title: [
|
||||
{
|
||||
required: true,
|
||||
message: '请输入标题',
|
||||
trigger: ['blur']
|
||||
}
|
||||
],
|
||||
address: [
|
||||
{
|
||||
required: true,
|
||||
message: '请选择图片地址',
|
||||
trigger: ['change']
|
||||
}
|
||||
],
|
||||
status: [
|
||||
{
|
||||
required: true,
|
||||
message: '请选择状态',
|
||||
trigger: ['change']
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
|
||||
// 获取详情
|
||||
const setFormData = async (data: Record<any, any>) => {
|
||||
for (const key in formData) {
|
||||
if (data[key] != null && data[key] != undefined) {
|
||||
//@ts-ignore
|
||||
formData[key] = data[key]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const getDetail = async (row: Record<string, any>) => {
|
||||
const data = await apiCarouselDetail({
|
||||
id: row.id
|
||||
})
|
||||
setFormData(data)
|
||||
}
|
||||
|
||||
|
||||
// 提交按钮
|
||||
const handleSubmit = async () => {
|
||||
await formRef.value?.validate()
|
||||
const data = { ...formData, }
|
||||
data.address = removeImageUrlPrefix(formData.address)
|
||||
mode.value == 'edit'
|
||||
? await apiCarouselEdit(data)
|
||||
: await apiCarouselAdd(data)
|
||||
popupRef.value?.close()
|
||||
emit('success')
|
||||
}
|
||||
|
||||
//打开弹窗
|
||||
const open = (type = 'add') => {
|
||||
mode.value = type
|
||||
popupRef.value?.open()
|
||||
}
|
||||
|
||||
// 关闭回调
|
||||
const handleClose = () => {
|
||||
emit('close')
|
||||
}
|
||||
|
||||
|
||||
|
||||
defineExpose({
|
||||
open,
|
||||
setFormData,
|
||||
getDetail
|
||||
})
|
||||
</script>
|
||||
108
src/views/gallery/carousel/index.vue
Normal file
108
src/views/gallery/carousel/index.vue
Normal file
@ -0,0 +1,108 @@
|
||||
<template>
|
||||
<div>
|
||||
<el-card class="!border-none" v-loading="pager.loading" shadow="never">
|
||||
<el-button v-perms="['carousel/add']" type="primary" @click="handleAdd">
|
||||
<template #icon>
|
||||
<icon name="el-icon-Plus" />
|
||||
</template>
|
||||
新增
|
||||
</el-button>
|
||||
<el-button v-perms="['carousel/delete']" :disabled="!selectData.length" @click="handleDelete(selectData)">
|
||||
删除
|
||||
</el-button>
|
||||
<div class="mt-4">
|
||||
<el-table :data="pager.lists" @selection-change="handleSelectionChange">
|
||||
<el-table-column type="selection" width="55" />
|
||||
<el-table-column label="标题" prop="title" show-overflow-tooltip />
|
||||
<el-table-column label="图片" prop="address" show-overflow-tooltip>
|
||||
<template #default="{ row }">
|
||||
<el-image style="width:100px;height:50px;" :src="row.address"
|
||||
:preview-src-list="[row.address]" preview-teleported fit="cover" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="状态" prop="status" show-overflow-tooltip>
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="row.status === 1 ? 'success' : 'danger'">
|
||||
{{ row.status === 1 ? '启用' : '禁用' }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="120" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button v-perms="['carousel/edit']" type="primary" link @click="handleEdit(row)">
|
||||
编辑
|
||||
</el-button>
|
||||
<el-button v-perms="['carousel/delete']" type="danger" link @click="handleDelete(row.id)">
|
||||
删除
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</div>
|
||||
<div class="flex mt-4 justify-end">
|
||||
<pagination v-model="pager" @change="getLists" />
|
||||
</div>
|
||||
</el-card>
|
||||
<edit-popup v-if="showEdit" ref="editRef" :dict-data="dictData" @success="getLists" @close="showEdit = false" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup name="carouselLists">
|
||||
import { usePaging } from '@/hooks/usePaging'
|
||||
import { useDictData } from '@/hooks/useDictOptions'
|
||||
import { apiCarouselLists, apiCarouselDelete } from '@/api/carousel'
|
||||
import { timeFormat } from '@/utils/util'
|
||||
import feedback from '@/utils/feedback'
|
||||
import EditPopup from './edit.vue'
|
||||
|
||||
const editRef = shallowRef<InstanceType<typeof EditPopup>>()
|
||||
// 是否显示编辑框
|
||||
const showEdit = ref(false)
|
||||
|
||||
|
||||
// 查询条件
|
||||
const queryParams = reactive({
|
||||
|
||||
})
|
||||
|
||||
// 选中数据
|
||||
const selectData = ref<any[]>([])
|
||||
|
||||
// 表格选择后回调事件
|
||||
const handleSelectionChange = (val: any[]) => {
|
||||
selectData.value = val.map(({ id }) => id)
|
||||
}
|
||||
|
||||
// 获取字典数据
|
||||
const { dictData } = useDictData('')
|
||||
|
||||
// 分页相关
|
||||
const { pager, getLists, resetParams, resetPage } = usePaging({
|
||||
fetchFun: apiCarouselLists,
|
||||
params: queryParams
|
||||
})
|
||||
|
||||
// 添加
|
||||
const handleAdd = async () => {
|
||||
showEdit.value = true
|
||||
await nextTick()
|
||||
editRef.value?.open('add')
|
||||
}
|
||||
|
||||
// 编辑
|
||||
const handleEdit = async (data: any) => {
|
||||
showEdit.value = true
|
||||
await nextTick()
|
||||
editRef.value?.open('edit')
|
||||
editRef.value?.setFormData(data)
|
||||
}
|
||||
|
||||
// 删除
|
||||
const handleDelete = async (id: number | any[]) => {
|
||||
await feedback.confirm('确定要删除?')
|
||||
await apiCarouselDelete({ id })
|
||||
getLists()
|
||||
}
|
||||
|
||||
getLists()
|
||||
</script>
|
||||
94
src/views/gallery/teamaster_gallery.vue
Normal file
94
src/views/gallery/teamaster_gallery.vue
Normal file
@ -0,0 +1,94 @@
|
||||
<template>
|
||||
<div class="teamaster-gallery">
|
||||
<el-card class="!border-none" v-loading="loading" shadow="never">
|
||||
<el-form ref="formRef" class="ls-form" :model="formData" :rules="formRules" label-width="100px">
|
||||
<el-form-item label="当前图片">
|
||||
<div class="w-[220px]">
|
||||
<el-image v-if="formData.url" style="width:220px;height:110px;" :src="formData.url"
|
||||
:preview-src-list="[formData.url]" preview-teleported fit="cover" />
|
||||
<div v-else class="text-tx-secondary">暂无图片</div>
|
||||
</div>
|
||||
</el-form-item>
|
||||
<el-form-item label="上传图片" prop="url">
|
||||
<material-picker v-model="formData.url" :limit="1" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-card>
|
||||
<footer-btns>
|
||||
<el-button type="primary" :loading="submitLoading" @click="handleSubmit">保存</el-button>
|
||||
</footer-btns>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup name="teamasterGallery">
|
||||
import type { FormInstance } from 'element-plus'
|
||||
import { apiCarouselTeamaster, apiCarouselTeamasterEdit } from '@/api/carousel'
|
||||
import { removeImageUrlPrefix } from '@/utils/util'
|
||||
|
||||
const formRef = shallowRef<FormInstance>()
|
||||
const loading = ref(false)
|
||||
const submitLoading = ref(false)
|
||||
|
||||
const formData = reactive<Record<string, any>>({
|
||||
url: ''
|
||||
})
|
||||
|
||||
const formRules = reactive({
|
||||
url: [
|
||||
{
|
||||
required: true,
|
||||
message: '请上传图片',
|
||||
trigger: ['change']
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
const setFormData = (data: any) => {
|
||||
formData.url = ''
|
||||
|
||||
if (!data) {
|
||||
return
|
||||
}
|
||||
|
||||
const currentData = Array.isArray(data) ? data.find((item) => item) : data
|
||||
|
||||
if (!currentData) {
|
||||
return
|
||||
}
|
||||
|
||||
if (typeof currentData === 'string') {
|
||||
formData.url = currentData
|
||||
return
|
||||
}
|
||||
|
||||
Object.assign(formData, currentData)
|
||||
formData.url = currentData.url ?? currentData.address ?? currentData.image ?? currentData.img ?? ''
|
||||
}
|
||||
|
||||
const getTeamasterImage = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const data = await apiCarouselTeamaster({})
|
||||
setFormData(data)
|
||||
}
|
||||
finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const handleSubmit = async () => {
|
||||
await formRef.value?.validate()
|
||||
submitLoading.value = true
|
||||
|
||||
const url = removeImageUrlPrefix(formData.url)
|
||||
try {
|
||||
await apiCarouselTeamasterEdit({ url })
|
||||
getTeamasterImage()
|
||||
}
|
||||
finally {
|
||||
submitLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
getTeamasterImage()
|
||||
</script>
|
||||
Reference in New Issue
Block a user