会员签到针对代码格式、功能优化
1.优化todo建议 2.删除无用代码
This commit is contained in:
parent
ac0f387322
commit
f310f65842
@ -2,13 +2,14 @@ import request from '@/config/axios'
|
|||||||
|
|
||||||
export interface SignInConfigVO {
|
export interface SignInConfigVO {
|
||||||
id: number
|
id: number
|
||||||
day: number
|
day: number | null
|
||||||
point: number
|
point: number | null
|
||||||
|
isEnable: boolean | null
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查询积分签到规则列表
|
// 查询积分签到规则列表
|
||||||
export const getSignInConfigPage = async (params) => {
|
export const getSignInConfigPage = async () => {
|
||||||
return await request.get({ url: `/point/sign-in-config/page`, params })
|
return await request.get({ url: `/point/sign-in-config/list` })
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查询积分签到规则详情
|
// 查询积分签到规则详情
|
||||||
@ -30,8 +31,3 @@ export const updateSignInConfig = async (data: SignInConfigVO) => {
|
|||||||
export const deleteSignInConfig = async (id: number) => {
|
export const deleteSignInConfig = async (id: number) => {
|
||||||
return await request.delete({ url: `/point/sign-in-config/delete?id=` + id })
|
return await request.delete({ url: `/point/sign-in-config/delete?id=` + id })
|
||||||
}
|
}
|
||||||
|
|
||||||
// 导出积分签到规则 Excel
|
|
||||||
export const exportSignInConfig = async (params) => {
|
|
||||||
return await request.download({ url: `/point/sign-in-config/export-excel`, params })
|
|
||||||
}
|
|
||||||
|
@ -12,26 +12,6 @@ export const getSignInRecordPage = async (params) => {
|
|||||||
return await request.get({ url: `/point/sign-in-record/page`, params })
|
return await request.get({ url: `/point/sign-in-record/page`, params })
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查询用户签到积分详情
|
|
||||||
export const getSignInRecord = async (id: number) => {
|
|
||||||
return await request.get({ url: `/point/sign-in-record/get?id=` + id })
|
|
||||||
}
|
|
||||||
|
|
||||||
// 新增用户签到积分
|
|
||||||
export const createSignInRecord = async (data: SignInRecordVO) => {
|
|
||||||
return await request.post({ url: `/point/sign-in-record/create`, data })
|
|
||||||
}
|
|
||||||
|
|
||||||
// 修改用户签到积分
|
|
||||||
export const updateSignInRecord = async (data: SignInRecordVO) => {
|
|
||||||
return await request.put({ url: `/point/sign-in-record/update`, data })
|
|
||||||
}
|
|
||||||
|
|
||||||
// 删除用户签到积分
|
|
||||||
export const deleteSignInRecord = async (id: number) => {
|
|
||||||
return await request.delete({ url: `/point/sign-in-record/delete?id=` + id })
|
|
||||||
}
|
|
||||||
|
|
||||||
// 导出用户签到积分 Excel
|
// 导出用户签到积分 Excel
|
||||||
export const exportSignInRecord = async (params) => {
|
export const exportSignInRecord = async (params) => {
|
||||||
return await request.download({ url: `/point/sign-in-record/export-excel`, params })
|
return await request.download({ url: `/point/sign-in-record/export-excel`, params })
|
||||||
|
@ -69,8 +69,14 @@
|
|||||||
/>
|
/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item>
|
<el-form-item>
|
||||||
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
|
<el-button @click="handleQuery">
|
||||||
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
|
<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-item>
|
||||||
</el-form>
|
</el-form>
|
||||||
</ContentWrap>
|
</ContentWrap>
|
||||||
@ -95,7 +101,7 @@
|
|||||||
align="center"
|
align="center"
|
||||||
prop="type"
|
prop="type"
|
||||||
:formatter="
|
:formatter="
|
||||||
(a, b, c) => {
|
(_, __, c) => {
|
||||||
return c === '1' ? '增加' : '扣减'
|
return c === '1' ? '增加' : '扣减'
|
||||||
}
|
}
|
||||||
"
|
"
|
||||||
|
@ -1,26 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<ContentWrap>
|
<ContentWrap>
|
||||||
<!-- 搜索工作栏 -->
|
<!-- 搜索工作栏 -->
|
||||||
<el-form
|
|
||||||
class="-mb-15px"
|
|
||||||
:model="queryParams"
|
|
||||||
ref="queryFormRef"
|
|
||||||
:inline="true"
|
|
||||||
label-width="68px"
|
|
||||||
>
|
|
||||||
<!-- TODO @xiaqing:搜索可以去掉,因为一共就没几条配置哈 -->
|
|
||||||
<el-form-item label="签到天数" prop="day">
|
|
||||||
<el-input
|
|
||||||
v-model="queryParams.day"
|
|
||||||
placeholder="请输入签到天数"
|
|
||||||
clearable
|
|
||||||
@keyup.enter="handleQuery"
|
|
||||||
class="!w-240px"
|
|
||||||
/>
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item>
|
|
||||||
<el-button @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-button
|
<el-button
|
||||||
type="primary"
|
type="primary"
|
||||||
plain
|
plain
|
||||||
@ -29,27 +9,31 @@
|
|||||||
>
|
>
|
||||||
<Icon icon="ep:plus" class="mr-5px" /> 新增
|
<Icon icon="ep:plus" class="mr-5px" /> 新增
|
||||||
</el-button>
|
</el-button>
|
||||||
<el-button
|
|
||||||
type="success"
|
|
||||||
plain
|
|
||||||
@click="handleExport"
|
|
||||||
:loading="exportLoading"
|
|
||||||
v-hasPermi="['point:sign-in-config:export']"
|
|
||||||
>
|
|
||||||
<!-- TODO @xiaqing:四个功能的导出都可以去掉 -->
|
|
||||||
<Icon icon="ep:download" class="mr-5px" /> 导出
|
|
||||||
</el-button>
|
|
||||||
</el-form-item>
|
|
||||||
</el-form>
|
|
||||||
</ContentWrap>
|
</ContentWrap>
|
||||||
|
|
||||||
<!-- 列表 -->
|
<!-- 列表 -->
|
||||||
<ContentWrap>
|
<ContentWrap>
|
||||||
<el-table v-loading="loading" :data="list">
|
<el-table v-loading="loading" :data="list">
|
||||||
<!-- TODO @xiaqing:展示优化下,改成第 1 天、第 2 天这种 -->
|
<el-table-column
|
||||||
<el-table-column label="签到天数" align="center" prop="day" />
|
label="签到天数"
|
||||||
|
align="center"
|
||||||
|
prop="day"
|
||||||
|
:formatter="(_, __, cellValue) => ['第', cellValue, '天'].join(' ')"
|
||||||
|
/>
|
||||||
<el-table-column label="获得积分" align="center" prop="point" />
|
<el-table-column label="获得积分" align="center" prop="point" />
|
||||||
<!-- TODO @xiaqing:展示一个是否开启 -->
|
<el-table-column label="是否开启" align="center">
|
||||||
|
<template #default="scope">
|
||||||
|
<div>
|
||||||
|
<el-switch
|
||||||
|
v-model="scope.row.isEnable"
|
||||||
|
@change="handleSwitchChange(scope.row.id, $event)"
|
||||||
|
inline-prompt
|
||||||
|
active-text="开启"
|
||||||
|
inactive-text="关闭"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
<el-table-column label="操作" align="center">
|
<el-table-column label="操作" align="center">
|
||||||
<template #default="scope">
|
<template #default="scope">
|
||||||
<el-button
|
<el-button
|
||||||
@ -71,13 +55,6 @@
|
|||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
</el-table>
|
</el-table>
|
||||||
<!-- 分页 -->
|
|
||||||
<Pagination
|
|
||||||
:total="total"
|
|
||||||
v-model:page="queryParams.pageNo"
|
|
||||||
v-model:limit="queryParams.pageSize"
|
|
||||||
@pagination="getList"
|
|
||||||
/>
|
|
||||||
</ContentWrap>
|
</ContentWrap>
|
||||||
|
|
||||||
<!-- 表单弹窗:添加/修改 -->
|
<!-- 表单弹窗:添加/修改 -->
|
||||||
@ -85,9 +62,9 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import download from '@/utils/download'
|
|
||||||
import * as SignInConfigApi from '@/api/point/signInConfig'
|
import * as SignInConfigApi from '@/api/point/signInConfig'
|
||||||
import SignInConfigForm from './SignInConfigForm.vue'
|
import SignInConfigForm from './SignInConfigForm.vue'
|
||||||
|
import { SignInConfigVO } from '@/api/point/signInConfig'
|
||||||
|
|
||||||
defineOptions({ name: 'SignInConfig' })
|
defineOptions({ name: 'SignInConfig' })
|
||||||
|
|
||||||
@ -95,41 +72,20 @@ const message = useMessage() // 消息弹窗
|
|||||||
const { t } = useI18n() // 国际化
|
const { t } = useI18n() // 国际化
|
||||||
|
|
||||||
const loading = ref(true) // 列表的加载中
|
const loading = ref(true) // 列表的加载中
|
||||||
const total = ref(0) // 列表的总页数
|
|
||||||
const list = ref([]) // 列表的数据
|
const list = ref([]) // 列表的数据
|
||||||
const queryParams = reactive({
|
|
||||||
pageNo: 1,
|
|
||||||
pageSize: 10,
|
|
||||||
day: null
|
|
||||||
})
|
|
||||||
const queryFormRef = ref() // 搜索的表单
|
|
||||||
const exportLoading = ref(false) // 导出的加载中
|
|
||||||
|
|
||||||
// TODO @xiaqing:可以不分页;
|
|
||||||
/** 查询列表 */
|
/** 查询列表 */
|
||||||
const getList = async () => {
|
const getList = async () => {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
try {
|
try {
|
||||||
const data = await SignInConfigApi.getSignInConfigPage(queryParams)
|
const data = await SignInConfigApi.getSignInConfigPage()
|
||||||
list.value = data.list
|
console.log(data)
|
||||||
total.value = data.total
|
list.value = data
|
||||||
} finally {
|
} finally {
|
||||||
loading.value = false
|
loading.value = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 搜索按钮操作 */
|
|
||||||
const handleQuery = () => {
|
|
||||||
queryParams.pageNo = 1
|
|
||||||
getList()
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 重置按钮操作 */
|
|
||||||
const resetQuery = () => {
|
|
||||||
queryFormRef.value.resetFields()
|
|
||||||
handleQuery()
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 添加/修改操作 */
|
/** 添加/修改操作 */
|
||||||
const formRef = ref()
|
const formRef = ref()
|
||||||
const openForm = (type: string, id?: number) => {
|
const openForm = (type: string, id?: number) => {
|
||||||
@ -149,19 +105,16 @@ const handleDelete = async (id: number) => {
|
|||||||
} catch {}
|
} catch {}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 导出按钮操作 */
|
const handleSwitchChange = async (id, e) => {
|
||||||
const handleExport = async () => {
|
console.log('开关状态变更,id:', id, '新状态:', e)
|
||||||
try {
|
// 创建对象
|
||||||
// 导出的二次确认
|
const signInConfig: SignInConfigVO = {
|
||||||
await message.exportConfirm()
|
id: id,
|
||||||
// 发起导出
|
day: null,
|
||||||
exportLoading.value = true
|
point: null,
|
||||||
const data = await SignInConfigApi.exportSignInConfig(queryParams)
|
isEnable: e
|
||||||
download.excel(data, '积分签到规则.xls')
|
|
||||||
} catch {
|
|
||||||
} finally {
|
|
||||||
exportLoading.value = false
|
|
||||||
}
|
}
|
||||||
|
await SignInConfigApi.updateSignInConfig(signInConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 初始化 **/
|
/** 初始化 **/
|
||||||
|
@ -1,99 +0,0 @@
|
|||||||
<template>
|
|
||||||
<Dialog :title="dialogTitle" v-model="dialogVisible">
|
|
||||||
<el-form
|
|
||||||
ref="formRef"
|
|
||||||
:model="formData"
|
|
||||||
:rules="formRules"
|
|
||||||
label-width="100px"
|
|
||||||
v-loading="formLoading"
|
|
||||||
>
|
|
||||||
<el-form-item label="签到用户" prop="userId">
|
|
||||||
<el-input v-model="formData.userId" placeholder="请输入签到用户" />
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item label="签到天数" prop="day">
|
|
||||||
<el-input v-model="formData.day" placeholder="请输入签到天数" />
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item label="签到的分数" prop="point">
|
|
||||||
<el-input v-model="formData.point" placeholder="请输入签到的分数" />
|
|
||||||
</el-form-item>
|
|
||||||
</el-form>
|
|
||||||
<template #footer>
|
|
||||||
<el-button @click="submitForm" type="primary" :disabled="formLoading">确 定</el-button>
|
|
||||||
<el-button @click="dialogVisible = false">取 消</el-button>
|
|
||||||
</template>
|
|
||||||
</Dialog>
|
|
||||||
</template>
|
|
||||||
<script lang="ts" setup>
|
|
||||||
import * as SignInRecordApi from '@/api/point/signInRecord'
|
|
||||||
|
|
||||||
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,
|
|
||||||
userId: undefined,
|
|
||||||
day: undefined,
|
|
||||||
point: undefined
|
|
||||||
})
|
|
||||||
const formRules = reactive({})
|
|
||||||
const formRef = ref() // 表单 Ref
|
|
||||||
|
|
||||||
/** 打开弹窗 */
|
|
||||||
const open = async (type: string, id?: number) => {
|
|
||||||
dialogVisible.value = true
|
|
||||||
dialogTitle.value = t('action.' + type)
|
|
||||||
formType.value = type
|
|
||||||
resetForm()
|
|
||||||
// 修改时,设置数据
|
|
||||||
if (id) {
|
|
||||||
formLoading.value = true
|
|
||||||
try {
|
|
||||||
formData.value = await SignInRecordApi.getSignInRecord(id)
|
|
||||||
} finally {
|
|
||||||
formLoading.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
|
|
||||||
|
|
||||||
/** 提交表单 */
|
|
||||||
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
|
|
||||||
const submitForm = async () => {
|
|
||||||
// 校验表单
|
|
||||||
if (!formRef) return
|
|
||||||
const valid = await formRef.value.validate()
|
|
||||||
if (!valid) return
|
|
||||||
// 提交请求
|
|
||||||
formLoading.value = true
|
|
||||||
try {
|
|
||||||
const data = formData.value as unknown as SignInRecordApi.SignInRecordVO
|
|
||||||
if (formType.value === 'create') {
|
|
||||||
await SignInRecordApi.createSignInRecord(data)
|
|
||||||
message.success(t('common.createSuccess'))
|
|
||||||
} else {
|
|
||||||
await SignInRecordApi.updateSignInRecord(data)
|
|
||||||
message.success(t('common.updateSuccess'))
|
|
||||||
}
|
|
||||||
dialogVisible.value = false
|
|
||||||
// 发送操作成功的事件
|
|
||||||
emit('success')
|
|
||||||
} finally {
|
|
||||||
formLoading.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 重置表单 */
|
|
||||||
const resetForm = () => {
|
|
||||||
formData.value = {
|
|
||||||
id: undefined,
|
|
||||||
userId: undefined,
|
|
||||||
day: undefined,
|
|
||||||
point: undefined
|
|
||||||
}
|
|
||||||
formRef.value?.resetFields()
|
|
||||||
}
|
|
||||||
</script>
|
|
@ -58,7 +58,7 @@
|
|||||||
<el-table v-loading="loading" :data="list">
|
<el-table v-loading="loading" :data="list">
|
||||||
<el-table-column label="编号" align="center" prop="id" />
|
<el-table-column label="编号" align="center" prop="id" />
|
||||||
<!-- TODO @xiaqing:展示用户昵称 -->
|
<!-- TODO @xiaqing:展示用户昵称 -->
|
||||||
<el-table-column label="签到用户" align="center" prop="userId" />
|
<el-table-column label="签到用户" align="center" prop="nickName" />
|
||||||
<el-table-column label="签到天数" align="center" prop="day" />
|
<el-table-column label="签到天数" align="center" prop="day" />
|
||||||
<el-table-column label="获得积分" align="center" prop="point" />
|
<el-table-column label="获得积分" align="center" prop="point" />
|
||||||
<el-table-column
|
<el-table-column
|
||||||
@ -67,18 +67,6 @@
|
|||||||
prop="createTime"
|
prop="createTime"
|
||||||
:formatter="dateFormatter"
|
:formatter="dateFormatter"
|
||||||
/>
|
/>
|
||||||
<el-table-column label="操作" align="center">
|
|
||||||
<template #default="scope">
|
|
||||||
<el-button
|
|
||||||
link
|
|
||||||
type="danger"
|
|
||||||
@click="handleDelete(scope.row.id)"
|
|
||||||
v-hasPermi="['point:sign-in-record:delete']"
|
|
||||||
>
|
|
||||||
删除
|
|
||||||
</el-button>
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
</el-table>
|
</el-table>
|
||||||
<!-- 分页 -->
|
<!-- 分页 -->
|
||||||
<Pagination
|
<Pagination
|
||||||
@ -97,12 +85,10 @@
|
|||||||
import { dateFormatter } from '@/utils/formatTime'
|
import { dateFormatter } from '@/utils/formatTime'
|
||||||
import download from '@/utils/download'
|
import download from '@/utils/download'
|
||||||
import * as SignInRecordApi from '@/api/point/signInRecord'
|
import * as SignInRecordApi from '@/api/point/signInRecord'
|
||||||
import SignInRecordForm from './SignInRecordForm.vue'
|
|
||||||
|
|
||||||
defineOptions({ name: 'SignInRecord' })
|
defineOptions({ name: 'SignInRecord' })
|
||||||
|
|
||||||
const message = useMessage() // 消息弹窗
|
const message = useMessage() // 消息弹窗
|
||||||
const { t } = useI18n() // 国际化
|
|
||||||
|
|
||||||
const loading = ref(true) // 列表的加载中
|
const loading = ref(true) // 列表的加载中
|
||||||
const total = ref(0) // 列表的总页数
|
const total = ref(0) // 列表的总页数
|
||||||
@ -141,25 +127,6 @@ const resetQuery = () => {
|
|||||||
handleQuery()
|
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 SignInRecordApi.deleteSignInRecord(id)
|
|
||||||
message.success(t('common.delSuccess'))
|
|
||||||
// 刷新列表
|
|
||||||
await getList()
|
|
||||||
} catch {}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 导出按钮操作 */
|
/** 导出按钮操作 */
|
||||||
const handleExport = async () => {
|
const handleExport = async () => {
|
||||||
try {
|
try {
|
||||||
|
Loading…
Reference in New Issue
Block a user