!207 会员管理:增加会员标签功能

Merge pull request !207 from 疯狂的世界/member_dev
This commit is contained in:
芋道源码 2023-08-20 01:16:45 +00:00 committed by Gitee
commit a99a125c2b
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
6 changed files with 399 additions and 3 deletions

View File

@ -0,0 +1,36 @@
import request from '@/config/axios'
export interface TagVO {
id: number
name: string
}
// 查询会员标签列表
export const getMemberTagPage = async (params) => {
return await request.get({ url: `/member/tag/page`, params })
}
// 查询会员标签详情
export const getMemberTag = async (id: number) => {
return await request.get({ url: `/member/tag/get?id=` + id })
}
// 新增会员标签
export const createMemberTag = async (data: TagVO) => {
return await request.post({ url: `/member/tag/create`, data })
}
// 修改会员标签
export const updateMemberTag = async (data: TagVO) => {
return await request.put({ url: `/member/tag/update`, data })
}
// 删除会员标签
export const deleteMemberTag = async (id: number) => {
return await request.delete({ url: `/member/tag/delete?id=` + id })
}
// 导出会员标签 Excel
export const exportMemberTag = async (params) => {
return await request.download({ url: `/member/tag/export-excel`, params })
}

View File

@ -0,0 +1,91 @@
<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="name">
<el-input v-model="formData.name" 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 setup lang="ts">
import * as TagApi from '@/api/member/tag'
const { t } = useI18n() //
const message = useMessage() //
const dialogVisible = ref(false) //
const dialogTitle = ref('') //
const formLoading = ref(false) // 12
const formType = ref('') // create - update -
const formData = ref({
id: undefined,
name: undefined
})
const formRules = reactive({
name: [{ required: true, message: '标签名称不能为空', trigger: 'blur' }]
})
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 TagApi.getMemberTag(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 TagApi.TagVO
if (formType.value === 'create') {
await TagApi.createMemberTag(data)
message.success(t('common.createSuccess'))
} else {
await TagApi.updateMemberTag(data)
message.success(t('common.updateSuccess'))
}
dialogVisible.value = false
//
emit('success')
} finally {
formLoading.value = false
}
}
/** 重置表单 */
const resetForm = () => {
formData.value = {
id: undefined,
name: undefined
}
formRef.value?.resetFields()
}
</script>

View File

@ -0,0 +1,69 @@
<template>
<el-select v-model="tagIds" placeholder="请选择用户标签" clearable multiple class="!w-240px">
<el-option v-for="tag in tags" :key="tag.id" :label="tag.name" :value="tag.id" />
</el-select>
<el-button
v-if="showAdd"
type="primary"
class="ml-2"
link
@click="openForm('create')"
v-hasPermi="['member:tag:create']"
>
新增标签
</el-button>
<!-- 表单弹窗添加 -->
<TagForm ref="formRef" @success="getList" />
</template>
<script lang="ts" setup>
import * as TagApi from '@/api/member/tag'
import TagForm from '@/views/member/tag/TagForm.vue'
defineOptions({ name: 'MemberTagSelect' })
const props = defineProps({
/** 下拉框选中值 **/
modelValue: {
type: Array,
default: undefined
},
/** 是否显示“新增标签”按钮 **/
showAdd: {
type: Boolean,
default: false
}
})
const emit = defineEmits(['update:modelValue'])
defineExpose({
showAdd: props.showAdd
})
const tagIds = computed({
get() {
return props.modelValue
},
set(value: any) {
emit('update:modelValue', value)
}
})
const tags = ref<TagApi.TagVO[]>([])
const getList = async () => {
const data = await TagApi.getMemberTagPage({})
tags.value = data.list
}
/** 添加用户标签表单弹框 */
const formRef = ref()
const openForm = (type: string, id?: number) => {
formRef.value.open(type, id)
}
/** 初始化 */
onMounted(() => {
getList()
})
</script>

View File

@ -0,0 +1,179 @@
<template>
<ContentWrap>
<!-- 搜索工作栏 -->
<el-form
class="-mb-15px"
:model="queryParams"
ref="queryFormRef"
:inline="true"
label-width="68px"
>
<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="createTime">
<el-date-picker
v-model="queryParams.createTime"
value-format="YYYY-MM-DD HH:mm:ss"
type="daterange"
start-placeholder="开始日期"
end-placeholder="结束日期"
:default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
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 type="primary" @click="openForm('create')" v-hasPermi="['member:tag:create']">
<Icon icon="ep:plus" class="mr-5px" /> 新增
</el-button>
<el-button
type="success"
plain
@click="handleExport"
:loading="exportLoading"
v-hasPermi="['member:tag:export']"
>
<Icon icon="ep:download" class="mr-5px" /> 导出
</el-button>
</el-form-item>
</el-form>
</ContentWrap>
<!-- 列表 -->
<ContentWrap>
<el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
<el-table-column label="序号" type="index" width="70px" />
<el-table-column label="编号" align="center" prop="id" width="150px" />
<el-table-column label="标签名称" align="center" prop="name" />
<el-table-column
label="创建时间"
align="center"
prop="createTime"
:formatter="dateFormatter"
width="180px"
/>
<el-table-column label="操作" align="center" width="150px">
<template #default="scope">
<el-button
link
type="primary"
@click="openForm('update', scope.row.id)"
v-hasPermi="['member:tag:update']"
>
编辑
</el-button>
<el-button
link
type="danger"
@click="handleDelete(scope.row.id)"
v-hasPermi="['member:tag: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>
<!-- 表单弹窗添加/修改 -->
<TagForm ref="formRef" @success="getList" />
</template>
<script setup lang="ts" name="MemberTag">
import { dateFormatter } from '@/utils/formatTime'
import download from '@/utils/download'
import * as TagApi from '@/api/member/tag'
import TagForm from './TagForm.vue'
const message = useMessage() //
const { t } = useI18n() //
const loading = ref(true) //
const total = ref(0) //
const list = ref([]) //
const queryParams = reactive({
pageNo: 1,
pageSize: 10,
name: null,
createTime: []
})
const queryFormRef = ref() //
const exportLoading = ref(false) //
/** 查询列表 */
const getList = async () => {
loading.value = true
try {
const data = await TagApi.getMemberTagPage(queryParams)
list.value = data.list
total.value = data.total
} finally {
loading.value = false
}
}
/** 搜索按钮操作 */
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 TagApi.deleteMemberTag(id)
message.success(t('common.delSuccess'))
//
await getList()
} catch {}
}
/** 导出按钮操作 */
const handleExport = async () => {
try {
//
await message.exportConfirm()
//
exportLoading.value = true
const data = await TagApi.exportMemberTag(queryParams)
download.excel(data, '会员标签.xls')
} catch {
} finally {
exportLoading.value = false
}
}
/** 初始化 **/
onMounted(() => {
getList()
})
</script>

