22import { onMounted , ref , useTemplateRef } from ' vue'
33import ChatUserApi from ' @/api/admin/system/chat-user'
44import type { ChatUser , LoginMethod , OptionItem , RequestParams } from ' @/api/types'
5- import { LOGIN_METHOD } from ' @/api/enums'
5+ import { LOGIN_METHOD , QUOTA_TYPE } from ' @/api/enums'
66import { LOGIN_METHOD_LABELS } from ' @/constants'
77import { datetimeFormat } from ' @/utils/time'
88import { MsgConfirm , MsgSuccess } from ' @/utils/message'
@@ -57,6 +57,32 @@ const searchFields: OptionItem<string>[] = [
5757]
5858const chatUserQuery = ref <RequestParams >()
5959
60+ function formatTokenAmount(value ? : number | null ) {
61+ if (typeof value !== ' number' || Number .isNaN (value )) return ' -'
62+ const units = [' ' , ' K' , ' M' , ' B' , ' T' ]
63+ let unitIndex = 0
64+ let num = value
65+ let abs = Math .abs (value )
66+ while (abs >= 1000 && unitIndex < units .length - 1 ) {
67+ num /= 1000
68+ abs /= 1000
69+ unitIndex ++
70+ }
71+ if (unitIndex === 0 ) return String (Math .round (num ))
72+ return ` ${num .toFixed (1 )}${units [unitIndex ]} `
73+ }
74+
75+ function formatPeriodEnd(value ? : string | null ) {
76+ return value ? datetimeFormat (value ) : ' -'
77+ }
78+
79+ function formatQuotaUsage(tokenQuota ? : ChatUser [' token_quota' ]) {
80+ if (! tokenQuota ) return ' -'
81+ const used = formatTokenAmount (tokenQuota .used_tokens )
82+ if (tokenQuota .quota_type === QUOTA_TYPE .UNLIMITED ) return ` ${used } / ∞ `
83+ return ` ${used } / ${formatTokenAmount (tokenQuota .token_limit )} `
84+ }
85+
6086function handleSearchChange(query ? : RequestParams ) {
6187 chatUserQuery .value = query
6288 paginationConfig .value .currentPage = 1
@@ -155,6 +181,10 @@ function openBatchSetUserGroupDialog() {
155181 batchSetUserGroupDialogRef .value ?.open (batchSelectedUsers .value .map (({ id }) => id ))
156182}
157183
184+ function openBatchQuotaSettingsDialog() {
185+ quotaSettingsDialogRef .value ?.open (batchSelectedUsers .value .map (({ id }) => id ))
186+ }
187+
158188onMounted (() => loadChatUsers ())
159189 </script >
160190
@@ -222,6 +252,18 @@ onMounted(() => loadChatUsers())
222252 </template >
223253 </el-table-column >
224254
255+ <el-table-column label =" Tokens使用量/总量" min-width =" 150" >
256+ <template #default =" { row } " >
257+ {{ formatQuotaUsage(row.token_quota) }}
258+ </template >
259+ </el-table-column >
260+
261+ <el-table-column label =" Tokens到期时间" min-width =" 180" >
262+ <template #default =" { row } " >
263+ {{ formatPeriodEnd(row.token_quota?.period_end) }}
264+ </template >
265+ </el-table-column >
266+
225267 <el-table-column label =" 创建时间" width =" 180" >
226268 <template #default =" { row } " >
227269 {{ datetimeFormat(row.create_time) }}
@@ -273,6 +315,9 @@ onMounted(() => loadChatUsers())
273315 <el-button type =" primary" plain @click =" openBatchSetUserGroupDialog" >
274316 设置用户组
275317 </el-button >
318+ <el-button type =" primary" plain @click =" openBatchQuotaSettingsDialog" >
319+ 配额设置
320+ </el-button >
276321 <el-button type =" danger" plain @click =" handleBatchDelete" >删除</el-button >
277322 </template >
278323 </MkTable >
@@ -282,5 +327,5 @@ onMounted(() => loadChatUsers())
282327 <ImportUsersDialog ref="importUsersDialogRef" @refresh =" loadChatUsers (true )" />
283328 <UserPwdDialog ref="userPwdDialogRef" @refresh =" loadChatUsers (false )" />
284329 <BatchSetUserGroupDialog ref="batchSetUserGroupDialogRef" @refresh =" loadChatUsers (false )" />
285- <QuotaSettingsDialog ref="quotaSettingsDialogRef" />
330+ <QuotaSettingsDialog ref="quotaSettingsDialogRef" @ refresh = " loadChatUsers " />
286331</template >
0 commit comments