allow give point directly

This commit is contained in:
2024-02-24 12:02:46 +08:00
parent ecf3a16586
commit 690ff14f1f
3 changed files with 100 additions and 20 deletions

View File

@@ -127,12 +127,9 @@ export class GuidUtils {
// 将GUID转换为数字 // 将GUID转换为数字
public static guidToLong(guid: string): number { public static guidToLong(guid: string): number {
if (!GuidUtils.isGuidFromUserId(guid)) {
throw new Error('The provided GUID was not generated from a long value.')
}
const buffer = GuidUtils.guidToBuffer(guid) const buffer = GuidUtils.guidToBuffer(guid)
const view = new DataView(buffer) const view = new DataView(buffer)
return Number(view.getBigUint64(8)) // 读取后8个字节的long值 return Number(view.getBigUint64(8))
} }
// 辅助方法将ArrayBuffer转换为GUID字符串 // 辅助方法将ArrayBuffer转换为GUID字符串
@@ -140,7 +137,7 @@ export class GuidUtils {
const bytes = new Uint8Array(buffer) const bytes = new Uint8Array(buffer)
const guid = bytes.reduce((str, byte, idx) => { const guid = bytes.reduce((str, byte, idx) => {
const pair = byte.toString(16).padStart(2, '0') const pair = byte.toString(16).padStart(2, '0')
return str + (idx === 4 || idx === 6 || idx === 8 || idx === 10 ? '-' : '') + pair return str + pair + (idx === 3 || idx === 5 || idx === 7 || idx === 9 ? '-' : '')
}, '') }, '')
return guid return guid
} }

View File