View File

@ -57,6 +57,9 @@
:render-after-expand="true" :render-after-expand="true"
/> />
</el-form-item> </el-form-item>
<el-form-item label="用户标签" prop="tagIds">
<MemberTagSelect v-model="formData.tagIds" show-add />
</el-form-item>
<el-form-item label="会员备注" prop="mark"> <el-form-item label="会员备注" prop="mark">
<el-input type="textarea" v-model="formData.mark" placeholder="请输入会员备注" /> <el-input type="textarea" v-model="formData.mark" placeholder="请输入会员备注" />
</el-form-item> </el-form-item>
@ -72,6 +75,7 @@ import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import * as UserApi from '@/api/member/user' import * as UserApi from '@/api/member/user'
import * as AreaApi from '@/api/system/area' import * as AreaApi from '@/api/system/area'
import { defaultProps } from '@/utils/tree' import { defaultProps } from '@/utils/tree'
import MemberTagSelect from '@/views/member/tag/components/MemberTagSelect.vue'
const { t } = useI18n() // const { t } = useI18n() //
const message = useMessage() // const message = useMessage() //
@ -90,7 +94,8 @@ const formData = ref({
sex: undefined, sex: undefined,
areaId: undefined, areaId: undefined,
birthday: undefined, birthday: undefined,
mark: undefined mark: undefined,
tagIds: []
}) })
const formRules = reactive({ const formRules = reactive({
mobile: [{ required: true, message: '手机号不能为空', trigger: 'blur' }], mobile: [{ required: true, message: '手机号不能为空', trigger: 'blur' }],
@ -163,7 +168,8 @@ const resetForm = () => {
areaId: undefined, areaId: undefined,
birthday: undefined, birthday: undefined,
mark: undefined, mark: undefined,
createTime: undefined createTime: undefined,
tagIds: []
} }
formRef.value?.resetFields() formRef.value?.resetFields()
} }

View File

@ -48,6 +48,9 @@
class="!w-240px" class="!w-240px"
/> />
</el-form-item> </el-form-item>
<el-form-item label="用户标签" prop="tagIds">
<MemberTagSelect v-model="queryParams.tagIds" />
</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"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button> <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
@ -69,6 +72,16 @@
<!-- TODO 芋艿待接入 --> <!-- TODO 芋艿待接入 -->
<el-table-column label="等级" align="center" width="100px" /> <el-table-column label="等级" align="center" width="100px" />
<el-table-column label="分组" align="center" width="100px" /> <el-table-column label="分组" align="center" width="100px" />
<el-table-column
label="用户标签"
align="center"
prop="tagNames"
:show-overflow-tooltip="false"
>
<template #default="scope">
<el-tag v-for="(tagName, index) in scope.row.tagNames" :key="index">{{ tagName }}</el-tag>
</template>
</el-table-column>
<el-table-column label="积分" align="center" width="100px" /> <el-table-column label="积分" align="center" width="100px" />
<el-table-column label="状态" align="center" prop="status" width="100px"> <el-table-column label="状态" align="center" prop="status" width="100px">
<template #default="scope"> <template #default="scope">
@ -119,6 +132,7 @@ import { dateFormatter } from '@/utils/formatTime'
import * as UserApi from '@/api/member/user' import * as UserApi from '@/api/member/user'
import UserForm from './UserForm.vue' import UserForm from './UserForm.vue'
import { DICT_TYPE } from '@/utils/dict' import { DICT_TYPE } from '@/utils/dict'
import MemberTagSelect from '@/views/member/tag/components/MemberTagSelect.vue'
defineOptions({ name: 'MemberUser' }) defineOptions({ name: 'MemberUser' })
@ -134,7 +148,8 @@ const queryParams = reactive({
nickname: null, nickname: null,
mobile: null, mobile: null,
loginDate: [], loginDate: [],
createTime: [] createTime: [],
tagIds: []
}) })
const queryFormRef = ref() // const queryFormRef = ref() //
const exportLoading = ref(false) // const exportLoading = ref(false) //