index.vue 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145
  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. .page-admin {
  596. min-height: 100vh;
  597. background: linear-gradient(180deg, #0c0a1a 0%, #1a1232 100%);
  598. padding: 16px;
  599. padding-bottom: 40px;
  600. }
  601. // ─── Placeholder ───
  602. .placeholder-style {
  603. color: rgba(255, 255, 255, 0.25);
  604. }
  605. // ─── Login Screen ───
  606. .login-screen {
  607. display: flex;
  608. align-items: center;
  609. justify-content: center;
  610. min-height: 90vh;
  611. padding: 20px;
  612. }
  613. .login-card {
  614. width: 100%;
  615. max-width: 340px;
  616. background: rgba(255, 255, 255, 0.03);
  617. border: 1px solid rgba(255, 255, 255, 0.06);
  618. border-radius: 20px;
  619. padding: 32px 24px;
  620. }
  621. .login-title {
  622. display: block;
  623. font-size: 26px;
  624. font-weight: 700;
  625. color: rgba(255, 255, 255, 0.95);
  626. text-align: center;
  627. margin-bottom: 6px;
  628. }
  629. .login-subtitle {
  630. display: block;
  631. font-size: 13px;
  632. color: rgba(255, 255, 255, 0.4);
  633. text-align: center;
  634. margin-bottom: 32px;
  635. }
  636. .login-form {
  637. display: flex;
  638. flex-direction: column;
  639. gap: 16px;
  640. }
  641. .login-field {
  642. display: flex;
  643. flex-direction: column;
  644. gap: 6px;
  645. }
  646. .field-label {
  647. font-size: 13px;
  648. font-weight: 500;
  649. color: rgba(255, 255, 255, 0.6);
  650. }
  651. .field-input {
  652. height: 44px;
  653. padding: 0 14px;
  654. background: rgba(255, 255, 255, 0.04);
  655. border: 1px solid rgba(255, 255, 255, 0.08);
  656. border-radius: 10px;
  657. font-size: 15px;
  658. color: rgba(255, 255, 255, 0.9);
  659. box-sizing: border-box;
  660. }
  661. .login-error {
  662. padding: 8px 12px;
  663. background: rgba(239, 68, 68, 0.1);
  664. border-radius: 8px;
  665. }
  666. .login-error-text {
  667. font-size: 13px;
  668. color: #ef4444;
  669. }
  670. .login-btn {
  671. height: 46px;
  672. margin-top: 8px;
  673. background: linear-gradient(135deg, #3b82f6, #2563eb);
  674. border: none;
  675. border-radius: 12px;
  676. font-size: 16px;
  677. font-weight: 600;
  678. color: #fff;
  679. display: flex;
  680. align-items: center;
  681. justify-content: center;
  682. line-height: 1;
  683. }
  684. .login-btn[disabled] {
  685. opacity: 0.5;
  686. }
  687. // ─── Loading ───
  688. .loading-state {
  689. padding: 60px 0;
  690. text-align: center;
  691. }
  692. .loading-text {
  693. font-size: 14px;
  694. color: rgba(255, 255, 255, 0.4);
  695. }
  696. // ─── Stats Grid ───
  697. .stats-grid {
  698. display: grid;
  699. grid-template-columns: 1fr 1fr 1fr;
  700. gap: 8px;
  701. margin-bottom: 16px;
  702. }
  703. .stat-card {
  704. background: rgba(255, 255, 255, 0.02);
  705. border: 1px solid rgba(255, 255, 255, 0.04);
  706. border-radius: 14px;
  707. padding: 14px 10px;
  708. text-align: center;
  709. }
  710. .stat-value {
  711. display: block;
  712. font-size: 22px;
  713. font-weight: 700;
  714. margin-bottom: 4px;
  715. }
  716. .stat-label {
  717. display: block;
  718. font-size: 11px;
  719. color: rgba(255, 255, 255, 0.45);
  720. }
  721. .accent-blue { color: #3b82f6; }
  722. .accent-green { color: #10b981; }
  723. .accent-amber { color: #f59e0b; }
  724. .accent-rose { color: #f472b6; }
  725. // ─── Section Card ───
  726. .section-card {
  727. background: rgba(255, 255, 255, 0.02);
  728. border: 1px solid rgba(255, 255, 255, 0.04);
  729. border-radius: 16px;
  730. padding: 14px;
  731. margin-bottom: 16px;
  732. }
  733. .section-header {
  734. margin-bottom: 10px;
  735. }
  736. .section-title {
  737. font-size: 15px;
  738. font-weight: 700;
  739. color: rgba(255, 255, 255, 0.85);
  740. }
  741. .mini-row {
  742. display: flex;
  743. justify-content: space-between;
  744. align-items: center;
  745. padding: 8px 0;
  746. border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  747. }
  748. .mini-row:last-child {
  749. border-bottom: none;
  750. }
  751. .mini-left {
  752. display: flex;
  753. flex-direction: column;
  754. gap: 2px;
  755. }
  756. .mini-label {
  757. font-size: 13px;
  758. font-weight: 500;
  759. color: rgba(255, 255, 255, 0.8);
  760. }
  761. .mini-desc {
  762. font-size: 11px;
  763. color: rgba(255, 255, 255, 0.4);
  764. }
  765. .mini-right {
  766. text-align: right;
  767. }
  768. .mini-value {
  769. display: block;
  770. font-size: 14px;
  771. font-weight: 600;
  772. }
  773. .mini-status {
  774. font-size: 10px;
  775. padding: 2px 8px;
  776. border-radius: 4px;
  777. display: inline-block;
  778. margin-top: 2px;
  779. }
  780. // ─── Tab Bar ───
  781. .tab-bar {
  782. display: flex;
  783. gap: 6px;
  784. margin-bottom: 14px;
  785. overflow-x: auto;
  786. white-space: nowrap;
  787. -webkit-overflow-scrolling: touch;
  788. padding-bottom: 4px;
  789. }
  790. .tab-item {
  791. flex-shrink: 0;
  792. padding: 8px 16px;
  793. border-radius: 10px;
  794. background: rgba(255, 255, 255, 0.02);
  795. border: 1px solid rgba(255, 255, 255, 0.04);
  796. }
  797. .tab-active {
  798. background: rgba(59, 130, 246, 0.12);
  799. border-color: rgba(59, 130, 246, 0.25);
  800. }
  801. .tab-text {
  802. font-size: 13px;
  803. font-weight: 500;
  804. color: rgba(255, 255, 255, 0.5);
  805. }
  806. .tab-active .tab-text {
  807. color: #3b82f6;
  808. }
  809. // ─── Tab Content ───
  810. .tab-content {
  811. margin-bottom: 16px;
  812. }
  813. // ─── Data Card ───
  814. .data-card {
  815. background: rgba(255, 255, 255, 0.02);
  816. border: 1px solid rgba(255, 255, 255, 0.04);
  817. border-radius: 14px;
  818. padding: 14px;
  819. margin-bottom: 10px;
  820. }
  821. .data-row {
  822. display: flex;
  823. justify-content: space-between;
  824. align-items: flex-start;
  825. }
  826. .data-left {
  827. flex: 1;
  828. min-width: 0;
  829. }
  830. .data-info {
  831. display: flex;
  832. flex-direction: column;
  833. gap: 3px;
  834. }
  835. .data-primary {
  836. font-size: 14px;
  837. font-weight: 600;
  838. color: rgba(255, 255, 255, 0.85);
  839. }
  840. .data-meta {
  841. font-size: 11px;
  842. color: rgba(255, 255, 255, 0.4);
  843. }
  844. .data-right {
  845. text-align: right;
  846. flex-shrink: 0;
  847. margin-left: 12px;
  848. }
  849. .data-price {
  850. display: block;
  851. font-size: 15px;
  852. font-weight: 700;
  853. color: rgba(255, 255, 255, 0.85);
  854. margin-bottom: 3px;
  855. }
  856. .data-extras {
  857. margin-top: 6px;
  858. padding-top: 6px;
  859. border-top: 1px solid rgba(255, 255, 255, 0.04);
  860. }
  861. // ─── Tags ───
  862. .tag-vip {
  863. font-size: 10px;
  864. font-weight: 600;
  865. padding: 2px 10px;
  866. border-radius: 999px;
  867. background: rgba(107, 114, 128, 0.2);
  868. color: rgba(255, 255, 255, 0.4);
  869. }
  870. .tag-vip-active {
  871. background: rgba(16, 185, 129, 0.15);
  872. color: #10b981;
  873. }
  874. .tag-status {
  875. font-size: 10px;
  876. font-weight: 500;
  877. padding: 2px 8px;
  878. border-radius: 4px;
  879. display: inline-block;
  880. }
  881. .tag-status-paid,
  882. .tag-status-settled,
  883. .tag-status-approved,
  884. .tag-status-completed {
  885. background: rgba(16, 185, 129, 0.12);
  886. color: #10b981;
  887. }
  888. .tag-status-unpaid,
  889. .tag-status-pending {
  890. background: rgba(245, 158, 11, 0.12);
  891. color: #f59e0b;
  892. }
  893. .tag-status-cancelled,
  894. .tag-status-rejected {
  895. background: rgba(239, 68, 68, 0.12);
  896. color: #ef4444;
  897. }
  898. .tag-status-refunded {
  899. background: rgba(107, 114, 128, 0.12);
  900. color: #9ca3af;
  901. }
  902. .tag-status-available {
  903. background: rgba(59, 130, 246, 0.12);
  904. color: #3b82f6;
  905. }
  906. .tag-status-withdrawn {
  907. background: rgba(107, 114, 128, 0.12);
  908. color: #9ca3af;
  909. }
  910. .badge-admin {
  911. font-size: 9px;
  912. font-weight: 600;
  913. background: rgba(59, 130, 246, 0.15);
  914. color: #3b82f6;
  915. padding: 1px 6px;
  916. border-radius: 4px;
  917. margin-left: 6px;
  918. vertical-align: middle;
  919. }
  920. // ─── Action Buttons ───
  921. .action-row {
  922. display: flex;
  923. gap: 8px;
  924. margin-top: 10px;
  925. padding-top: 10px;
  926. border-top: 1px solid rgba(255, 255, 255, 0.04);
  927. }
  928. .btn {
  929. border: none;
  930. border-radius: 8px;
  931. font-size: 12px;
  932. font-weight: 600;
  933. display: flex;
  934. align-items: center;
  935. justify-content: center;
  936. line-height: 1;
  937. height: auto;
  938. padding: 8px 14px;
  939. }
  940. .btn-sm {
  941. font-size: 11px;
  942. padding: 6px 12px;
  943. height: 30px;
  944. }
  945. .btn-xxs {
  946. font-size: 10px;
  947. padding: 4px 10px;
  948. height: 26px;
  949. }
  950. .btn-green {
  951. background: #10b981;
  952. color: #fff;
  953. }
  954. .btn-green[disabled] {
  955. opacity: 0.5;
  956. }
  957. .btn-red-outline {
  958. background: transparent;
  959. border: 1px solid #ef4444;
  960. color: #ef4444;
  961. }
  962. .btn-red-outline[disabled] {
  963. opacity: 0.5;
  964. }
  965. .btn-blue-outline {
  966. background: transparent;
  967. border: 1px solid rgba(59, 130, 246, 0.4);
  968. color: #3b82f6;
  969. }
  970. .btn-blue-outline[disabled] {
  971. opacity: 0.5;
  972. }
  973. .btn-amber-outline {
  974. background: transparent;
  975. border: 1px solid rgba(245, 158, 11, 0.4);
  976. color: #f59e0b;
  977. }
  978. .btn-amber-outline[disabled] {
  979. opacity: 0.5;
  980. }
  981. // ─── Config ───
  982. .config-row {
  983. display: flex;
  984. flex-direction: column;
  985. gap: 8px;
  986. }
  987. .config-header {
  988. display: flex;
  989. justify-content: space-between;
  990. align-items: center;
  991. }
  992. .config-value-row {
  993. display: flex;
  994. gap: 8px;
  995. align-items: center;
  996. }
  997. .config-input {
  998. flex: 1;
  999. height: 34px;
  1000. padding: 0 10px;
  1001. background: rgba(255, 255, 255, 0.04);
  1002. border: 1px solid rgba(255, 255, 255, 0.08);
  1003. border-radius: 8px;
  1004. font-size: 13px;
  1005. color: rgba(255, 255, 255, 0.9);
  1006. box-sizing: border-box;
  1007. min-width: 0;
  1008. }
  1009. .config-desc {
  1010. font-size: 10px;
  1011. }
  1012. // ─── Empty State ───
  1013. .empty-state {
  1014. display: flex;
  1015. align-items: center;
  1016. justify-content: center;
  1017. padding: 60px 20px;
  1018. }
  1019. .empty-text {
  1020. font-size: 13px;
  1021. color: rgba(255, 255, 255, 0.35);
  1022. }
  1023. // ─── Logout ───
  1024. .logout-bar {
  1025. margin-top: 8px;
  1026. padding: 12px 0;
  1027. text-align: center;
  1028. }
  1029. .logout-text {
  1030. font-size: 12px;
  1031. color: rgba(255, 255, 255, 0.3);
  1032. text-decoration: underline;
  1033. }
  1034. </style>