index.vue 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261
  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. uni.showModal({
  477. title: '升级VIP',
  478. content: '确定要将该用户升级为VIP吗?',
  479. success: async (res) => {
  480. if (!res.confirm) return
  481. actionLoading.userId = userId
  482. actionLoading.type = 'upgrade'
  483. try {
  484. await adminApi.upgradeUser(userId)
  485. uni.showToast({ title: '已升级为VIP', icon: 'success' })
  486. await fetchAllData()
  487. } catch (e) {
  488. uni.showToast({ title: e.message || '操作失败', icon: 'none' })
  489. } finally {
  490. actionLoading.userId = null
  491. actionLoading.type = null
  492. }
  493. }
  494. })
  495. }
  496. async function handleDowngrade(userId) {
  497. uni.showModal({
  498. title: '取消VIP',
  499. content: '确定要取消该用户的VIP资格吗?',
  500. success: async (res) => {
  501. if (!res.confirm) return
  502. actionLoading.userId = userId
  503. actionLoading.type = 'downgrade'
  504. try {
  505. await adminApi.downgradeUser(userId)
  506. uni.showToast({ title: '已取消VIP', icon: 'success' })
  507. await fetchAllData()
  508. } catch (e) {
  509. uni.showToast({ title: e.message || '操作失败', icon: 'none' })
  510. } finally {
  511. actionLoading.userId = null
  512. actionLoading.type = null
  513. }
  514. }
  515. })
  516. }
  517. async function handleToggleAdmin(user) {
  518. const newIsAdmin = !user.isAdmin
  519. uni.showModal({
  520. title: newIsAdmin ? '设为管理员' : '取消管理员',
  521. content: newIsAdmin ? '确定要将该用户设为管理员吗?' : '确定要取消该用户的管理员权限吗?',
  522. success: async (res) => {
  523. if (!res.confirm) return
  524. actionLoading.userId = user.id
  525. actionLoading.type = 'set-admin'
  526. try {
  527. await adminApi.setAdmin(user.id, newIsAdmin)
  528. uni.showToast({ title: newIsAdmin ? '已设为管理员' : '已取消管理员', icon: 'success' })
  529. await fetchAllData()
  530. } catch (e) {
  531. uni.showToast({ title: e.message || '操作失败', icon: 'none' })
  532. } finally {
  533. actionLoading.userId = null
  534. actionLoading.type = null
  535. }
  536. }
  537. })
  538. }
  539. // ─── Withdraw Actions ───
  540. async function handleApproveWithdraw(id) {
  541. actionLoading.withdrawId = id
  542. actionLoading.type = 'approve'
  543. try {
  544. await adminApi.approveWithdraw(id)
  545. uni.showToast({ title: '提现已批准', icon: 'success' })
  546. await fetchAllData()
  547. } catch (e) {
  548. uni.showToast({ title: e.message || '操作失败', icon: 'none' })
  549. } finally {
  550. actionLoading.withdrawId = null
  551. actionLoading.type = null
  552. }
  553. }
  554. async function handleRejectWithdraw(id) {
  555. uni.showModal({
  556. title: '拒绝提现',
  557. content: '确定要拒绝该提现申请吗?',
  558. success: async (res) => {
  559. if (!res.confirm) return
  560. actionLoading.withdrawId = id
  561. actionLoading.type = 'reject'
  562. try {
  563. await adminApi.rejectWithdraw(id)
  564. uni.showToast({ title: '提现已拒绝', icon: 'success' })
  565. await fetchAllData()
  566. } catch (e) {
  567. uni.showToast({ title: e.message || '操作失败', icon: 'none' })
  568. } finally {
  569. actionLoading.withdrawId = null
  570. actionLoading.type = null
  571. }
  572. }
  573. })
  574. }
  575. // ─── Config Actions ───
  576. async function handleSaveConfig(configKey) {
  577. const newValue = configEdits[configKey]
  578. if (newValue == null) return
  579. configSaving.value = configKey
  580. try {
  581. await adminApi.configUpdate({ key: configKey, value: newValue })
  582. uni.showToast({ title: '配置已更新', icon: 'success' })
  583. await fetchAllData()
  584. } catch (e) {
  585. uni.showToast({ title: e.message || '保存失败', icon: 'none' })
  586. } finally {
  587. configSaving.value = null
  588. }
  589. }
  590. async function handleResetConfig(configKey) {
  591. uni.showModal({
  592. title: '重置配置',
  593. content: `确定要将 "${configKey}" 重置为默认值吗?`,
  594. success: async (res) => {
  595. if (!res.confirm) return
  596. configResetting.value = configKey
  597. try {
  598. await adminApi.configReset(configKey)
  599. uni.showToast({ title: '配置已重置', icon: 'success' })
  600. await fetchAllData()
  601. } catch (e) {
  602. uni.showToast({ title: e.message || '重置失败', icon: 'none' })
  603. } finally {
  604. configResetting.value = null
  605. }
  606. }
  607. })
  608. }
  609. </script>
  610. <style scoped lang="scss">
  611. .page-admin {
  612. min-height: 100vh;
  613. background: linear-gradient(180deg, #0c0a1a 0%, #1a1232 100%);
  614. padding: 16px;
  615. padding-bottom: 40px;
  616. }
  617. // ─── Placeholder ───
  618. .placeholder-style {
  619. color: rgba(255, 255, 255, 0.25);
  620. }
  621. // ─── Login Screen ───
  622. .login-screen {
  623. display: flex;
  624. align-items: center;
  625. justify-content: center;
  626. min-height: 90vh;
  627. padding: 20px;
  628. }
  629. .login-card {
  630. width: 100%;
  631. max-width: 340px;
  632. background: rgba(255, 255, 255, 0.03);
  633. border: 1px solid rgba(255, 255, 255, 0.06);
  634. border-radius: 20px;
  635. padding: 32px 24px;
  636. }
  637. .login-title {
  638. display: block;
  639. font-size: 26px;
  640. font-weight: 700;
  641. color: rgba(255, 255, 255, 0.95);
  642. text-align: center;
  643. margin-bottom: 6px;
  644. }
  645. .login-subtitle {
  646. display: block;
  647. font-size: 13px;
  648. color: var(--color-text-tertiary);
  649. text-align: center;
  650. margin-bottom: 32px;
  651. }
  652. .login-form {
  653. display: flex;
  654. flex-direction: column;
  655. gap: 16px;
  656. }
  657. .login-field {
  658. display: flex;
  659. flex-direction: column;
  660. gap: 6px;
  661. }
  662. .field-label {
  663. font-size: 13px;
  664. font-weight: 500;
  665. color: var(--color-text-secondary);
  666. }
  667. .field-input {
  668. height: 44px;
  669. padding: 0 14px;
  670. background: rgba(255, 255, 255, 0.04);
  671. border: 1px solid rgba(255, 255, 255, 0.08);
  672. border-radius: 10px;
  673. font-size: 15px;
  674. color: rgba(255, 255, 255, 0.9);
  675. box-sizing: border-box;
  676. }
  677. .login-error {
  678. padding: 8px 12px;
  679. background: rgba(239, 68, 68, 0.1);
  680. border-radius: 8px;
  681. }
  682. .login-error-text {
  683. font-size: 13px;
  684. color: #ef4444;
  685. }
  686. .login-btn {
  687. height: 46px;
  688. margin-top: 8px;
  689. background: linear-gradient(135deg, #3b82f6, #2563eb);
  690. border: none;
  691. border-radius: 12px;
  692. font-size: 16px;
  693. font-weight: 600;
  694. color: #fff;
  695. display: flex;
  696. align-items: center;
  697. justify-content: center;
  698. line-height: 1;
  699. }
  700. .login-btn[disabled] {
  701. opacity: 0.5;
  702. }
  703. // ─── Loading ───
  704. .loading-state {
  705. padding: 60px 0;
  706. text-align: center;
  707. }
  708. .loading-text {
  709. font-size: 14px;
  710. color: var(--color-text-tertiary);
  711. }
  712. // ─── Stats Grid ───
  713. .stats-grid {
  714. display: grid;
  715. grid-template-columns: 1fr 1fr 1fr;
  716. gap: 8px;
  717. margin-bottom: 16px;
  718. }
  719. .stat-card {
  720. background: rgba(255, 255, 255, 0.02);
  721. border: 1px solid rgba(255, 255, 255, 0.04);
  722. border-radius: 14px;
  723. padding: 14px 10px;
  724. text-align: center;
  725. }
  726. .stat-value {
  727. display: block;
  728. font-size: 22px;
  729. font-weight: 700;
  730. margin-bottom: 4px;
  731. }
  732. .stat-label {
  733. display: block;
  734. font-size: 11px;
  735. color: rgba(255, 255, 255, 0.45);
  736. }
  737. .accent-blue { color: #3b82f6; }
  738. .accent-green { color: #10b981; }
  739. .accent-amber { color: #f59e0b; }
  740. .accent-rose { color: #f472b6; }
  741. // ─── Section Card ───
  742. .section-card {
  743. background: rgba(255, 255, 255, 0.02);
  744. border: 1px solid rgba(255, 255, 255, 0.04);
  745. border-radius: 16px;
  746. padding: 14px;
  747. margin-bottom: 16px;
  748. }
  749. .section-header {
  750. margin-bottom: 10px;
  751. }
  752. .section-title {
  753. font-size: 15px;
  754. font-weight: 700;
  755. color: rgba(255, 255, 255, 0.85);
  756. }
  757. .mini-row {
  758. display: flex;
  759. justify-content: space-between;
  760. align-items: center;
  761. padding: 8px 0;
  762. border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  763. }
  764. .mini-row:last-child {
  765. border-bottom: none;
  766. }
  767. .mini-left {
  768. display: flex;
  769. flex-direction: column;
  770. gap: 2px;
  771. }
  772. .mini-label {
  773. font-size: 13px;
  774. font-weight: 500;
  775. color: rgba(255, 255, 255, 0.8);
  776. }
  777. .mini-desc {
  778. font-size: 11px;
  779. color: var(--color-text-tertiary);
  780. }
  781. .mini-right {
  782. text-align: right;
  783. }
  784. .mini-value {
  785. display: block;
  786. font-size: 14px;
  787. font-weight: 600;
  788. }
  789. .mini-status {
  790. font-size: 10px;
  791. padding: 2px 8px;
  792. border-radius: 4px;
  793. display: inline-block;
  794. margin-top: 2px;
  795. }
  796. // ─── Tab Bar ───
  797. .tab-bar {
  798. display: flex;
  799. gap: 6px;
  800. margin-bottom: 14px;
  801. overflow-x: auto;
  802. white-space: nowrap;
  803. -webkit-overflow-scrolling: touch;
  804. padding-bottom: 4px;
  805. }
  806. .tab-item {
  807. flex-shrink: 0;
  808. padding: 8px 16px;
  809. border-radius: 10px;
  810. background: rgba(255, 255, 255, 0.02);
  811. border: 1px solid rgba(255, 255, 255, 0.04);
  812. }
  813. .tab-active {
  814. background: rgba(59, 130, 246, 0.12);
  815. border-color: rgba(59, 130, 246, 0.25);
  816. }
  817. .tab-text {
  818. font-size: 13px;
  819. font-weight: 500;
  820. color: var(--color-text-tertiary);
  821. }
  822. .tab-active .tab-text {
  823. color: #3b82f6;
  824. }
  825. // ─── Tab Content ───
  826. .tab-content {
  827. margin-bottom: 16px;
  828. }
  829. // ─── Data Card ───
  830. .data-card {
  831. background: rgba(255, 255, 255, 0.02);
  832. border: 1px solid rgba(255, 255, 255, 0.04);
  833. border-radius: 14px;
  834. padding: 14px;
  835. margin-bottom: 10px;
  836. }
  837. .data-row {
  838. display: flex;
  839. justify-content: space-between;
  840. align-items: flex-start;
  841. }
  842. .data-left {
  843. flex: 1;
  844. min-width: 0;
  845. }
  846. .data-info {
  847. display: flex;
  848. flex-direction: column;
  849. gap: 3px;
  850. }
  851. .data-primary {
  852. font-size: 14px;
  853. font-weight: 600;
  854. color: rgba(255, 255, 255, 0.85);
  855. }
  856. .data-meta {
  857. font-size: 11px;
  858. color: var(--color-text-tertiary);
  859. }
  860. .data-right {
  861. text-align: right;
  862. flex-shrink: 0;
  863. margin-left: 12px;
  864. }
  865. .data-price {
  866. display: block;
  867. font-size: 15px;
  868. font-weight: 700;
  869. color: rgba(255, 255, 255, 0.85);
  870. margin-bottom: 3px;
  871. }
  872. .data-extras {
  873. margin-top: 6px;
  874. padding-top: 6px;
  875. border-top: 1px solid rgba(255, 255, 255, 0.04);
  876. }
  877. // ─── Tags ───
  878. .tag-vip {
  879. font-size: 10px;
  880. font-weight: 600;
  881. padding: 2px 10px;
  882. border-radius: 999px;
  883. background: rgba(107, 114, 128, 0.2);
  884. color: var(--color-text-tertiary);
  885. }
  886. .tag-vip-active {
  887. background: rgba(16, 185, 129, 0.15);
  888. color: #10b981;
  889. }
  890. .tag-status {
  891. font-size: 10px;
  892. font-weight: 500;
  893. padding: 2px 8px;
  894. border-radius: 4px;
  895. display: inline-block;
  896. }
  897. .tag-status-paid,
  898. .tag-status-settled,
  899. .tag-status-approved,
  900. .tag-status-completed {
  901. background: rgba(16, 185, 129, 0.12);
  902. color: #10b981;
  903. }
  904. .tag-status-unpaid,
  905. .tag-status-pending {
  906. background: rgba(245, 158, 11, 0.12);
  907. color: #f59e0b;
  908. }
  909. .tag-status-cancelled,
  910. .tag-status-rejected {
  911. background: rgba(239, 68, 68, 0.12);
  912. color: #ef4444;
  913. }
  914. .tag-status-refunded {
  915. background: rgba(107, 114, 128, 0.12);
  916. color: #9ca3af;
  917. }
  918. .tag-status-available {
  919. background: rgba(59, 130, 246, 0.12);
  920. color: #3b82f6;
  921. }
  922. .tag-status-withdrawn {
  923. background: rgba(107, 114, 128, 0.12);
  924. color: #9ca3af;
  925. }
  926. .badge-admin {
  927. font-size: 9px;
  928. font-weight: 600;
  929. background: rgba(59, 130, 246, 0.15);
  930. color: #3b82f6;
  931. padding: 1px 6px;
  932. border-radius: 4px;
  933. margin-left: 6px;
  934. vertical-align: middle;
  935. }
  936. // ─── Action Buttons ───
  937. .action-row {
  938. display: flex;
  939. gap: 8px;
  940. margin-top: 10px;
  941. padding-top: 10px;
  942. border-top: 1px solid rgba(255, 255, 255, 0.04);
  943. }
  944. .btn {
  945. border: none;
  946. border-radius: 8px;
  947. font-size: 12px;
  948. font-weight: 600;
  949. display: flex;
  950. align-items: center;
  951. justify-content: center;
  952. line-height: 1;
  953. height: auto;
  954. padding: 8px 14px;
  955. }
  956. .btn-sm {
  957. font-size: 11px;
  958. padding: 6px 12px;
  959. height: 30px;
  960. }
  961. .btn-xxs {
  962. font-size: 10px;
  963. padding: 4px 10px;
  964. height: 26px;
  965. }
  966. .btn-green {
  967. background: #10b981;
  968. color: #fff;
  969. }
  970. .btn-green[disabled] {
  971. opacity: 0.5;
  972. }
  973. .btn-red-outline {
  974. background: transparent;
  975. border: 1px solid #ef4444;
  976. color: #ef4444;
  977. }
  978. .btn-red-outline[disabled] {
  979. opacity: 0.5;
  980. }
  981. .btn-blue-outline {
  982. background: transparent;
  983. border: 1px solid rgba(59, 130, 246, 0.4);
  984. color: #3b82f6;
  985. }
  986. .btn-blue-outline[disabled] {
  987. opacity: 0.5;
  988. }
  989. .btn-amber-outline {
  990. background: transparent;
  991. border: 1px solid rgba(245, 158, 11, 0.4);
  992. color: #f59e0b;
  993. }
  994. .btn-amber-outline[disabled] {
  995. opacity: 0.5;
  996. }
  997. // ─── Config ───
  998. .config-row {
  999. display: flex;
  1000. flex-direction: column;
  1001. gap: 8px;
  1002. }
  1003. .config-header {
  1004. display: flex;
  1005. justify-content: space-between;
  1006. align-items: center;
  1007. }
  1008. .config-value-row {
  1009. display: flex;
  1010. gap: 8px;
  1011. align-items: center;
  1012. }
  1013. .config-input {
  1014. flex: 1;
  1015. height: 34px;
  1016. padding: 0 10px;
  1017. background: rgba(255, 255, 255, 0.04);
  1018. border: 1px solid rgba(255, 255, 255, 0.08);
  1019. border-radius: 8px;
  1020. font-size: 13px;
  1021. color: rgba(255, 255, 255, 0.9);
  1022. box-sizing: border-box;
  1023. min-width: 0;
  1024. }
  1025. .config-desc {
  1026. font-size: 10px;
  1027. }
  1028. // ─── Empty State ───
  1029. .empty-state {
  1030. display: flex;
  1031. align-items: center;
  1032. justify-content: center;
  1033. padding: 60px 20px;
  1034. }
  1035. .empty-text {
  1036. font-size: 13px;
  1037. color: rgba(255, 255, 255, 0.35);
  1038. }
  1039. // ─── Logout ───
  1040. .logout-bar {
  1041. margin-top: 8px;
  1042. padding: 12px 0;
  1043. text-align: center;
  1044. }
  1045. .logout-text {
  1046. font-size: 12px;
  1047. color: var(--color-text-tertiary);
  1048. text-decoration: underline;
  1049. }
  1050. </style>
  1051. <style lang="scss">
  1052. // ─── Light Theme Overrides ───
  1053. .theme-light .page-admin {
  1054. background: linear-gradient(180deg, #f0f2f5 0%, #e8ecf0 100%);
  1055. }
  1056. .theme-light {
  1057. // Placeholder
  1058. .placeholder-style {
  1059. color: rgba(0, 0, 0, 0.25);
  1060. }
  1061. // Login
  1062. .login-card {
  1063. background: #ffffff;
  1064. border-color: rgba(0, 0, 0, 0.06);
  1065. box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  1066. }
  1067. .login-title {
  1068. color: rgba(0, 0, 0, 0.9);
  1069. }
  1070. .field-input {
  1071. background: rgba(0, 0, 0, 0.02);
  1072. border-color: rgba(0, 0, 0, 0.08);
  1073. color: rgba(0, 0, 0, 0.85);
  1074. }
  1075. // Stats
  1076. .stat-card {
  1077. background: #ffffff;
  1078. border-color: rgba(0, 0, 0, 0.06);
  1079. }
  1080. .stat-label {
  1081. color: rgba(0, 0, 0, 0.55);
  1082. }
  1083. // Section card (recent orders)
  1084. .section-card {
  1085. background: #ffffff;
  1086. border-color: rgba(0, 0, 0, 0.06);
  1087. }
  1088. .section-title {
  1089. color: rgba(0, 0, 0, 0.85);
  1090. }
  1091. .mini-row {
  1092. border-bottom-color: rgba(0, 0, 0, 0.06);
  1093. }
  1094. .mini-label {
  1095. color: rgba(0, 0, 0, 0.8);
  1096. }
  1097. // Tabs
  1098. .tab-item {
  1099. background: rgba(0, 0, 0, 0.02);
  1100. border-color: rgba(0, 0, 0, 0.06);
  1101. }
  1102. // Data cards
  1103. .data-card {
  1104. background: #ffffff;
  1105. border-color: rgba(0, 0, 0, 0.06);
  1106. }
  1107. .data-primary {
  1108. color: rgba(0, 0, 0, 0.85);
  1109. }
  1110. .data-price {
  1111. color: rgba(0, 0, 0, 0.85);
  1112. }
  1113. .data-extras {
  1114. border-top-color: rgba(0, 0, 0, 0.06);
  1115. }
  1116. .action-row {
  1117. border-top-color: rgba(0, 0, 0, 0.06);
  1118. }
  1119. // Config
  1120. .config-input {
  1121. background: rgba(0, 0, 0, 0.02);
  1122. border-color: rgba(0, 0, 0, 0.08);
  1123. color: rgba(0, 0, 0, 0.85);
  1124. }
  1125. // Empty state
  1126. .empty-text {
  1127. color: rgba(0, 0, 0, 0.35);
  1128. }
  1129. }
  1130. </style>