新增小程序配置
parent
95bb75ebda
commit
0ba451ee6d
|
|
@ -0,0 +1,54 @@
|
|||
import request from '@/config/axios'
|
||||
import type {Dayjs} from 'dayjs';
|
||||
|
||||
/** 小程序配置信息 */
|
||||
export interface MiniAppConfig {
|
||||
id: number; // 编号
|
||||
name?: string; // 功能名称
|
||||
icon: string; // 功能图标
|
||||
position?: number; // 显示位置(1-首页,2-更多服务)
|
||||
sort?: number; // 排序(数字越小越靠前)
|
||||
status?: number; // 是否显示(0-启用,1-禁用)
|
||||
communityId?: number; // 小区ID
|
||||
communityName: string; // 小区名称
|
||||
url: string; // 跳转链接
|
||||
remark: string; // 备注
|
||||
}
|
||||
|
||||
// 小程序配置 API
|
||||
export const MiniAppConfigApi = {
|
||||
// 查询小程序配置分页
|
||||
getMiniAppConfigPage: async (params: any) => {
|
||||
return await request.get({ url: `/community/mini-app-config/page`, params })
|
||||
},
|
||||
|
||||
// 查询小程序配置详情
|
||||
getMiniAppConfig: async (id: number) => {
|
||||
return await request.get({ url: `/community/mini-app-config/get?id=` + id })
|
||||
},
|
||||
|
||||
// 新增小程序配置
|
||||
createMiniAppConfig: async (data: MiniAppConfig) => {
|
||||
return await request.post({ url: `/community/mini-app-config/create`, data })
|
||||
},
|
||||
|
||||
// 修改小程序配置
|
||||
updateMiniAppConfig: async (data: MiniAppConfig) => {
|
||||
return await request.put({ url: `/community/mini-app-config/update`, data })
|
||||
},
|
||||
|
||||
// 删除小程序配置
|
||||
deleteMiniAppConfig: async (id: number) => {
|
||||
return await request.delete({ url: `/community/mini-app-config/delete?id=` + id })
|
||||
},
|
||||
|
||||
/** 批量删除小程序配置 */
|
||||
deleteMiniAppConfigList: async (ids: number[]) => {
|
||||
return await request.delete({ url: `/community/mini-app-config/delete-list?ids=${ids.join(',')}` })
|
||||
},
|
||||
|
||||
// 导出小程序配置 Excel
|
||||
exportMiniAppConfig: async (params) => {
|
||||
return await request.download({ url: `/community/mini-app-config/export-excel`, params })
|
||||
}
|
||||
}
|
||||
|
|
@ -203,4 +203,5 @@ export enum DICT_TYPE {
|
|||
COMM_RELATION_TYPE = 'comm_relation_type',
|
||||
COMM_ID_TYPE = 'comm_id_type',
|
||||
COMM_BANNER_LOCATION = 'comm_banner_location',
|
||||
COMM_MINI_APP_LOCATION = 'comm_mini_app_location'
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,214 @@
|
|||
<template>
|
||||
<Dialog :title="dialogTitle" v-model="dialogVisible" width="800">
|
||||
<el-form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:rules="formRules"
|
||||
label-width="100px"
|
||||
v-loading="formLoading"
|
||||
>
|
||||
<el-row :gutter="20">
|
||||
<el-col :span="12">
|
||||
<el-form-item label="功能名称" prop="name">
|
||||
<el-input v-model="formData.name" placeholder="请输入功能名称" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="小区名称" prop="communityId">
|
||||
<el-select
|
||||
v-model="formData.communityId"
|
||||
placeholder="请选择"
|
||||
clearable
|
||||
filterable
|
||||
style="width: 100%"
|
||||
@change="handleCommunityChange"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in communityOptions"
|
||||
:key="item.id"
|
||||
:label="item.communityName"
|
||||
:value="item.id"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row :gutter="20">
|
||||
<el-col :span="12">
|
||||
<el-form-item label="跳转链接" prop="url">
|
||||
<el-input v-model="formData.url" placeholder="请输入跳转链接" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="显示位置" prop="position">
|
||||
<el-select v-model="formData.position" placeholder="请选择" style="width: 100%">
|
||||
<el-option
|
||||
v-for="dict in getIntDictOptions(DICT_TYPE.COMM_MINI_APP_LOCATION)"
|
||||
:key="dict.value"
|
||||
:label="dict.label"
|
||||
:value="dict.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row :gutter="20">
|
||||
<el-col :span="12">
|
||||
<el-form-item label="功能图标" prop="icon">
|
||||
<UploadImg v-model="formData.icon" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="排序" prop="sort">
|
||||
<el-input-number
|
||||
v-model="formData.sort"
|
||||
:min="0"
|
||||
:max="9999"
|
||||
:step="1"
|
||||
placeholder="请输入排序"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row :gutter="20">
|
||||
<el-col :span="12">
|
||||
<el-form-item label="是否有效" prop="status">
|
||||
<el-radio-group v-model="formData.status">
|
||||
<el-radio :value="0">启用</el-radio>
|
||||
<el-radio :value="1">禁用</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="dialogVisible = false">取 消</el-button>
|
||||
<el-button @click="submitForm" type="primary" :disabled="formLoading">确 定</el-button>
|
||||
</template>
|
||||
</Dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { getIntDictOptions, DICT_TYPE } from '@/utils/dict'
|
||||
import { MiniAppConfigApi, MiniAppConfig } from '@/api/community/miniappconfig'
|
||||
import { CommunityApi, CommunitySimpleVO } from '@/api/community/community'
|
||||
|
||||
/** 小程序配置 表单 */
|
||||
defineOptions({ name: 'MiniAppConfigForm' })
|
||||
|
||||
const { t } = useI18n() // 国际化
|
||||
const message = useMessage() // 消息弹窗
|
||||
|
||||
const dialogVisible = ref(false) // 弹窗的是否展示
|
||||
const dialogTitle = ref('') // 弹窗的标题
|
||||
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
|
||||
const formType = ref('') // 表单的类型:create - 新增;update - 修改
|
||||
const formData = ref({
|
||||
id: undefined,
|
||||
name: undefined,
|
||||
icon: undefined,
|
||||
position: undefined,
|
||||
sort: 0,
|
||||
status: 0,
|
||||
communityId: undefined,
|
||||
communityName: undefined,
|
||||
url: undefined,
|
||||
remark: undefined
|
||||
})
|
||||
const formRules = reactive({
|
||||
name: [{ required: true, message: '功能名称不能为空', trigger: 'blur' }],
|
||||
position: [{ required: true, message: '显示位置不能为空', trigger: 'change' }],
|
||||
status: [{ required: true, message: '是否有效不能为空', trigger: 'change' }],
|
||||
communityId: [{ required: true, message: '小区名称不能为空', trigger: 'change' }],
|
||||
icon: [{ required: true, message: '功能图标不能为空', trigger: 'change' }],
|
||||
url: [{ required: true, message: '跳转链接不能为空', trigger: 'blur' }],
|
||||
sort: [
|
||||
{ required: true, message: '排序不能为空', trigger: 'blur' },
|
||||
{ type: 'number', message: '排序必须为数字', trigger: 'blur' }
|
||||
]
|
||||
})
|
||||
const formRef = ref() // 表单 Ref
|
||||
const communityOptions = ref<CommunitySimpleVO[]>([]) // 小区选项列表
|
||||
|
||||
/** 加载小区列表 */
|
||||
const loadCommunityList = async () => {
|
||||
try {
|
||||
communityOptions.value = await CommunityApi.getCommunitySimpleList()
|
||||
} catch (error) {
|
||||
console.error('加载小区列表失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
/** 小区选择变化 */
|
||||
const handleCommunityChange = (value: number) => {
|
||||
const community = communityOptions.value.find(item => item.id === value)
|
||||
if (community) {
|
||||
formData.value.communityName = community.communityName
|
||||
}
|
||||
}
|
||||
|
||||
/** 打开弹窗 */
|
||||
const open = async (type: string, id?: number) => {
|
||||
dialogVisible.value = true
|
||||
dialogTitle.value = t('action.' + type)
|
||||
formType.value = type
|
||||
resetForm()
|
||||
|
||||
// 加载小区列表
|
||||
await loadCommunityList()
|
||||
|
||||
// 修改时,设置数据
|
||||
if (id) {
|
||||
formLoading.value = true
|
||||
try {
|
||||
formData.value = await MiniAppConfigApi.getMiniAppConfig(id)
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
}
|
||||
}
|
||||
}
|
||||
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
|
||||
|
||||
/** 提交表单 */
|
||||
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
|
||||
const submitForm = async () => {
|
||||
// 校验表单
|
||||
await formRef.value.validate()
|
||||
// 提交请求
|
||||
formLoading.value = true
|
||||
try {
|
||||
const data = formData.value as unknown as MiniAppConfig
|
||||
if (formType.value === 'create') {
|
||||
await MiniAppConfigApi.createMiniAppConfig(data)
|
||||
message.success(t('common.createSuccess'))
|
||||
} else {
|
||||
await MiniAppConfigApi.updateMiniAppConfig(data)
|
||||
message.success(t('common.updateSuccess'))
|
||||
}
|
||||
dialogVisible.value = false
|
||||
// 发送操作成功的事件
|
||||
emit('success')
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 重置表单 */
|
||||
const resetForm = () => {
|
||||
formData.value = {
|
||||
id: undefined,
|
||||
name: undefined,
|
||||
icon: undefined,
|
||||
position: undefined,
|
||||
sort: 0,
|
||||
status: 0,
|
||||
communityId: undefined,
|
||||
communityName: undefined,
|
||||
url: undefined,
|
||||
remark: undefined
|
||||
}
|
||||
formRef.value?.resetFields()
|
||||
}
|
||||
|
||||
</script>
|
||||
|
|
@ -0,0 +1,295 @@
|
|||
<template>
|
||||
<ContentWrap>
|
||||
<!-- 搜索工作栏 -->
|
||||
<el-form
|
||||
class="-mb-15px"
|
||||
:model="queryParams"
|
||||
ref="queryFormRef"
|
||||
:inline="true"
|
||||
label-width="80px"
|
||||
>
|
||||
<el-form-item label="功能名称" prop="name">
|
||||
<el-input
|
||||
v-model="queryParams.name"
|
||||
placeholder="请输入功能名称"
|
||||
clearable
|
||||
@keyup.enter="handleQuery"
|
||||
class="!w-240px"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="是否显示" prop="status">
|
||||
<el-select
|
||||
v-model="queryParams.status"
|
||||
placeholder="请选择"
|
||||
clearable
|
||||
class="!w-240px"
|
||||
>
|
||||
<el-option
|
||||
v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
|
||||
:key="dict.value"
|
||||
:label="dict.label"
|
||||
:value="dict.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="小区名称" prop="communityName">
|
||||
<el-select
|
||||
v-model="queryParams.communityName"
|
||||
placeholder="请选择"
|
||||
clearable
|
||||
filterable
|
||||
class="!w-240px"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in communityOptions"
|
||||
:key="item.id"
|
||||
:label="item.communityName"
|
||||
:value="item.communityName"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="handleQuery">
|
||||
<Icon icon="ep:search" class="mr-5px" /> 查询
|
||||
</el-button>
|
||||
<el-button @click="resetQuery">
|
||||
<Icon icon="ep:refresh" class="mr-5px" /> 重置
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</ContentWrap>
|
||||
|
||||
<!-- 操作按钮栏 -->
|
||||
<ContentWrap>
|
||||
<div class="mb-15px">
|
||||
<el-button
|
||||
type="primary"
|
||||
plain
|
||||
@click="openForm('create')"
|
||||
v-hasPermi="['community:mini-app-config:create']"
|
||||
>
|
||||
<Icon icon="ep:plus" class="mr-5px" /> 新建
|
||||
</el-button>
|
||||
</div>
|
||||
</ContentWrap>
|
||||
|
||||
<!-- 列表 -->
|
||||
<ContentWrap>
|
||||
<el-table
|
||||
row-key="id"
|
||||
v-loading="loading"
|
||||
:data="list"
|
||||
:stripe="true"
|
||||
:show-overflow-tooltip="true"
|
||||
@selection-change="handleRowCheckboxChange"
|
||||
:header-cell-style="{
|
||||
background: '#1890ff',
|
||||
color: '#ffffff',
|
||||
textAlign: 'center',
|
||||
fontWeight: 'normal',
|
||||
fontSize: '14px',
|
||||
borderColor: '#1890ff'
|
||||
}"
|
||||
:cell-style="{
|
||||
textAlign: 'center',
|
||||
fontSize: '14px',
|
||||
color: '#333333',
|
||||
borderColor: '#ebeef5'
|
||||
}"
|
||||
>
|
||||
<el-table-column type="selection" width="55" align="center" />
|
||||
<el-table-column label="序号" align="center" type="index" width="80" />
|
||||
<el-table-column label="功能名称" align="center" prop="name" min-width="120" />
|
||||
<el-table-column label="小区名称" align="center" prop="communityName" min-width="120" />
|
||||
<el-table-column label="功能图标" align="center" prop="icon" width="100">
|
||||
<template #default="scope">
|
||||
<el-image
|
||||
v-if="scope.row.icon"
|
||||
:src="scope.row.icon"
|
||||
:preview-src-list="[scope.row.icon]"
|
||||
fit="contain"
|
||||
style="width: 40px; height: 40px"
|
||||
/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="显示位置" align="center" prop="position" width="120">
|
||||
<template #default="scope">
|
||||
<dict-tag :type="DICT_TYPE.COMM_MINI_APP_LOCATION" :value="scope.row.position" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="排序" align="center" prop="sort" width="80" />
|
||||
<el-table-column label="是否显示" align="center" prop="status" width="100">
|
||||
<template #default="scope">
|
||||
<el-switch
|
||||
v-model="scope.row.status"
|
||||
:active-value="0"
|
||||
:inactive-value="1"
|
||||
@change="handleStatusChange(scope.row)"
|
||||
v-hasPermi="['community:mini-app-config:update']"
|
||||
/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" align="center" min-width="120px" fixed="right">
|
||||
<template #default="scope">
|
||||
<el-button
|
||||
link
|
||||
type="primary"
|
||||
@click="openForm('update', scope.row.id)"
|
||||
v-hasPermi="['community:mini-app-config:update']"
|
||||
>
|
||||
详情
|
||||
</el-button>
|
||||
<el-button
|
||||
link
|
||||
type="danger"
|
||||
@click="handleDelete(scope.row.id)"
|
||||
v-hasPermi="['community:mini-app-config:delete']"
|
||||
>
|
||||
删除
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<!-- 分页 -->
|
||||
<Pagination
|
||||
:total="total"
|
||||
v-model:page="queryParams.pageNo"
|
||||
v-model:limit="queryParams.pageSize"
|
||||
@pagination="getList"
|
||||
/>
|
||||
</ContentWrap>
|
||||
|
||||
<!-- 表单弹窗:添加/修改 -->
|
||||
<MiniAppConfigForm ref="formRef" @success="getList" />
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { getIntDictOptions, DICT_TYPE } from '@/utils/dict'
|
||||
import { isEmpty } from '@/utils/is'
|
||||
import { dateFormatter } from '@/utils/formatTime'
|
||||
import download from '@/utils/download'
|
||||
import { MiniAppConfigApi, MiniAppConfig } from '@/api/community/miniappconfig'
|
||||
import MiniAppConfigForm from './MiniAppConfigForm.vue'
|
||||
import { CommunityApi, CommunitySimpleVO } from '@/api/community/community'
|
||||
|
||||
/** 小程序配置 列表 */
|
||||
defineOptions({ name: 'MiniAppConfig' })
|
||||
|
||||
const message = useMessage() // 消息弹窗
|
||||
const { t } = useI18n() // 国际化
|
||||
|
||||
const loading = ref(true) // 列表的加载中
|
||||
const list = ref<MiniAppConfig[]>([]) // 列表的数据
|
||||
const total = ref(0) // 列表的总页数
|
||||
const queryParams = reactive({
|
||||
pageNo: 1,
|
||||
pageSize: 10,
|
||||
name: undefined,
|
||||
status: undefined,
|
||||
communityName: undefined
|
||||
})
|
||||
const queryFormRef = ref() // 搜索的表单
|
||||
const exportLoading = ref(false) // 导出的加载中
|
||||
const communityOptions = ref<CommunitySimpleVO[]>([]) // 小区选项列表
|
||||
|
||||
/** 查询列表 */
|
||||
const getList = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const data = await MiniAppConfigApi.getMiniAppConfigPage(queryParams)
|
||||
list.value = data.list
|
||||
total.value = data.total
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 加载小区列表 */
|
||||
const loadCommunityList = async () => {
|
||||
try {
|
||||
communityOptions.value = await CommunityApi.getCommunitySimpleList()
|
||||
} catch (error) {
|
||||
console.error('加载小区列表失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
/** 搜索按钮操作 */
|
||||
const handleQuery = () => {
|
||||
queryParams.pageNo = 1
|
||||
getList()
|
||||
}
|
||||
|
||||
/** 重置按钮操作 */
|
||||
const resetQuery = () => {
|
||||
queryFormRef.value.resetFields()
|
||||
handleQuery()
|
||||
}
|
||||
|
||||
/** 添加/修改操作 */
|
||||
const formRef = ref()
|
||||
const openForm = (type: string, id?: number) => {
|
||||
formRef.value.open(type, id)
|
||||
}
|
||||
|
||||
/** 删除按钮操作 */
|
||||
const handleDelete = async (id: number) => {
|
||||
try {
|
||||
// 删除的二次确认
|
||||
await message.delConfirm()
|
||||
// 发起删除
|
||||
await MiniAppConfigApi.deleteMiniAppConfig(id)
|
||||
message.success(t('common.delSuccess'))
|
||||
// 刷新列表
|
||||
await getList()
|
||||
} catch {}
|
||||
}
|
||||
|
||||
/** 批量删除小程序配置 */
|
||||
const handleDeleteBatch = async () => {
|
||||
try {
|
||||
// 删除的二次确认
|
||||
await message.delConfirm()
|
||||
await MiniAppConfigApi.deleteMiniAppConfigList(checkedIds.value);
|
||||
checkedIds.value = [];
|
||||
message.success(t('common.delSuccess'))
|
||||
await getList();
|
||||
} catch {}
|
||||
}
|
||||
|
||||
const checkedIds = ref<number[]>([])
|
||||
const handleRowCheckboxChange = (records: MiniAppConfig[]) => {
|
||||
checkedIds.value = records.map((item) => item.id!);
|
||||
}
|
||||
|
||||
/** 状态切换 */
|
||||
const handleStatusChange = async (row: MiniAppConfig) => {
|
||||
try {
|
||||
await MiniAppConfigApi.updateMiniAppConfig(row)
|
||||
message.success('状态修改成功')
|
||||
} catch {
|
||||
// 失败时恢复原状态
|
||||
row.status = row.status === 0 ? 1 : 0
|
||||
}
|
||||
}
|
||||
|
||||
/** 导出按钮操作 */
|
||||
const handleExport = async () => {
|
||||
try {
|
||||
// 导出的二次确认
|
||||
await message.exportConfirm()
|
||||
// 发起导出
|
||||
exportLoading.value = true
|
||||
const data = await MiniAppConfigApi.exportMiniAppConfig(queryParams)
|
||||
download.excel(data, '小程序配置.xls')
|
||||
} catch {
|
||||
} finally {
|
||||
exportLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 初始化 **/
|
||||
onMounted(() => {
|
||||
loadCommunityList()
|
||||
getList()
|
||||
})
|
||||
</script>
|
||||
Loading…
Reference in New Issue