@@ -1,4 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import { GuidUtils } from '@/Utils'
import { import {
ResponsePointGoodModel, ResponsePointGoodModel,
ResponsePointHisrotyModel, ResponsePointHisrotyModel,
@@ -98,11 +99,26 @@ async function givePoint() {
} }
isLoading.value = true isLoading.value = true
try { try {
const data = await QueryGetAPI(POINT_API_URL + 'give-point', { const data = await QueryGetAPI(
POINT_API_URL + 'give-point',
props.user.info?.id >= 0
? {
authId: props.user.info?.id, authId: props.user.info?.id,
count: addPointCount.value, count: addPointCount.value,
reason: addPointReason.value, reason: addPointReason.value ?? '',
}) }
: props.user.info?.userId
? {
uId: props.user.info?.userId,
count: addPointCount.value,
reason: addPointReason.value ?? '',
}
: {
oId: props.user.info?.openId,
count: addPointCount.value,
reason: addPointReason.value ?? '',
},
)
if (data.code == 200) { if (data.code == 200) {
message.success('添加成功') message.success('添加成功')
showAddPointModal.value = false showAddPointModal.value = false
@@ -160,14 +176,7 @@ onMounted(async () => {
</NDescriptions> </NDescriptions>
<template #footer> <template #footer>
<NFlex> <NFlex>
<NTooltip :disabled="user.isAuthed"> <NButton type="primary" @click="showAddPointModal = true" size="small"> 给予积分 </NButton>
<template #trigger>
<NButton type="primary" @click="showAddPointModal = true" :disabled="!user.isAuthed" size="small">
给予积分
</NButton>
</template>
<NText> 未认证用户无法给予积分 </NText>
</NTooltip>
</NFlex> </NFlex>
</template> </template>
</NCard> </NCard>

View File

@@ -12,6 +12,10 @@ import {
NDivider, NDivider,
NEmpty, NEmpty,
NFlex, NFlex,
NInput,
NInputGroup,
NInputGroupLabel,
NInputNumber,
NModal, NModal,
NPopconfirm, NPopconfirm,
NScrollbar, NScrollbar,
@@ -42,8 +46,13 @@ const settings = useStorage<PointUserSettings>('Settings.Point.Users', JSON.pars
const pn = ref(1) const pn = ref(1)
const ps = ref(25) const ps = ref(25)
const showModal = ref(false) const showModal = ref(false)
const showGivePointModal = ref(false)
const isLoading = ref(true) const isLoading = ref(true)
const addPointCount = ref(0)
const addPointReason = ref<string>()
const addPointTarget = ref<number>()
const users = ref<ResponsePointUserModel[]>([]) const users = ref<ResponsePointUserModel[]>([])
const filteredUsers = computed(() => { const filteredUsers = computed(() => {
return users.value return users.value
@@ -137,9 +146,42 @@ async function getUsers() {
} }
return [] return []
} }
async function refresh() {
users.value = await getUsers()
}
async function givePoint() {
if (addPointCount.value <= 0) {
message.error('积分数量必须大于0')
return
}
if (!addPointTarget.value) {
message.error('请输入用户')
}
isLoading.value = true
try {
const data = await QueryGetAPI(POINT_API_URL + 'give-point', {
uId: addPointTarget.value,
count: addPointCount.value,
reason: addPointReason.value,
})
if (data.code == 200) {
message.success('添加成功')
showGivePointModal.value = false
await refresh()
addPointCount.value = 0
addPointReason.value = undefined
addPointTarget.value = undefined
} else {
message.error('添加失败: ' + data.message)
}
} catch (err) {
message.error('添加失败: ' + err)
}
}
onMounted(async () => { onMounted(async () => {
users.value = await getUsers() await refresh()
}) })
</script> </script>
@@ -154,13 +196,19 @@ onMounted(async () => {
<span>确定要恢复默认设置吗?</span> <span>确定要恢复默认设置吗?</span>
</NPopconfirm> </NPopconfirm>
</template> </template>
<template #footer>
<NFlex>
<NButton type="primary" @click="refresh">刷新</NButton>
<NButton type="info" @click="showGivePointModal = true">给予积分</NButton>
</NFlex>
</template>
<NFlex> <NFlex>
<NCheckbox v-model:checked="settings.onlyAuthed"> 只显示已认证用户 </NCheckbox> <NCheckbox v-model:checked="settings.onlyAuthed"> 只显示已认证用户 </NCheckbox>
</NFlex> </NFlex>
</NCard> </NCard>
<template v-if="filteredUsers.length == 0"> <template v-if="filteredUsers.length == 0">
<NDivider /> <NDivider />
<NEmpty description="暂无用户" /> <NEmpty :description="settings.onlyAuthed ? '没有已认证的用户' : '没有用户'" />
</template> </template>
<NDataTable <NDataTable
v-else v-else
@@ -181,4 +229,30 @@ onMounted(async () => {
<PointUserDetailCard v-if="currentUser" :user="currentUser" :authInfo="currentUser.info" :goods="goods" /> <PointUserDetailCard v-if="currentUser" :user="currentUser" :authInfo="currentUser.info" :goods="goods" />
</NScrollbar> </NScrollbar>
</NModal> </NModal>
<NModal v-model:show="showGivePointModal" preset="card" style="max-width: 500px" title="给予积分">
<NFlex vertical>
<NInputGroup>
<NInputGroupLabel> 目标用户 </NInputGroupLabel>
<NInputNumber
v-model:value="addPointTarget"
type="number"
placeholder="请输入目标用户UId"
min="0"
style="max-width: 200px"
/>
</NInputGroup>
<NInputGroup>
<NInputGroupLabel> 积分数量 </NInputGroupLabel>
<NInputNumber
v-model:value="addPointCount"
type="number"
placeholder="请输入积分数量"
min="0"
style="max-width: 120px"
/>
</NInputGroup>
<NInput placeholder="(选填) 请输入备注" v-model:value="addPointReason" :maxlength="100" show-count clearable />
<NButton type="primary" @click="givePoint" :loading="isLoading"> 给予 </NButton>
</NFlex>
</NModal>
</template> </template>