index.vue 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148
  1. <template>
  2. <view class="page-admin" :class="themeClass">
  3. <!-- ===== Login Screen ===== -->
  4. <view v-if="!authenticated" class="login-screen">
  5. <view class="login-card">
  6. <text class="login-title">管理后台</text>
  7. <text class="login-subtitle">数字能量学系统</text>
  8. <view class="login-form">
  9. <view class="login-field">
  10. <text class="field-label">用户名</text>
  11. <input
  12. class="field-input"
  13. v-model="loginForm.username"
  14. placeholder="请输入管理员账号"
  15. placeholder-class="placeholder-style"
  16. @confirm="handleLogin"
  17. />
  18. </view>
  19. <view class="login-field">
  20. <text class="field-label">密码</text>
  21. <input
  22. class="field-input"
  23. type="password"
  24. v-model="loginForm.password"
  25. placeholder="请输入密码"
  26. placeholder-class="placeholder-style"
  27. @confirm="handleLogin"
  28. />
  29. </view>
  30. <view class="login-error" v-if="loginError">
  31. <text class="login-error-text">{{ loginError }}</text>
  32. </view>
  33. <button
  34. class="login-btn"
  35. :disabled="loggingIn"
  36. @click="handleLogin"
  37. >
  38. <text v-if="loggingIn">登录中...</text>
  39. <text v-else>登 录</text>
  40. </button>
  41. </view>
  42. </view>
  43. </view>
  44. <!-- ===== Main Admin Dashboard ===== -->
  45. <view v-else class="dashboard">
  46. <!-- Refresh indicator -->
  47. <view v-if="loading" class="loading-state">
  48. <text class="loading-text">加载中...</text>
  49. </view>
  50. <template v-else>
  51. <!-- ===== Stats Grid ===== -->
  52. <view class="stats-grid">
  53. <view class="stat-card">
  54. <text class="stat-value accent-blue">{{ stats.totalUsers }}</text>
  55. <text class="stat-label">总用户数</text>
  56. </view>
  57. <view class="stat-card">
  58. <text class="stat-value accent-green">{{ stats.vipUsers }}</text>
  59. <text class="stat-label">VIP 用户</text>
  60. </view>
  61. <view class="stat-card">
  62. <text class="stat-value accent-amber">{{ stats.totalOrders }}</text>
  63. <text class="stat-label">总订单</text>
  64. </view>
  65. <view class="stat-card">
  66. <text class="stat-value accent-rose">{{ formatMoney(stats.totalRevenue) }}</text>
  67. <text class="stat-label">总收入 (¥)</text>
  68. </view>
  69. <view class="stat-card">
  70. <text class="stat-value accent-blue">{{ stats.totalCharts }}</text>
  71. <text class="stat-label">能量盘总数</text>
  72. </view>
  73. <view class="stat-card">
  74. <text class="stat-value accent-green">{{ stats.totalCommissions }}</text>
  75. <text class="stat-label">佣金笔数</text>
  76. </view>
  77. </view>
  78. <!-- ===== Recent Orders Preview ===== -->
  79. <view class="section-card" v-if="stats.recentOrders && stats.recentOrders.length > 0">
  80. <view class="section-header">
  81. <text class="section-title">最近订单</text>
  82. </view>
  83. <view
  84. v-for="(order, idx) in stats.recentOrders.slice(0, 5)"
  85. :key="idx"
  86. class="mini-row"
  87. >
  88. <view class="mini-left">
  89. <text class="mini-label">#{{ order.id }}</text>
  90. <text class="mini-desc">{{ order.productType || '--' }}</text>
  91. </view>
  92. <view class="mini-right">
  93. <text class="mini-value accent-amber">¥{{ formatMoney(order.totalFee) }}</text>
  94. <text class="mini-status" :class="'status-' + order.status">
  95. {{ orderStatusLabel(order.status) }}
  96. </text>
  97. </view>
  98. </view>
  99. </view>
  100. <!-- ===== Tab Navigation ===== -->
  101. <view class="tab-bar">
  102. <view
  103. v-for="tab in tabs"
  104. :key="tab.key"
  105. class="tab-item"
  106. :class="{ 'tab-active': currentTab === tab.key }"
  107. @click="currentTab = tab.key"
  108. >
  109. <text class="tab-text">{{ tab.label }}</text>
  110. </view>
  111. </view>
  112. <!-- ===== Users Tab ===== -->
  113. <view v-show="currentTab === 'users'" class="tab-content">
  114. <view v-if="users.length === 0" class="empty-state">
  115. <text class="empty-text">暂无用户数据</text>
  116. </view>
  117. <view v-for="(user, idx) in users" :key="user.id || idx" class="data-card">
  118. <view class="data-row">
  119. <view class="data-left">
  120. <view class="data-info">
  121. <text class="data-primary">
  122. {{ user.nickname || '微信用户' }}
  123. <text v-if="user.isAdmin" class="badge-admin">管理员</text>
  124. </text>
  125. <text class="data-meta">ID: {{ user.id }} | 注册: {{ formatDate(user.createdAt) }}</text>
  126. </view>
  127. </view>
  128. <view class="data-right">
  129. <text
  130. class="tag-vip"
  131. :class="{ 'tag-vip-active': isVipActive(user) }"
  132. >
  133. {{ isVipActive(user) ? 'VIP' : '普通' }}
  134. </text>
  135. </view>
  136. </view>
  137. <view class="action-row">
  138. <button
  139. v-if="!isVipActive(user)"
  140. class="btn btn-sm btn-green"
  141. :disabled="actionLoading.userId === user.id"
  142. @click="handleUpgrade(user.id)"
  143. >
  144. {{ actionLoading.userId === user.id && actionLoading.type === 'upgrade' ? '...' : '升级VIP' }}
  145. </button>
  146. <button
  147. v-if="isVipActive(user)"
  148. class="btn btn-sm btn-red-outline"
  149. :disabled="actionLoading.userId === user.id"
  150. @click="handleDowngrade(user.id)"
  151. >
  152. {{ actionLoading.userId === user.id && actionLoading.type === 'downgrade' ? '...' : '取消VIP' }}
  153. </button>
  154. <button
  155. class="btn btn-sm"
  156. :class="user.isAdmin ? 'btn-amber-outline' : 'btn-blue-outline'"
  157. :disabled="actionLoading.userId === user.id"
  158. @click="handleToggleAdmin(user)"
  159. >
  160. {{
  161. actionLoading.userId === user.id && actionLoading.type === 'set-admin'
  162. ? '...'
  163. : (user.isAdmin ? '取消管理' : '设为管理')
  164. }}
  165. </button>
  166. </view>
  167. </view>
  168. </view>
  169. <!-- ===== Orders Tab ===== -->
  170. <view v-show="currentTab === 'orders'" class="tab-content">
  171. <view v-if="orders.length === 0" class="empty-state">
  172. <text class="empty-text">暂无订单数据</text>
  173. </view>
  174. <view v-for="(order, idx) in orders" :key="order.id || idx" class="data-card">
  175. <view class="data-row">
  176. <view class="data-left">
  177. <view class="data-info">
  178. <text class="data-primary">订单 #{{ order.id }}</text>
  179. <text class="data-meta">
  180. 用户ID: {{ order.userId }} | {{ order.productType || '--' }}
  181. </text>
  182. </view>
  183. </view>
  184. <view class="data-right">
  185. <text class="data-price">¥{{ formatMoney(order.totalFee) }}</text>
  186. <text class="tag-status" :class="'tag-status-' + order.status">
  187. {{ orderStatusLabel(order.status) }}
  188. </text>
  189. </view>
  190. </view>
  191. <view class="data-extras" v-if="order.paidAt || order.createdAt">
  192. <text class="data-meta" v-if="order.paidAt">支付时间: {{ formatDate(order.paidAt) }}</text>
  193. <text class="data-meta" v-else>创建时间: {{ formatDate(order.createdAt) }}</text>
  194. </view>
  195. </view>
  196. </view>
  197. <!-- ===== Commissions Tab ===== -->
  198. <view v-show="currentTab === 'commissions'" class="tab-content">
  199. <view v-if="commissions.length === 0" class="empty-state">
  200. <text class="empty-text">暂无佣金数据</text>
  201. </view>
  202. <view v-for="(comm, idx) in commissions" :key="comm.id || idx" class="data-card">
  203. <view class="data-row">
  204. <view class="data-left">
  205. <view class="data-info">
  206. <text class="data-primary">用户 #{{ comm.userId }}</text>
  207. <text class="data-meta">
  208. 级别: {{ comm.level === 1 ? '一级推广' : '二级推广' }}
  209. <text v-if="comm.remark"> | {{ comm.remark }}</text>
  210. </text>
  211. </view>
  212. </view>
  213. <view class="data-right">
  214. <text class="data-price accent-green">+¥{{ formatMoney(comm.amount) }}</text>
  215. <text class="tag-status" :class="'tag-status-' + comm.status">
  216. {{ commissionStatusLabel(comm.status) }}
  217. </text>
  218. </view>
  219. </view>
  220. <view class="data-extras">
  221. <text class="data-meta">{{ formatDate(comm.createdAt) }}</text>
  222. </view>
  223. </view>
  224. </view>
  225. <!-- ===== Withdraws Tab ===== -->
  226. <view v-show="currentTab === 'withdraws'" class="tab-content">
  227. <view v-if="withdraws.length === 0" class="empty-state">
  228. <text class="empty-text">暂无提现申请</text>
  229. </view>
  230. <view v-for="(wd, idx) in withdraws" :key="wd.id || idx" class="data-card">
  231. <view class="data-row">
  232. <view class="data-left">
  233. <view class="data-info">
  234. <text class="data-primary">提现 #{{ wd.id }}</text>
  235. <text class="data-meta">用户ID: {{ wd.userId }}</text>
  236. </view>
  237. </view>
  238. <view class="data-right">
  239. <text class="data-price">¥{{ formatMoney(wd.amount) }}</text>
  240. <text class="tag-status" :class="'tag-status-' + wd.status">
  241. {{ withdrawStatusLabel(wd.status) }}
  242. </text>
  243. </view>
  244. </view>
  245. <view class="data-extras">
  246. <text class="data-meta">{{ formatDate(wd.createdAt) }}</text>
  247. </view>
  248. <view class="action-row" v-if="wd.status === 'pending'">
  249. <button
  250. class="btn btn-sm btn-green"
  251. :disabled="actionLoading.withdrawId === wd.id"
  252. @click="handleApproveWithdraw(wd.id)"
  253. >
  254. {{ actionLoading.withdrawId === wd.id && actionLoading.type === 'approve' ? '...' : '批准' }}
  255. </button>
  256. <button
  257. class="btn btn-sm btn-red-outline"
  258. :disabled="actionLoading.withdrawId === wd.id"
  259. @click="handleRejectWithdraw(wd.id)"
  260. >
  261. {{ actionLoading.withdrawId === wd.id && actionLoading.type === 'reject' ? '...' : '拒绝' }}
  262. </button>
  263. </view>
  264. </view>
  265. </view>
  266. <!-- ===== Config Tab ===== -->
  267. <view v-show="currentTab === 'config'" class="tab-content">
  268. <view v-if="configs.length === 0" class="empty-state">
  269. <text class="empty-text">暂无系统配置</text>
  270. </view>
  271. <view v-for="(cfg, idx) in configs" :key="cfg.id || idx" class="data-card">
  272. <view class="config-row">
  273. <view class="config-header">
  274. <text class="data-primary">{{ cfg.configKey }}</text>
  275. <button
  276. class="btn btn-xxs btn-amber-outline"
  277. :disabled="configResetting === cfg.configKey"
  278. @click="handleResetConfig(cfg.configKey)"
  279. >
  280. {{ configResetting === cfg.configKey ? '...' : '重置' }}
  281. </button>
  282. </view>
  283. <view class="config-value-row">
  284. <input
  285. class="config-input"
  286. v-model="configEdits[cfg.configKey]"
  287. :placeholder="cfg.configValue || '输入值'"
  288. placeholder-class="placeholder-style"
  289. />
  290. <button
  291. class="btn btn-xxs btn-green"
  292. :disabled="configSaving === cfg.configKey || configEdits[cfg.configKey] === cfg.configValue"
  293. @click="handleSaveConfig(cfg.configKey)"
  294. >
  295. {{ configSaving === cfg.configKey ? '...' : '保存' }}
  296. </button>
  297. </view>
  298. <text class="data-meta config-desc" v-if="cfg.description">{{ cfg.description }}</text>
  299. <text class="data-meta config-desc" v-if="cfg.defaultValue">默认值: {{ cfg.defaultValue }}</text>
  300. </view>
  301. </view>
  302. </view>
  303. </template>
  304. </view>
  305. <!-- ===== Admin logout hint ===== -->
  306. <view v-if="authenticated" class="logout-bar" @click="handleLogout">
  307. <text class="logout-text">退出登录</text>
  308. </view>
  309. </view>
  310. </template>
  311. <script setup>
  312. import { ref, reactive, computed, onMounted } from 'vue'
  313. import { onPullDownRefresh } from '@dcloudio/uni-app'
  314. import { adminApi } from '@/utils/api'
  315. import { useTheme } from '@/composables/useThemeStyle'
  316. const { themeClass } = useTheme()
  317. // ─── Auth State ───
  318. const authenticated = ref(!!uni.getStorageSync('adminToken'))
  319. const loginForm = reactive({ username: '', password: '' })
  320. const loggingIn = ref(false)
  321. const loginError = ref('')
  322. // ─── Data State ───
  323. const loading = ref(true)
  324. const stats = reactive({
  325. totalUsers: 0,
  326. vipUsers: 0,
  327. totalOrders: 0,
  328. totalRevenue: 0,
  329. totalCharts: 0,
  330. totalCommissions: 0,
  331. recentOrders: []
  332. })
  333. const users = ref([])
  334. const orders = ref([])
  335. const commissions = ref([])
  336. const withdraws = ref([])
  337. const configs = ref([])
  338. // ─── UI State ───
  339. const currentTab = ref('users')
  340. const actionLoading = reactive({ userId: null, withdrawId: null, type: null })
  341. const configResetting = ref(null)
  342. const configSaving = ref(null)
  343. const configEdits = reactive({})
  344. const tabs = [
  345. { key: 'users', label: '用户管理' },
  346. { key: 'orders', label: '订单管理' },
  347. { key: 'commissions', label: '佣金记录' },
  348. { key: 'withdraws', label: '提现审核' },
  349. { key: 'config', label: '系统配置' }
  350. ]
  351. // ─── Helpers ───
  352. function formatMoney(cents) {
  353. if (cents == null) return '0.00'
  354. return (cents / 100).toFixed(2)
  355. }
  356. function formatDate(dateStr) {
  357. if (!dateStr) return '--'
  358. const d = new Date(dateStr)
  359. if (isNaN(d.getTime())) return '--'
  360. return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`
  361. }
  362. function isVipActive(user) {
  363. if (!user.vipEndTime) return false
  364. return new Date(user.vipEndTime) > new Date()
  365. }
  366. function orderStatusLabel(status) {
  367. const map = { paid: '已支付', unpaid: '未支付', cancelled: '已取消', refunded: '已退款', pending: '处理中' }
  368. return map[status] || status || '未知'
  369. }
  370. function commissionStatusLabel(status) {
  371. const map = { settled: '已结算', pending: '处理中', withdrawn: '已提现', available: '可提现' }
  372. return map[status] || status || '未知'
  373. }
  374. function withdrawStatusLabel(status) {
  375. const map = { pending: '待审核', approved: '已批准', rejected: '已拒绝', completed: '已完成' }
  376. return map[status] || status || '未知'
  377. }
  378. // ─── Auth ───
  379. async function handleLogin() {
  380. if (!loginForm.username || !loginForm.password) {
  381. loginError.value = '请输入用户名和密码'
  382. return
  383. }
  384. loginError.value = ''
  385. loggingIn.value = true
  386. try {
  387. const result = await adminApi.login(loginForm.username, loginForm.password)
  388. uni.setStorageSync('adminToken', result.token)
  389. authenticated.value = true
  390. await fetchAllData()
  391. } catch (e) {
  392. loginError.value = e.message || '登录失败,请检查账号密码'
  393. } finally {
  394. loggingIn.value = false
  395. }
  396. }
  397. function handleLogout() {
  398. uni.showModal({
  399. title: '退出登录',
  400. content: '确定要退出管理后台吗?',
  401. success: (res) => {
  402. if (res.confirm) {
  403. uni.removeStorageSync('adminToken')
  404. authenticated.value = false
  405. loginForm.username = ''
  406. loginForm.password = ''
  407. }
  408. }
  409. })
  410. }
  411. // ─── Data Fetching ───
  412. async function fetchAllData() {
  413. loading.value = true
  414. try {
  415. const [
  416. statsData,
  417. usersData,
  418. ordersData,
  419. commissionsData,
  420. withdrawsData,
  421. configsData
  422. ] = await Promise.all([
  423. adminApi.stats(),
  424. adminApi.users(),
  425. adminApi.orders(),
  426. adminApi.commissions(),
  427. adminApi.withdraws(),
  428. adminApi.configList()
  429. ])
  430. if (statsData) {
  431. stats.totalUsers = statsData.totalUsers || 0
  432. stats.vipUsers = statsData.vipUsers || 0
  433. stats.totalOrders = statsData.totalOrders || 0
  434. stats.totalRevenue = statsData.totalRevenue || 0
  435. stats.totalCharts = statsData.totalCharts || 0
  436. stats.totalCommissions = statsData.totalCommissions || 0
  437. stats.recentOrders = statsData.recentOrders || []
  438. }
  439. users.value = usersData || []
  440. orders.value = ordersData || []
  441. commissions.value = commissionsData || []
  442. withdraws.value = withdrawsData || []
  443. configs.value = configsData || []
  444. // Init config edits
  445. if (configsData) {
  446. configsData.forEach(cfg => {
  447. configEdits[cfg.configKey] = cfg.configValue || ''
  448. })
  449. }
  450. } catch (e) {
  451. if (e.code === 1001) {
  452. // Token expired — redirect to login
  453. uni.removeStorageSync('adminToken')
  454. authenticated.value = false
  455. }
  456. uni.showToast({ title: e.message || '数据加载失败', icon: 'none' })
  457. } finally {
  458. loading.value = false
  459. }
  460. }
  461. onMounted(async () => {
  462. if (authenticated.value) {
  463. await fetchAllData()
  464. } else {
  465. loading.value = false
  466. }
  467. })
  468. onPullDownRefresh(async () => {
  469. if (authenticated.value) {
  470. await fetchAllData()
  471. }
  472. uni.stopPullDownRefresh()
  473. })
  474. // ─── User Actions ───
  475. async function handleUpgrade(userId) {
  476. actionLoading.userId = userId
  477. actionLoading.type = 'upgrade'
  478. try {
  479. await adminApi.upgradeUser(userId)
  480. uni.showToast({ title: '已升级为VIP', icon: 'success' })
  481. await fetchAllData()
  482. } catch (e) {
  483. uni.showToast({ title: e.message || '操作失败', icon: 'none' })
  484. } finally {
  485. actionLoading.userId = null
  486. actionLoading.type = null
  487. }
  488. }
  489. async function handleDowngrade(userId) {
  490. uni.showModal({
  491. title: '取消VIP',
  492. content: '确定要取消该用户的VIP资格吗?',
  493. success: async (res) => {
  494. if (!res.confirm) return
  495. actionLoading.userId = userId
  496. actionLoading.type = 'downgrade'
  497. try {
  498. await adminApi.downgradeUser(userId)
  499. uni.showToast({ title: '已取消VIP', icon: 'success' })
  500. await fetchAllData()
  501. } catch (e) {
  502. uni.showToast({ title: e.message || '操作失败', icon: 'none' })
  503. } finally {
  504. actionLoading.userId = null
  505. actionLoading.type = null
  506. }
  507. }
  508. })
  509. }
  510. async function handleToggleAdmin(user) {
  511. const newIsAdmin = !user.isAdmin
  512. actionLoading.userId = user.id
  513. actionLoading.type = 'set-admin'
  514. try {
  515. await adminApi.setAdmin(user.id, newIsAdmin)
  516. uni.showToast({ title: newIsAdmin ? '已设为管理员' : '已取消管理员', icon: 'success' })
  517. await fetchAllData()
  518. } catch (e) {
  519. uni.showToast({ title: e.message || '操作失败', icon: 'none' })
  520. } finally {
  521. actionLoading.userId = null
  522. actionLoading.type = null
  523. }
  524. }
  525. // ─── Withdraw Actions ───
  526. async function handleApproveWithdraw(id) {
  527. actionLoading.withdrawId = id
  528. actionLoading.type = 'approve'
  529. try {
  530. await adminApi.approveWithdraw(id)
  531. uni.showToast({ title: '提现已批准', icon: 'success' })
  532. await fetchAllData()
  533. } catch (e) {
  534. uni.showToast({ title: e.message || '操作失败', icon: 'none' })
  535. } finally {
  536. actionLoading.withdrawId = null
  537. actionLoading.type = null
  538. }
  539. }
  540. async function handleRejectWithdraw(id) {
  541. uni.showModal({
  542. title: '拒绝提现',
  543. content: '确定要拒绝该提现申请吗?',
  544. success: async (res) => {
  545. if (!res.confirm) return
  546. actionLoading.withdrawId = id
  547. actionLoading.type = 'reject'
  548. try {
  549. await adminApi.rejectWithdraw(id)
  550. uni.showToast({ title: '提现已拒绝', icon: 'success' })
  551. await fetchAllData()
  552. } catch (e) {
  553. uni.showToast({ title: e.message || '操作失败', icon: 'none' })
  554. } finally {
  555. actionLoading.withdrawId = null
  556. actionLoading.type = null
  557. }
  558. }
  559. })
  560. }
  561. // ─── Config Actions ───
  562. async function handleSaveConfig(configKey) {
  563. const newValue = configEdits[configKey]
  564. if (newValue == null) return
  565. configSaving.value = configKey
  566. try {
  567. await adminApi.configUpdate({ key: configKey, value: newValue })
  568. uni.showToast({ title: '配置已更新', icon: 'success' })
  569. await fetchAllData()
  570. } catch (e) {
  571. uni.showToast({ title: e.message || '保存失败', icon: 'none' })
  572. } finally {
  573. configSaving.value = null
  574. }
  575. }
  576. async function handleResetConfig(configKey) {
  577. uni.showModal({
  578. title: '重置配置',
  579. content: `确定要将 "${configKey}" 重置为默认值吗?`,
  580. success: async (res) => {
  581. if (!res.confirm) return
  582. configResetting.value = configKey
  583. try {
  584. await adminApi.configReset(configKey)
  585. uni.showToast({ title: '配置已重置', icon: 'success' })
  586. await fetchAllData()
  587. } catch (e) {
  588. uni.showToast({ title: e.message || '重置失败', icon: 'none' })
  589. } finally {
  590. configResetting.value = null
  591. }
  592. }
  593. })
  594. }
  595. </script>
  596. <style scoped lang="scss">
  597. .page-admin {
  598. min-height: 100vh;
  599. background: linear-gradient(180deg, #0c0a1a 0%, #1a1232 100%);
  600. padding: 16px;
  601. padding-bottom: 40px;
  602. }
  603. // ─── Placeholder ───
  604. .placeholder-style {
  605. color: rgba(255, 255, 255, 0.25);
  606. }
  607. // ─── Login Screen ───
  608. .login-screen {
  609. display: flex;
  610. align-items: center;
  611. justify-content: center;
  612. min-height: 90vh;
  613. padding: 20px;
  614. }
  615. .login-card {
  616. width: 100%;
  617. max-width: 340px;
  618. background: rgba(255, 255, 255, 0.03);
  619. border: 1px solid rgba(255, 255, 255, 0.06);
  620. border-radius: 20px;
  621. padding: 32px 24px;
  622. }
  623. .login-title {
  624. display: block;
  625. font-size: 26px;
  626. font-weight: 700;
  627. color: rgba(255, 255, 255, 0.95);
  628. text-align: center;
  629. margin-bottom: 6px;
  630. }
  631. .login-subtitle {
  632. display: block;
  633. font-size: 13px;
  634. color: var(--color-text-tertiary);
  635. text-align: center;
  636. margin-bottom: 32px;
  637. }
  638. .login-form {
  639. display: flex;
  640. flex-direction: column;
  641. gap: 16px;
  642. }
  643. .login-field {
  644. display: flex;
  645. flex-direction: column;
  646. gap: 6px;
  647. }
  648. .field-label {
  649. font-size: 13px;
  650. font-weight: 500;
  651. color: var(--color-text-secondary);
  652. }
  653. .field-input {
  654. height: 44px;
  655. padding: 0 14px;
  656. background: rgba(255, 255, 255, 0.04);
  657. border: 1px solid rgba(255, 255, 255, 0.08);
  658. border-radius: 10px;
  659. font-size: 15px;
  660. color: rgba(255, 255, 255, 0.9);
  661. box-sizing: border-box;
  662. }
  663. .login-error {
  664. padding: 8px 12px;
  665. background: rgba(239, 68, 68, 0.1);
  666. border-radius: 8px;
  667. }
  668. .login-error-text {
  669. font-size: 13px;
  670. color: #ef4444;
  671. }
  672. .login-btn {
  673. height: 46px;
  674. margin-top: 8px;
  675. background: linear-gradient(135deg, #3b82f6, #2563eb);
  676. border: none;
  677. border-radius: 12px;
  678. font-size: 16px;
  679. font-weight: 600;
  680. color: #fff;
  681. display: flex;
  682. align-items: center;
  683. justify-content: center;
  684. line-height: 1;
  685. }
  686. .login-btn[disabled] {
  687. opacity: 0.5;
  688. }
  689. // ─── Loading ───
  690. .loading-state {
  691. padding: 60px 0;
  692. text-align: center;
  693. }
  694. .loading-text {
  695. font-size: 14px;
  696. color: var(--color-text-tertiary);
  697. }
  698. // ─── Stats Grid ───
  699. .stats-grid {
  700. display: grid;
  701. grid-template-columns: 1fr 1fr 1fr;
  702. gap: 8px;
  703. margin-bottom: 16px;
  704. }
  705. .stat-card {
  706. background: rgba(255, 255, 255, 0.02);
  707. border: 1px solid rgba(255, 255, 255, 0.04);
  708. border-radius: 14px;
  709. padding: 14px 10px;
  710. text-align: center;
  711. }
  712. .stat-value {
  713. display: block;
  714. font-size: 22px;
  715. font-weight: 700;
  716. margin-bottom: 4px;
  717. }
  718. .stat-label {
  719. display: block;
  720. font-size: 11px;
  721. color: rgba(255, 255, 255, 0.45);
  722. }
  723. .accent-blue { color: #3b82f6; }
  724. .accent-green { color: #10b981; }
  725. .accent-amber { color: #f59e0b; }
  726. .accent-rose { color: #f472b6; }
  727. // ─── Section Card ───
  728. .section-card {
  729. background: rgba(255, 255, 255, 0.02);
  730. border: 1px solid rgba(255, 255, 255, 0.04);
  731. border-radius: 16px;
  732. padding: 14px;
  733. margin-bottom: 16px;
  734. }
  735. .section-header {
  736. margin-bottom: 10px;
  737. }
  738. .section-title {
  739. font-size: 15px;
  740. font-weight: 700;
  741. color: rgba(255, 255, 255, 0.85);
  742. }
  743. .mini-row {
  744. display: flex;
  745. justify-content: space-between;
  746. align-items: center;
  747. padding: 8px 0;
  748. border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  749. }
  750. .mini-row:last-child {
  751. border-bottom: none;
  752. }
  753. .mini-left {
  754. display: flex;
  755. flex-direction: column;
  756. gap: 2px;
  757. }
  758. .mini-label {
  759. font-size: 13px;
  760. font-weight: 500;
  761. color: rgba(255, 255, 255, 0.8);
  762. }
  763. .mini-desc {
  764. font-size: 11px;
  765. color: var(--color-text-tertiary);
  766. }
  767. .mini-right {
  768. text-align: right;
  769. }
  770. .mini-value {
  771. display: block;
  772. font-size: 14px;
  773. font-weight: 600;
  774. }
  775. .mini-status {
  776. font-size: 10px;
  777. padding: 2px 8px;
  778. border-radius: 4px;
  779. display: inline-block;
  780. margin-top: 2px;
  781. }
  782. // ─── Tab Bar ───
  783. .tab-bar {
  784. display: flex;
  785. gap: 6px;
  786. margin-bottom: 14px;
  787. overflow-x: auto;
  788. white-space: nowrap;
  789. -webkit-overflow-scrolling: touch;
  790. padding-bottom: 4px;
  791. }
  792. .tab-item {
  793. flex-shrink: 0;
  794. padding: 8px 16px;
  795. border-radius: 10px;
  796. background: rgba(255, 255, 255, 0.02);
  797. border: 1px solid rgba(255, 255, 255, 0.04);
  798. }
  799. .tab-active {
  800. background: rgba(59, 130, 246, 0.12);
  801. border-color: rgba(59, 130, 246, 0.25);
  802. }
  803. .tab-text {
  804. font-size: 13px;
  805. font-weight: 500;
  806. color: var(--color-text-tertiary);
  807. }
  808. .tab-active .tab-text {
  809. color: #3b82f6;
  810. }
  811. // ─── Tab Content ───
  812. .tab-content {
  813. margin-bottom: 16px;
  814. }
  815. // ─── Data Card ───
  816. .data-card {
  817. background: rgba(255, 255, 255, 0.02);
  818. border: 1px solid rgba(255, 255, 255, 0.04);
  819. border-radius: 14px;
  820. padding: 14px;
  821. margin-bottom: 10px;
  822. }
  823. .data-row {
  824. display: flex;
  825. justify-content: space-between;
  826. align-items: flex-start;
  827. }
  828. .data-left {
  829. flex: 1;
  830. min-width: 0;
  831. }
  832. .data-info {
  833. display: flex;
  834. flex-direction: column;
  835. gap: 3px;
  836. }
  837. .data-primary {
  838. font-size: 14px;
  839. font-weight: 600;
  840. color: rgba(255, 255, 255, 0.85);
  841. }
  842. .data-meta {
  843. font-size: 11px;
  844. color: var(--color-text-tertiary);
  845. }
  846. .data-right {
  847. text-align: right;
  848. flex-shrink: 0;
  849. margin-left: 12px;
  850. }
  851. .data-price {
  852. display: block;
  853. font-size: 15px;
  854. font-weight: 700;
  855. color: rgba(255, 255, 255, 0.85);
  856. margin-bottom: 3px;
  857. }
  858. .data-extras {
  859. margin-top: 6px;
  860. padding-top: 6px;
  861. border-top: 1px solid rgba(255, 255, 255, 0.04);
  862. }
  863. // ─── Tags ───
  864. .tag-vip {
  865. font-size: 10px;
  866. font-weight: 600;
  867. padding: 2px 10px;
  868. border-radius: 999px;
  869. background: rgba(107, 114, 128, 0.2);
  870. color: var(--color-text-tertiary);
  871. }
  872. .tag-vip-active {
  873. background: rgba(16, 185, 129, 0.15);
  874. color: #10b981;
  875. }
  876. .tag-status {
  877. font-size: 10px;
  878. font-weight: 500;
  879. padding: 2px 8px;
  880. border-radius: 4px;
  881. display: inline-block;
  882. }
  883. .tag-status-paid,
  884. .tag-status-settled,
  885. .tag-status-approved,
  886. .tag-status-completed {
  887. background: rgba(16, 185, 129, 0.12);
  888. color: #10b981;
  889. }
  890. .tag-status-unpaid,
  891. .tag-status-pending {
  892. background: rgba(245, 158, 11, 0.12);
  893. color: #f59e0b;
  894. }
  895. .tag-status-cancelled,
  896. .tag-status-rejected {
  897. background: rgba(239, 68, 68, 0.12);
  898. color: #ef4444;
  899. }
  900. .tag-status-refunded {
  901. background: rgba(107, 114, 128, 0.12);
  902. color: #9ca3af;
  903. }
  904. .tag-status-available {
  905. background: rgba(59, 130, 246, 0.12);
  906. color: #3b82f6;
  907. }
  908. .tag-status-withdrawn {
  909. background: rgba(107, 114, 128, 0.12);
  910. color: #9ca3af;
  911. }
  912. .badge-admin {
  913. font-size: 9px;
  914. font-weight: 600;
  915. background: rgba(59, 130, 246, 0.15);
  916. color: #3b82f6;
  917. padding: 1px 6px;
  918. border-radius: 4px;
  919. margin-left: 6px;
  920. vertical-align: middle;
  921. }
  922. // ─── Action Buttons ───
  923. .action-row {
  924. display: flex;
  925. gap: 8px;
  926. margin-top: 10px;
  927. padding-top: 10px;
  928. border-top: 1px solid rgba(255, 255, 255, 0.04);
  929. }
  930. .btn {
  931. border: none;
  932. border-radius: 8px;
  933. font-size: 12px;
  934. font-weight: 600;
  935. display: flex;
  936. align-items: center;
  937. justify-content: center;
  938. line-height: 1;
  939. height: auto;
  940. padding: 8px 14px;
  941. }
  942. .btn-sm {
  943. font-size: 11px;
  944. padding: 6px 12px;
  945. height: 30px;
  946. }
  947. .btn-xxs {
  948. font-size: 10px;
  949. padding: 4px 10px;
  950. height: 26px;
  951. }
  952. .btn-green {
  953. background: #10b981;
  954. color: #fff;
  955. }
  956. .btn-green[disabled] {
  957. opacity: 0.5;
  958. }
  959. .btn-red-outline {
  960. background: transparent;
  961. border: 1px solid #ef4444;
  962. color: #ef4444;
  963. }
  964. .btn-red-outline[disabled] {
  965. opacity: 0.5;
  966. }
  967. .btn-blue-outline {
  968. background: transparent;
  969. border: 1px solid rgba(59, 130, 246, 0.4);
  970. color: #3b82f6;
  971. }
  972. .btn-blue-outline[disabled] {
  973. opacity: 0.5;
  974. }
  975. .btn-amber-outline {
  976. background: transparent;
  977. border: 1px solid rgba(245, 158, 11, 0.4);
  978. color: #f59e0b;
  979. }
  980. .btn-amber-outline[disabled] {
  981. opacity: 0.5;
  982. }
  983. // ─── Config ───
  984. .config-row {
  985. display: flex;
  986. flex-direction: column;
  987. gap: 8px;
  988. }
  989. .config-header {
  990. display: flex;
  991. justify-content: space-between;
  992. align-items: center;
  993. }
  994. .config-value-row {
  995. display: flex;
  996. gap: 8px;
  997. align-items: center;
  998. }
  999. .config-input {
  1000. flex: 1;
  1001. height: 34px;
  1002. padding: 0 10px;
  1003. background: rgba(255, 255, 255, 0.04);
  1004. border: 1px solid rgba(255, 255, 255, 0.08);
  1005. border-radius: 8px;
  1006. font-size: 13px;
  1007. color: rgba(255, 255, 255, 0.9);
  1008. box-sizing: border-box;
  1009. min-width: 0;
  1010. }
  1011. .config-desc {
  1012. font-size: 10px;
  1013. }
  1014. // ─── Empty State ───
  1015. .empty-state {
  1016. display: flex;
  1017. align-items: center;
  1018. justify-content: center;
  1019. padding: 60px 20px;
  1020. }
  1021. .empty-text {
  1022. font-size: 13px;
  1023. color: rgba(255, 255, 255, 0.35);
  1024. }
  1025. // ─── Logout ───
  1026. .logout-bar {
  1027. margin-top: 8px;
  1028. padding: 12px 0;
  1029. text-align: center;
  1030. }
  1031. .logout-text {
  1032. font-size: 12px;
  1033. color: var(--color-text-tertiary);
  1034. text-decoration: underline;
  1035. }
  1036. </style>