index.vue 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147
  1. <template>
  2. <view class="page-admin">
  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. // ─── Auth State ───
  316. const authenticated = ref(!!uni.getStorageSync('adminToken'))
  317. const loginForm = reactive({ username: '', password: '' })
  318. const loggingIn = ref(false)
  319. const loginError = ref('')
  320. // ─── Data State ───
  321. const loading = ref(true)
  322. const stats = reactive({
  323. totalUsers: 0,
  324. vipUsers: 0,
  325. totalOrders: 0,
  326. totalRevenue: 0,
  327. totalCharts: 0,
  328. totalCommissions: 0,
  329. recentOrders: []
  330. })
  331. const users = ref([])
  332. const orders = ref([])
  333. const commissions = ref([])
  334. const withdraws = ref([])
  335. const configs = ref([])
  336. // ─── UI State ───
  337. const currentTab = ref('users')
  338. const actionLoading = reactive({ userId: null, withdrawId: null, type: null })
  339. const configResetting = ref(null)
  340. const configSaving = ref(null)
  341. const configEdits = reactive({})
  342. const tabs = [
  343. { key: 'users', label: '用户管理' },
  344. { key: 'orders', label: '订单管理' },
  345. { key: 'commissions', label: '佣金记录' },
  346. { key: 'withdraws', label: '提现审核' },
  347. { key: 'config', label: '系统配置' }
  348. ]
  349. // ─── Helpers ───
  350. function formatMoney(cents) {
  351. if (cents == null) return '0.00'
  352. return (cents / 100).toFixed(2)
  353. }
  354. function formatDate(dateStr) {
  355. if (!dateStr) return '--'
  356. const d = new Date(dateStr)
  357. if (isNaN(d.getTime())) return '--'
  358. return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`
  359. }
  360. function isVipActive(user) {
  361. if (!user.vipEndTime) return false
  362. return new Date(user.vipEndTime) > new Date()
  363. }
  364. function orderStatusLabel(status) {
  365. const map = { paid: '已支付', unpaid: '未支付', cancelled: '已取消', refunded: '已退款', pending: '处理中' }
  366. return map[status] || status || '未知'
  367. }
  368. function commissionStatusLabel(status) {
  369. const map = { settled: '已结算', pending: '处理中', withdrawn: '已提现', available: '可提现' }
  370. return map[status] || status || '未知'
  371. }
  372. function withdrawStatusLabel(status) {
  373. const map = { pending: '待审核', approved: '已批准', rejected: '已拒绝', completed: '已完成' }
  374. return map[status] || status || '未知'
  375. }
  376. // ─── Auth ───
  377. async function handleLogin() {
  378. if (!loginForm.username || !loginForm.password) {
  379. loginError.value = '请输入用户名和密码'
  380. return
  381. }
  382. loginError.value = ''
  383. loggingIn.value = true
  384. try {
  385. const result = await adminApi.login(loginForm.username, loginForm.password)
  386. uni.setStorageSync('adminToken', result.token)
  387. authenticated.value = true
  388. await fetchAllData()
  389. } catch (e) {
  390. loginError.value = e.message || '登录失败,请检查账号密码'
  391. } finally {
  392. loggingIn.value = false
  393. }
  394. }
  395. function handleLogout() {
  396. uni.showModal({
  397. title: '退出登录',
  398. content: '确定要退出管理后台吗?',
  399. success: (res) => {
  400. if (res.confirm) {
  401. uni.removeStorageSync('adminToken')
  402. authenticated.value = false
  403. loginForm.username = ''
  404. loginForm.password = ''
  405. }
  406. }
  407. })
  408. }
  409. // ─── Data Fetching ───
  410. async function fetchAllData() {
  411. loading.value = true
  412. try {
  413. const [
  414. statsData,
  415. usersData,
  416. ordersData,
  417. commissionsData,
  418. withdrawsData,
  419. configsData
  420. ] = await Promise.all([
  421. adminApi.stats(),
  422. adminApi.users(),
  423. adminApi.orders(),
  424. adminApi.commissions(),
  425. adminApi.withdraws(),
  426. adminApi.configList()
  427. ])
  428. if (statsData) {
  429. stats.totalUsers = statsData.totalUsers || 0
  430. stats.vipUsers = statsData.vipUsers || 0
  431. stats.totalOrders = statsData.totalOrders || 0
  432. stats.totalRevenue = statsData.totalRevenue || 0
  433. stats.totalCharts = statsData.totalCharts || 0
  434. stats.totalCommissions = statsData.totalCommissions || 0
  435. stats.recentOrders = statsData.recentOrders || []
  436. }
  437. users.value = usersData || []
  438. orders.value = ordersData || []
  439. commissions.value = commissionsData || []
  440. withdraws.value = withdrawsData || []
  441. configs.value = configsData || []
  442. // Init config edits
  443. if (configsData) {
  444. configsData.forEach(cfg => {
  445. configEdits[cfg.configKey] = cfg.configValue || ''
  446. })
  447. }
  448. } catch (e) {
  449. if (e.code === 1001) {
  450. // Token expired — redirect to login
  451. uni.removeStorageSync('adminToken')
  452. authenticated.value = false
  453. }
  454. uni.showToast({ title: e.message || '数据加载失败', icon: 'none' })
  455. } finally {
  456. loading.value = false
  457. }
  458. }
  459. onMounted(async () => {
  460. if (authenticated.value) {
  461. await fetchAllData()
  462. } else {
  463. loading.value = false
  464. }
  465. })
  466. onPullDownRefresh(async () => {
  467. if (authenticated.value) {
  468. await fetchAllData()
  469. }
  470. uni.stopPullDownRefresh()
  471. })
  472. // ─── User Actions ───
  473. async function handleUpgrade(userId) {
  474. actionLoading.userId = userId
  475. actionLoading.type = 'upgrade'
  476. try {
  477. await adminApi.upgradeUser(userId)
  478. uni.showToast({ title: '已升级为VIP', icon: 'success' })
  479. await fetchAllData()
  480. } catch (e) {
  481. uni.showToast({ title: e.message || '操作失败', icon: 'none' })
  482. } finally {
  483. actionLoading.userId = null
  484. actionLoading.type = null
  485. }
  486. }
  487. async function handleDowngrade(userId) {
  488. uni.showModal({
  489. title: '取消VIP',
  490. content: '确定要取消该用户的VIP资格吗?',
  491. success: async (res) => {
  492. if (!res.confirm) return
  493. actionLoading.userId = userId
  494. actionLoading.type = 'downgrade'
  495. try {
  496. await adminApi.downgradeUser(userId)
  497. uni.showToast({ title: '已取消VIP', icon: 'success' })
  498. await fetchAllData()
  499. } catch (e) {
  500. uni.showToast({ title: e.message || '操作失败', icon: 'none' })
  501. } finally {
  502. actionLoading.userId = null
  503. actionLoading.type = null
  504. }
  505. }
  506. })
  507. }
  508. async function handleToggleAdmin(user) {
  509. const newIsAdmin = !user.isAdmin
  510. actionLoading.userId = user.id
  511. actionLoading.type = 'set-admin'
  512. try {
  513. await adminApi.setAdmin(user.id, newIsAdmin)
  514. uni.showToast({ title: newIsAdmin ? '已设为管理员' : '已取消管理员', icon: 'success' })
  515. await fetchAllData()
  516. } catch (e) {
  517. uni.showToast({ title: e.message || '操作失败', icon: 'none' })
  518. } finally {
  519. actionLoading.userId = null
  520. actionLoading.type = null
  521. }
  522. }
  523. // ─── Withdraw Actions ───
  524. async function handleApproveWithdraw(id) {
  525. actionLoading.withdrawId = id
  526. actionLoading.type = 'approve'
  527. try {
  528. await adminApi.approveWithdraw(id)
  529. uni.showToast({ title: '提现已批准', icon: 'success' })
  530. await fetchAllData()
  531. } catch (e) {
  532. uni.showToast({ title: e.message || '操作失败', icon: 'none' })
  533. } finally {
  534. actionLoading.withdrawId = null
  535. actionLoading.type = null
  536. }
  537. }
  538. async function handleRejectWithdraw(id) {
  539. uni.showModal({
  540. title: '拒绝提现',
  541. content: '确定要拒绝该提现申请吗?',
  542. success: async (res) => {
  543. if (!res.confirm) return
  544. actionLoading.withdrawId = id
  545. actionLoading.type = 'reject'
  546. try {
  547. await adminApi.rejectWithdraw(id)
  548. uni.showToast({ title: '提现已拒绝', icon: 'success' })
  549. await fetchAllData()
  550. } catch (e) {
  551. uni.showToast({ title: e.message || '操作失败', icon: 'none' })
  552. } finally {
  553. actionLoading.withdrawId = null
  554. actionLoading.type = null
  555. }
  556. }
  557. })
  558. }
  559. // ─── Config Actions ───
  560. async function handleSaveConfig(configKey) {
  561. const newValue = configEdits[configKey]
  562. if (newValue == null) return
  563. configSaving.value = configKey
  564. try {
  565. await adminApi.configUpdate({ key: configKey, value: newValue })
  566. uni.showToast({ title: '配置已更新', icon: 'success' })
  567. await fetchAllData()
  568. } catch (e) {
  569. uni.showToast({ title: e.message || '保存失败', icon: 'none' })
  570. } finally {
  571. configSaving.value = null
  572. }
  573. }
  574. async function handleResetConfig(configKey) {
  575. uni.showModal({
  576. title: '重置配置',
  577. content: `确定要将 "${configKey}" 重置为默认值吗?`,
  578. success: async (res) => {
  579. if (!res.confirm) return
  580. configResetting.value = configKey
  581. try {
  582. await adminApi.configReset(configKey)
  583. uni.showToast({ title: '配置已重置', icon: 'success' })
  584. await fetchAllData()
  585. } catch (e) {
  586. uni.showToast({ title: e.message || '重置失败', icon: 'none' })
  587. } finally {
  588. configResetting.value = null
  589. }
  590. }
  591. })
  592. }
  593. </script>
  594. <style scoped lang="scss">
  595. @import "@/styles/theme.scss";
  596. .page-admin {
  597. min-height: 100vh;
  598. background: linear-gradient(180deg, #0c0a1a 0%, #1a1232 100%);
  599. padding: 16px;
  600. padding-bottom: 40px;
  601. }
  602. // ─── Placeholder ───
  603. .placeholder-style {
  604. color: rgba(255, 255, 255, 0.25);
  605. }
  606. // ─── Login Screen ───
  607. .login-screen {
  608. display: flex;
  609. align-items: center;
  610. justify-content: center;
  611. min-height: 90vh;
  612. padding: 20px;
  613. }
  614. .login-card {
  615. width: 100%;
  616. max-width: 340px;
  617. background: rgba(255, 255, 255, 0.03);
  618. border: 1px solid rgba(255, 255, 255, 0.06);
  619. border-radius: 20px;
  620. padding: 32px 24px;
  621. }
  622. .login-title {
  623. display: block;
  624. font-size: 26px;
  625. font-weight: 700;
  626. color: rgba(255, 255, 255, 0.95);
  627. text-align: center;
  628. margin-bottom: 6px;
  629. }
  630. .login-subtitle {
  631. display: block;
  632. font-size: 13px;
  633. color: var(--color-text-tertiary);
  634. text-align: center;
  635. margin-bottom: 32px;
  636. }
  637. .login-form {
  638. display: flex;
  639. flex-direction: column;
  640. gap: 16px;
  641. }
  642. .login-field {
  643. display: flex;
  644. flex-direction: column;
  645. gap: 6px;
  646. }
  647. .field-label {
  648. font-size: 13px;
  649. font-weight: 500;
  650. color: var(--color-text-secondary);
  651. }
  652. .field-input {
  653. height: 44px;
  654. padding: 0 14px;
  655. background: rgba(255, 255, 255, 0.04);
  656. border: 1px solid rgba(255, 255, 255, 0.08);
  657. border-radius: 10px;
  658. font-size: 15px;
  659. color: rgba(255, 255, 255, 0.9);
  660. box-sizing: border-box;
  661. }
  662. .login-error {
  663. padding: 8px 12px;
  664. background: rgba(239, 68, 68, 0.1);
  665. border-radius: 8px;
  666. }
  667. .login-error-text {
  668. font-size: 13px;
  669. color: #ef4444;
  670. }
  671. .login-btn {
  672. height: 46px;
  673. margin-top: 8px;
  674. background: linear-gradient(135deg, #3b82f6, #2563eb);
  675. border: none;
  676. border-radius: 12px;
  677. font-size: 16px;
  678. font-weight: 600;
  679. color: #fff;
  680. display: flex;
  681. align-items: center;
  682. justify-content: center;
  683. line-height: 1;
  684. }
  685. .login-btn[disabled] {
  686. opacity: 0.5;
  687. }
  688. // ─── Loading ───
  689. .loading-state {
  690. padding: 60px 0;
  691. text-align: center;
  692. }
  693. .loading-text {
  694. font-size: 14px;
  695. color: var(--color-text-tertiary);
  696. }
  697. // ─── Stats Grid ───
  698. .stats-grid {
  699. display: grid;
  700. grid-template-columns: 1fr 1fr 1fr;
  701. gap: 8px;
  702. margin-bottom: 16px;
  703. }
  704. .stat-card {
  705. background: rgba(255, 255, 255, 0.02);
  706. border: 1px solid rgba(255, 255, 255, 0.04);
  707. border-radius: 14px;
  708. padding: 14px 10px;
  709. text-align: center;
  710. }
  711. .stat-value {
  712. display: block;
  713. font-size: 22px;
  714. font-weight: 700;
  715. margin-bottom: 4px;
  716. }
  717. .stat-label {
  718. display: block;
  719. font-size: 11px;
  720. color: rgba(255, 255, 255, 0.45);
  721. }
  722. .accent-blue { color: #3b82f6; }
  723. .accent-green { color: #10b981; }
  724. .accent-amber { color: #f59e0b; }
  725. .accent-rose { color: #f472b6; }
  726. // ─── Section Card ───
  727. .section-card {
  728. background: rgba(255, 255, 255, 0.02);
  729. border: 1px solid rgba(255, 255, 255, 0.04);
  730. border-radius: 16px;
  731. padding: 14px;
  732. margin-bottom: 16px;
  733. }
  734. .section-header {
  735. margin-bottom: 10px;
  736. }
  737. .section-title {
  738. font-size: 15px;
  739. font-weight: 700;
  740. color: rgba(255, 255, 255, 0.85);
  741. }
  742. .mini-row {
  743. display: flex;
  744. justify-content: space-between;
  745. align-items: center;
  746. padding: 8px 0;
  747. border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  748. }
  749. .mini-row:last-child {
  750. border-bottom: none;
  751. }
  752. .mini-left {
  753. display: flex;
  754. flex-direction: column;
  755. gap: 2px;
  756. }
  757. .mini-label {
  758. font-size: 13px;
  759. font-weight: 500;
  760. color: rgba(255, 255, 255, 0.8);
  761. }
  762. .mini-desc {
  763. font-size: 11px;
  764. color: var(--color-text-tertiary);
  765. }
  766. .mini-right {
  767. text-align: right;
  768. }
  769. .mini-value {
  770. display: block;
  771. font-size: 14px;
  772. font-weight: 600;
  773. }
  774. .mini-status {
  775. font-size: 10px;
  776. padding: 2px 8px;
  777. border-radius: 4px;
  778. display: inline-block;
  779. margin-top: 2px;
  780. }
  781. // ─── Tab Bar ───
  782. .tab-bar {
  783. display: flex;
  784. gap: 6px;
  785. margin-bottom: 14px;
  786. overflow-x: auto;
  787. white-space: nowrap;
  788. -webkit-overflow-scrolling: touch;
  789. padding-bottom: 4px;
  790. }
  791. .tab-item {
  792. flex-shrink: 0;
  793. padding: 8px 16px;
  794. border-radius: 10px;
  795. background: rgba(255, 255, 255, 0.02);
  796. border: 1px solid rgba(255, 255, 255, 0.04);
  797. }
  798. .tab-active {
  799. background: rgba(59, 130, 246, 0.12);
  800. border-color: rgba(59, 130, 246, 0.25);
  801. }
  802. .tab-text {
  803. font-size: 13px;
  804. font-weight: 500;
  805. color: var(--color-text-tertiary);
  806. }
  807. .tab-active .tab-text {
  808. color: #3b82f6;
  809. }
  810. // ─── Tab Content ───
  811. .tab-content {
  812. margin-bottom: 16px;
  813. }
  814. // ─── Data Card ───
  815. .data-card {
  816. background: rgba(255, 255, 255, 0.02);
  817. border: 1px solid rgba(255, 255, 255, 0.04);
  818. border-radius: 14px;
  819. padding: 14px;
  820. margin-bottom: 10px;
  821. }
  822. .data-row {
  823. display: flex;
  824. justify-content: space-between;
  825. align-items: flex-start;
  826. }
  827. .data-left {
  828. flex: 1;
  829. min-width: 0;
  830. }
  831. .data-info {
  832. display: flex;
  833. flex-direction: column;
  834. gap: 3px;
  835. }
  836. .data-primary {
  837. font-size: 14px;
  838. font-weight: 600;
  839. color: rgba(255, 255, 255, 0.85);
  840. }
  841. .data-meta {
  842. font-size: 11px;
  843. color: var(--color-text-tertiary);
  844. }
  845. .data-right {
  846. text-align: right;
  847. flex-shrink: 0;
  848. margin-left: 12px;
  849. }
  850. .data-price {
  851. display: block;
  852. font-size: 15px;
  853. font-weight: 700;
  854. color: rgba(255, 255, 255, 0.85);
  855. margin-bottom: 3px;
  856. }
  857. .data-extras {
  858. margin-top: 6px;
  859. padding-top: 6px;
  860. border-top: 1px solid rgba(255, 255, 255, 0.04);
  861. }
  862. // ─── Tags ───
  863. .tag-vip {
  864. font-size: 10px;
  865. font-weight: 600;
  866. padding: 2px 10px;
  867. border-radius: 999px;
  868. background: rgba(107, 114, 128, 0.2);
  869. color: var(--color-text-tertiary);
  870. }
  871. .tag-vip-active {
  872. background: rgba(16, 185, 129, 0.15);
  873. color: #10b981;
  874. }
  875. .tag-status {
  876. font-size: 10px;
  877. font-weight: 500;
  878. padding: 2px 8px;
  879. border-radius: 4px;
  880. display: inline-block;
  881. }
  882. .tag-status-paid,
  883. .tag-status-settled,
  884. .tag-status-approved,
  885. .tag-status-completed {
  886. background: rgba(16, 185, 129, 0.12);
  887. color: #10b981;
  888. }
  889. .tag-status-unpaid,
  890. .tag-status-pending {
  891. background: rgba(245, 158, 11, 0.12);
  892. color: #f59e0b;
  893. }
  894. .tag-status-cancelled,
  895. .tag-status-rejected {
  896. background: rgba(239, 68, 68, 0.12);
  897. color: #ef4444;
  898. }
  899. .tag-status-refunded {
  900. background: rgba(107, 114, 128, 0.12);
  901. color: #9ca3af;
  902. }
  903. .tag-status-available {
  904. background: rgba(59, 130, 246, 0.12);
  905. color: #3b82f6;
  906. }
  907. .tag-status-withdrawn {
  908. background: rgba(107, 114, 128, 0.12);
  909. color: #9ca3af;
  910. }
  911. .badge-admin {
  912. font-size: 9px;
  913. font-weight: 600;
  914. background: rgba(59, 130, 246, 0.15);
  915. color: #3b82f6;
  916. padding: 1px 6px;
  917. border-radius: 4px;
  918. margin-left: 6px;
  919. vertical-align: middle;
  920. }
  921. // ─── Action Buttons ───
  922. .action-row {
  923. display: flex;
  924. gap: 8px;
  925. margin-top: 10px;
  926. padding-top: 10px;
  927. border-top: 1px solid rgba(255, 255, 255, 0.04);
  928. }
  929. .btn {
  930. border: none;
  931. border-radius: 8px;
  932. font-size: 12px;
  933. font-weight: 600;
  934. display: flex;
  935. align-items: center;
  936. justify-content: center;
  937. line-height: 1;
  938. height: auto;
  939. padding: 8px 14px;
  940. }
  941. .btn-sm {
  942. font-size: 11px;
  943. padding: 6px 12px;
  944. height: 30px;
  945. }
  946. .btn-xxs {
  947. font-size: 10px;
  948. padding: 4px 10px;
  949. height: 26px;
  950. }
  951. .btn-green {
  952. background: #10b981;
  953. color: #fff;
  954. }
  955. .btn-green[disabled] {
  956. opacity: 0.5;
  957. }
  958. .btn-red-outline {
  959. background: transparent;
  960. border: 1px solid #ef4444;
  961. color: #ef4444;
  962. }
  963. .btn-red-outline[disabled] {
  964. opacity: 0.5;
  965. }
  966. .btn-blue-outline {
  967. background: transparent;
  968. border: 1px solid rgba(59, 130, 246, 0.4);
  969. color: #3b82f6;
  970. }
  971. .btn-blue-outline[disabled] {
  972. opacity: 0.5;
  973. }
  974. .btn-amber-outline {
  975. background: transparent;
  976. border: 1px solid rgba(245, 158, 11, 0.4);
  977. color: #f59e0b;
  978. }
  979. .btn-amber-outline[disabled] {
  980. opacity: 0.5;
  981. }
  982. // ─── Config ───
  983. .config-row {
  984. display: flex;
  985. flex-direction: column;
  986. gap: 8px;
  987. }
  988. .config-header {
  989. display: flex;
  990. justify-content: space-between;
  991. align-items: center;
  992. }
  993. .config-value-row {
  994. display: flex;
  995. gap: 8px;
  996. align-items: center;
  997. }
  998. .config-input {
  999. flex: 1;
  1000. height: 34px;
  1001. padding: 0 10px;
  1002. background: rgba(255, 255, 255, 0.04);
  1003. border: 1px solid rgba(255, 255, 255, 0.08);
  1004. border-radius: 8px;
  1005. font-size: 13px;
  1006. color: rgba(255, 255, 255, 0.9);
  1007. box-sizing: border-box;
  1008. min-width: 0;
  1009. }
  1010. .config-desc {
  1011. font-size: 10px;
  1012. }
  1013. // ─── Empty State ───
  1014. .empty-state {
  1015. display: flex;
  1016. align-items: center;
  1017. justify-content: center;
  1018. padding: 60px 20px;
  1019. }
  1020. .empty-text {
  1021. font-size: 13px;
  1022. color: rgba(255, 255, 255, 0.35);
  1023. }
  1024. // ─── Logout ───
  1025. .logout-bar {
  1026. margin-top: 8px;
  1027. padding: 12px 0;
  1028. text-align: center;
  1029. }
  1030. .logout-text {
  1031. font-size: 12px;
  1032. color: var(--color-text-tertiary);
  1033. text-decoration: underline;
  1034. }
  1035. </style>