新增社交用户 RUD

(cherry picked from commit 6ee2492ff1)
This commit is contained in:
puhui999 2023-10-25 17:02:11 +08:00 committed by shizhong
parent 212d40f290
commit ca7c311f88
3 changed files with 377 additions and 0 deletions

View File

@ -0,0 +1,34 @@
import request from '@/config/axios'
export interface SocialUserVO {
id: number
type: number
openid: string
token: string
rawTokenInfo: string
nickname: string
avatar: string
rawUserInfo: string
code: string
state: string
}
// 查询社交用户列表
export const getSocialUserPage = async (params) => {
return await request.get({ url: `/system/social-user/page`, params })
}
// 查询社交用户详情
export const getSocialUser = async (id: number) => {
return await request.get({ url: `/system/social-user/get?id=` + id })
}
// 修改社交用户
export const updateSocialUser = async (data: SocialUserVO) => {
return await request.put({ url: `/system/social-user/update`, data })
}
// 删除社交用户
export const deleteSocialUser = async (id: number) => {
return await request.delete({ url: `/system/social-user/delete?id=` + id })
}

View File

@ -0,0 +1,139 @@
<template>
<Dialog v-model="dialogVisible" :title="dialogTitle">
<el-form
ref="formRef"
v-loading="formLoading"
:model="formData"
:rules="formRules"
label-width="150px"
>
<el-form-item label="社交平台" prop="type">
<el-radio-group v-model="formData.type">
<el-radio
v-for="dict in getIntDictOptions(DICT_TYPE.SYSTEM_SOCIAL_CLIENT_TYPE)"
:key="dict.value"
:label="dict.value"
>
{{ dict.label }}
</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="社交 openid" prop="openid">
<el-input v-model="formData.openid" placeholder="请输入社交 openid" />
</el-form-item>
<el-form-item label="社交 token" prop="token">
<el-input v-model="formData.token" placeholder="请输入社交 token" />
</el-form-item>
<el-form-item label="原始 Token 数据" prop="rawTokenInfo">
<el-input v-model="formData.rawTokenInfo" placeholder="请输入原始 Token 数据" />
</el-form-item>
<el-form-item label="用户昵称" prop="nickname">
<el-input v-model="formData.nickname" placeholder="请输入用户昵称" />
</el-form-item>
<el-form-item label="用户头像" prop="avatar">
<el-input v-model="formData.avatar" placeholder="请输入用户头像" />
</el-form-item>
<el-form-item label="原始用户数据" prop="rawUserInfo">
<el-input v-model="formData.rawUserInfo" placeholder="请输入原始用户数据" />
</el-form-item>
<el-form-item label="最后一次的认证 code" prop="code">
<el-input v-model="formData.code" placeholder="请输入最后一次的认证 code" />
</el-form-item>
<el-form-item label="最后一次的认证 state" prop="state">
<el-input v-model="formData.state" placeholder="请输入最后一次的认证 state" />
</el-form-item>
</el-form>
<template #footer>
<el-button :disabled="formLoading" type="primary" @click="submitForm"> </el-button>
<el-button @click="dialogVisible = false"> </el-button>
</template>
</Dialog>
</template>
<script lang="ts" setup>
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import * as SocialUserApi from '@/api/system/social/user'
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,
type: undefined,
openid: undefined,
token: undefined,
rawTokenInfo: undefined,
nickname: undefined,
avatar: undefined,
rawUserInfo: undefined,
code: undefined,
state: 0
})
const formRules = reactive({
type: [{ required: true, message: '社交平台不能为空', trigger: 'blur' }],
openid: [{ required: true, message: '社交 openid 不能为空', trigger: 'blur' }],
nickname: [{ 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 SocialUserApi.getSocialUser(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 SocialUserApi.SocialUserVO
if (formType.value === 'update') {
await SocialUserApi.updateSocialUser(data)
message.success(t('common.updateSuccess'))
}
dialogVisible.value = false
//
emit('success')
} finally {
formLoading.value = false
}
}
/** 重置表单 */
const resetForm = () => {
formData.value = {
id: undefined,
type: undefined,
openid: undefined,
token: undefined,
rawTokenInfo: undefined,
nickname: undefined,
avatar: undefined,
rawUserInfo: undefined,
code: undefined,
state: 0
}
formRef.value?.resetFields()
}
</script>

View File

@ -0,0 +1,204 @@
<template>
<ContentWrap>
<!-- 搜索工作栏 -->
<el-form
ref="queryFormRef"
:inline="true"
:model="queryParams"
class="-mb-15px"
label-width="68px"
>
<el-form-item label="社交平台" prop="type">
<el-select
v-model="queryParams.type"
class="!w-240px"
clearable
placeholder="请选择社交平台"
>
<el-option
v-for="dict in getIntDictOptions(DICT_TYPE.SYSTEM_SOCIAL_CLIENT_TYPE)"
:key="dict.value"
:label="dict.label"
:value="dict.value"
/>
</el-select>
</el-form-item>
<el-form-item label="用户昵称" prop="nickname">
<el-input
v-model="queryParams.nickname"
class="!w-240px"
clearable
placeholder="请输入用户昵称"
@keyup.enter="handleQuery"
/>
</el-form-item>
<el-form-item label="创建时间" prop="createTime">
<el-date-picker
v-model="queryParams.createTime"
:default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
class="!w-240px"
end-placeholder="结束日期"
start-placeholder="开始日期"
type="daterange"
value-format="YYYY-MM-DD HH:mm:ss"
/>
</el-form-item>
<el-form-item>
<el-button @click="handleQuery">
<Icon class="mr-5px" icon="ep:search" />
搜索
</el-button>
<el-button @click="resetQuery">
<Icon class="mr-5px" icon="ep:refresh" />
重置
</el-button>
</el-form-item>
</el-form>
</ContentWrap>
<!-- 列表 -->
<ContentWrap>
<el-table v-loading="loading" :data="list" :show-overflow-tooltip="true" :stripe="true">
<el-table-column align="center" label="社交平台" prop="type">
<template #default="scope">
<dict-tag :type="DICT_TYPE.SYSTEM_SOCIAL_CLIENT_TYPE" :value="scope.row.type" />
</template>
</el-table-column>
<el-table-column align="center" label="社交 openid" prop="openid" />
<el-table-column align="center" label="社交 token" prop="token" />
<el-table-column align="center" label="原始 Token 数据" prop="rawTokenInfo" />
<el-table-column align="center" label="用户昵称" prop="nickname" />
<el-table-column align="center" label="用户头像" prop="avatar">
<template #default="{ row }">
<el-image :src="row.avatar" class="h-30px w-30px" @click="imagePreview(row.avatar)" />
</template>
</el-table-column>
<el-table-column align="center" label="原始用户数据" prop="rawUserInfo" />
<el-table-column align="center" label="最后一次的认证 code" prop="code" />
<el-table-column align="center" label="最后一次的认证 state" prop="state" />
<el-table-column
:formatter="dateFormatter"
align="center"
label="创建时间"
prop="createTime"
width="180px"
/>
<el-table-column align="center" fixed="right" label="操作">
<template #default="scope">
<el-button
v-hasPermi="['system:social-user:update']"
link
type="primary"
@click="openForm('update', scope.row.id)"
>
编辑
</el-button>
<el-button
v-hasPermi="['system:social-user:delete']"
link
type="danger"
@click="handleDelete(scope.row.id)"
>
删除
</el-button>
</template>
</el-table-column>
</el-table>
<!-- 分页 -->
<Pagination
v-model:limit="queryParams.pageSize"
v-model:page="queryParams.pageNo"
:total="total"
@pagination="getList"
/>
</ContentWrap>
<!-- 表单弹窗添加/修改 -->
<SocialUserForm ref="formRef" @success="getList" />
</template>
<script lang="ts" setup>
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import { dateFormatter } from '@/utils/formatTime'
import * as SocialUserApi from '@/api/system/social/user'
import SocialUserForm from './SocialUserForm.vue'
import { createImageViewer } from '@/components/ImageViewer'
defineOptions({ name: 'SocialUser' })
const message = useMessage() //
const { t } = useI18n() //
const loading = ref(true) //
const total = ref(0) //
const list = ref([]) //
const queryParams = reactive({
pageNo: 1,
pageSize: 10,
type: undefined,
openid: undefined,
token: undefined,
rawTokenInfo: undefined,
nickname: undefined,
avatar: undefined,
rawUserInfo: undefined,
code: undefined,
state: undefined,
createTime: []
})
const queryFormRef = ref() //
/** 查询列表 */
const getList = async () => {
loading.value = true
try {
const data = await SocialUserApi.getSocialUserPage(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 imagePreview = (imgUrl: string) => {
createImageViewer({
urlList: [imgUrl]
})
}
/** 修改操作 */
const formRef = ref()
const openForm = (type: string, id?: number) => {
formRef.value.open(type, id)
}
/** 删除按钮操作 */
const handleDelete = async (id: number) => {
try {
//
await message.delConfirm()
//
await SocialUserApi.deleteSocialUser(id)
message.success(t('common.delSuccess'))
//
await getList()
} catch {}
}
/** 初始化 **/
onMounted(() => {
getList()
})
</script>