index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  1. <template>
  2. <view class="container" :style="{ '--font-scale': fontScale }">
  3. <view class="header">
  4. <text class="title">活动管理</text>
  5. <view class="btn-create" @click="goToCreate">
  6. <text class="btn-create-text">+ 新建活动</text>
  7. </view>
  8. </view>
  9. <view class="filter-bar">
  10. <view class="filter-chips">
  11. <view
  12. v-for="f in filterOptions"
  13. :key="f.value"
  14. :class="['filter-chip', currentFilter === f.value ? 'active' : '']"
  15. @click="onFilterChange(f.value)"
  16. >
  17. <text>{{ f.label }}</text>
  18. </view>
  19. </view>
  20. </view>
  21. <view class="activity-list" v-if="activities.length > 0">
  22. <view class="activity-card" v-for="act in activities" :key="act.id"
  23. @click="goToDetail(act.id)">
  24. <view class="act-cover" v-if="act.coverImage">
  25. <image class="cover-img" :src="getImageUrl(act.coverImage)" mode="aspectFill" />
  26. </view>
  27. <view class="act-cover placeholder" v-else>
  28. <text class="cover-placeholder-text">{{ categoryIcon(act.category) }}</text>
  29. </view>
  30. <view class="act-body">
  31. <view class="act-header">
  32. <text class="act-title">{{ act.title || '未命名活动' }}</text>
  33. <text class="act-status" :class="'status-' + act.status">{{ statusText(act.status) }}</text>
  34. </view>
  35. <view class="act-meta">
  36. <text class="meta-item" v-if="act.activityDate">
  37. &#x1F4C5; {{ formatDate(act.activityDate) }}
  38. </text>
  39. <text class="meta-item" v-if="act.location">
  40. &#x1F4CD; {{ act.location }}
  41. </text>
  42. </view>
  43. <view class="act-desc" v-if="act.description">{{ act.description }}</view>
  44. <view class="act-stats">
  45. <text class="stat-item">&#x1F465; {{ act.currentParticipants || 0 }}/{{ act.maxParticipants || 20 }}人</text>
  46. <text class="stat-item" v-if="act.price > 0">&#x1F4B0; {{ act.price / 100 }}元</text>
  47. <text class="stat-item free" v-else>免费</text>
  48. </view>
  49. <view class="act-actions" @click.stop>
  50. <view class="act-btn outline" @click="goToDetail(act.id)">
  51. <text>{{ act.status === 'draft' ? '编辑' : '查看' }}</text>
  52. </view>
  53. <view class="act-btn primary" v-if="act.status === 'draft'" @click="handlePublish(act.id)">
  54. <text>发布</text>
  55. </view>
  56. <view class="act-btn warning" v-if="act.status === 'published'" @click="handleCancel(act.id)">
  57. <text>取消</text>
  58. </view>
  59. <view class="act-btn danger" v-if="act.status === 'draft'" @click="handleDelete(act.id)">
  60. <text>删除</text>
  61. </view>
  62. </view>
  63. </view>
  64. </view>
  65. </view>
  66. <view class="empty" v-else>
  67. <text class="empty-icon">&#x1F3E0;</text>
  68. <text class="empty-title">暂无活动</text>
  69. <text class="empty-desc">创建户外/自然/文化/体育等主题活动,吸引家庭参与</text>
  70. <view class="empty-btn" @click="goToCreate">
  71. <text>立即创建</text>
  72. </view>
  73. </view>
  74. <view class="loading" v-if="loading">
  75. <text class="loading-text">加载中...</text>
  76. </view>
  77. </view>
  78. </template>
  79. <script>
  80. import { getGuideActivityList, publishActivity, cancelActivity, deleteActivity } from '../../../utils/api.js'
  81. import config from '@/config.js'
  82. import { parseDate } from '../../../utils/format.js'
  83. import fontScaleMixin from '@/mixins/font-scale.js'
  84. export default {
  85. mixins: [fontScaleMixin],
  86. data() {
  87. return {
  88. activities: [],
  89. currentFilter: '',
  90. loading: false,
  91. filterOptions: [
  92. { value: '', label: '全部' },
  93. { value: 'draft', label: '草稿' },
  94. { value: 'published', label: '已发布' },
  95. { value: 'cancelled', label: '已取消' },
  96. { value: 'completed', label: '已完成' }
  97. ]
  98. }
  99. },
  100. onShow() {
  101. this.loadActivities()
  102. },
  103. methods: {
  104. loadActivities() {
  105. var self = this
  106. self.loading = true
  107. getGuideActivityList(self.currentFilter).then(function(res) {
  108. self.loading = false
  109. if (res && res.code === 200) {
  110. self.activities = (res.data && Array.isArray(res.data)) ? res.data : []
  111. }
  112. }).catch(function() {
  113. self.loading = false
  114. })
  115. },
  116. onFilterChange(value) {
  117. this.currentFilter = value
  118. this.loadActivities()
  119. },
  120. goToCreate() {
  121. uni.navigateTo({ url: '/pages/guide/activities/detail?activityId=0' })
  122. },
  123. goToDetail(activityId) {
  124. uni.navigateTo({ url: '/pages/guide/activities/detail?activityId=' + activityId })
  125. },
  126. handlePublish(activityId) {
  127. var self = this
  128. uni.showModal({
  129. title: '确认发布',
  130. content: '发布后活动将对外展示,是否继续?',
  131. success: function(res) {
  132. if (res.confirm) {
  133. uni.showLoading({ title: '发布中...' })
  134. publishActivity(activityId).then(function(res) {
  135. uni.hideLoading()
  136. if (res.code === 200) {
  137. uni.showToast({ title: '发布成功', icon: 'success' })
  138. self.loadActivities()
  139. } else {
  140. uni.showToast({ title: res.message || '发布失败', icon: 'none' })
  141. }
  142. }).catch(function() {
  143. uni.hideLoading()
  144. uni.showToast({ title: '网络异常', icon: 'none' })
  145. })
  146. }
  147. }
  148. })
  149. },
  150. handleCancel(activityId) {
  151. var self = this
  152. uni.showModal({
  153. title: '确认取消',
  154. content: '取消后活动将不再对外展示,是否继续?',
  155. success: function(res) {
  156. if (res.confirm) {
  157. cancelActivity(activityId).then(function(r) {
  158. if (r.code === 200) {
  159. uni.showToast({ title: '已取消', icon: 'success' })
  160. self.loadActivities()
  161. } else {
  162. uni.showToast({ title: r.message || '操作失败', icon: 'none' })
  163. }
  164. }).catch(function() {})
  165. }
  166. }
  167. })
  168. },
  169. handleDelete(activityId) {
  170. var self = this
  171. uni.showModal({
  172. title: '确认删除',
  173. content: '删除后无法恢复,是否确定删除?',
  174. success: function(res) {
  175. if (res.confirm) {
  176. deleteActivity(activityId).then(function(r) {
  177. if (r.code === 200) {
  178. uni.showToast({ title: '已删除', icon: 'success' })
  179. self.loadActivities()
  180. } else {
  181. uni.showToast({ title: r.message || '删除失败', icon: 'none' })
  182. }
  183. }).catch(function() {})
  184. }
  185. }
  186. })
  187. },
  188. statusText(status) {
  189. var map = { draft: '草稿', published: '已发布', cancelled: '已取消', completed: '已完成' }
  190. return map[status] || status || '草稿'
  191. },
  192. categoryIcon(category) {
  193. var map = { outdoor: '&#x26F5;', nature: '&#x1F33F;', culture: '&#x1F3A8;', sports: '&#x26BD;', other: '&#x1F3E0;' }
  194. return map[category] || '&#x1F3E0;'
  195. },
  196. formatDate(dateStr) {
  197. if (!dateStr) return ''
  198. var d = parseDate(dateStr)
  199. if (!d) return ''
  200. var y = d.getFullYear()
  201. var m = ('0' + (d.getMonth() + 1)).slice(-2)
  202. var day = ('0' + d.getDate()).slice(-2)
  203. var h = ('0' + d.getHours()).slice(-2)
  204. var mi = ('0' + d.getMinutes()).slice(-2)
  205. return y + '-' + m + '-' + day + ' ' + h + ':' + mi
  206. },getImageUrl: function(path) {
  207. if (!path || path === 'null' || path === 'undefined' || path === '/null') return ''
  208. var s = String(path).trim()
  209. if (!s || s === 'null' || s === '/null') return ''
  210. if (s.indexOf('http://') === 0 || s.indexOf('https://') === 0) return s
  211. return config.API_BASE_URL + (s.charAt(0) === '/' ? s : '/' + s)
  212. }
  213. }
  214. }
  215. </script>
  216. <style scoped lang="scss">
  217. .container {
  218. min-height: 100vh;
  219. background: $app-bg;
  220. padding-bottom: 40rpx;
  221. }
  222. .header {
  223. display: flex;
  224. flex-direction: row;
  225. justify-content: space-between;
  226. align-items: center;
  227. padding: $uni-space-page;
  228. background: $app-surface;
  229. }
  230. .title {
  231. font-size: calc(36rpx * var(--font-scale, 1));
  232. font-weight: bold;
  233. color: $facade-text-strong;
  234. }
  235. .btn-create {
  236. background: linear-gradient(135deg, $status-success, $status-success-deep);
  237. padding: 14rpx 32rpx;
  238. border-radius: 24rpx;
  239. box-shadow: 0 4rpx 12rpx rgba(16, 185, 129, 0.3);
  240. }
  241. .btn-create:active { opacity: 0.8; }
  242. .btn-create-text {
  243. color: $app-surface;
  244. font-size: calc(28rpx * var(--font-scale, 1));
  245. font-weight: 500;
  246. }
  247. .filter-bar {
  248. background: $app-surface;
  249. padding: 0 $uni-space-page 20rpx;
  250. border-bottom: 1rpx solid $facade-fill;
  251. }
  252. .filter-chips {
  253. display: flex;
  254. flex-direction: row;
  255. gap: 12rpx;
  256. overflow-x: auto;
  257. -webkit-overflow-scrolling: touch;
  258. }
  259. .filter-chip {
  260. flex-shrink: 0;
  261. padding: 10rpx 24rpx;
  262. border-radius: 24rpx;
  263. background: $facade-fill-gray-100;
  264. border: 1rpx solid $facade-gray-200;
  265. }
  266. .filter-chip.active {
  267. background: $status-success-soft;
  268. border-color: $status-success;
  269. }
  270. .filter-chip text {
  271. font-size: calc(26rpx * var(--font-scale, 1));
  272. color: $facade-text-body;
  273. }
  274. .filter-chip.active text {
  275. color: $status-success-deep;
  276. font-weight: 500;
  277. }
  278. .activity-list {
  279. padding: 20rpx $uni-space-page;
  280. display: flex;
  281. flex-direction: column;
  282. gap: 20rpx;
  283. }
  284. .activity-card {
  285. background: $app-surface;
  286. border-radius: 24rpx;
  287. overflow: hidden;
  288. box-shadow: 0 4rpx 16rpx rgba(0,0,0,0.05);
  289. display: flex;
  290. flex-direction: row;
  291. }
  292. .act-cover {
  293. width: 200rpx;
  294. height: 200rpx;
  295. flex-shrink: 0;
  296. }
  297. .cover-img {
  298. width: 100%;
  299. height: 100%;
  300. }
  301. .act-cover.placeholder {
  302. background: linear-gradient(135deg, $status-success 0%, $status-success-deep 100%);
  303. display: flex;
  304. align-items: center;
  305. justify-content: center;
  306. }
  307. .cover-placeholder-text {
  308. font-size: calc($uni-font-size-4xl * var(--font-scale, 1));
  309. color: $app-surface;
  310. }
  311. .act-body {
  312. flex: 1;
  313. padding: 20rpx;
  314. display: flex;
  315. flex-direction: column;
  316. }
  317. .act-header {
  318. display: flex;
  319. flex-direction: row;
  320. justify-content: space-between;
  321. align-items: flex-start;
  322. margin-bottom: 8rpx;
  323. }
  324. .act-title {
  325. font-size: calc(30rpx * var(--font-scale, 1));
  326. font-weight: bold;
  327. color: $facade-text-strong;
  328. flex: 1;
  329. margin-right: 12rpx;
  330. }
  331. .act-status {
  332. font-size: calc(22rpx * var(--font-scale, 1));
  333. padding: 4rpx 14rpx;
  334. border-radius: 16rpx;
  335. flex-shrink: 0;
  336. }
  337. .status-draft { background: $facade-fill-gray-100; color: $facade-text-body; }
  338. .status-published { background: $status-success-soft; color: $status-success-deep; }
  339. .status-cancelled { background: $status-danger-soft; color: $status-danger-deep; }
  340. .status-completed { background: $status-info-soft; color: $status-info-deep; }
  341. .act-meta {
  342. display: flex;
  343. flex-direction: row;
  344. gap: 16rpx;
  345. margin-bottom: 6rpx;
  346. }
  347. .meta-item {
  348. font-size: calc(24rpx * var(--font-scale, 1));
  349. color: $facade-text-faint;
  350. }
  351. .act-desc {
  352. font-size: calc(24rpx * var(--font-scale, 1));
  353. color: $facade-text-faint;
  354. line-height: 1.4;
  355. margin-bottom: 8rpx;
  356. overflow: hidden;
  357. text-overflow: ellipsis;
  358. display: -webkit-box;
  359. -webkit-line-clamp: 2;
  360. -webkit-box-orient: vertical;
  361. }
  362. .act-stats {
  363. display: flex;
  364. flex-direction: row;
  365. gap: 16rpx;
  366. margin-bottom: 12rpx;
  367. }
  368. .stat-item {
  369. font-size: calc(24rpx * var(--font-scale, 1));
  370. color: $facade-text-body;
  371. }
  372. .stat-item.free {
  373. color: $status-success;
  374. font-weight: 500;
  375. }
  376. .act-actions {
  377. display: flex;
  378. flex-direction: row;
  379. flex-wrap: wrap;
  380. gap: 10rpx;
  381. margin-top: auto;
  382. border-top: 1rpx solid $facade-fill;
  383. padding-top: 12rpx;
  384. }
  385. .act-btn {
  386. padding: 8rpx 20rpx;
  387. border-radius: 24rpx;
  388. font-size: calc(24rpx * var(--font-scale, 1));
  389. }
  390. .act-btn:active { opacity: 0.7; }
  391. .act-btn.outline {
  392. background: $facade-fill-gray-50;
  393. color: $facade-text-gray-700;
  394. border: 1rpx solid $facade-gray-200;
  395. }
  396. .act-btn.primary {
  397. background: $status-success;
  398. color: $app-surface;
  399. }
  400. .act-btn.warning {
  401. background: $status-danger-soft;
  402. color: $status-danger-deep;
  403. }
  404. .act-btn.danger {
  405. background: $status-danger-soft;
  406. color: $status-danger-deep;
  407. }
  408. .empty {
  409. display: flex;
  410. flex-direction: column;
  411. align-items: center;
  412. padding: 120rpx 40rpx 80rpx;
  413. }
  414. .empty-icon {
  415. font-size: calc($uni-font-size-6xl * var(--font-scale, 1));
  416. margin-bottom: 20rpx;
  417. }
  418. .empty-title {
  419. font-size: calc(32rpx * var(--font-scale, 1));
  420. color: $facade-text-strong;
  421. font-weight: bold;
  422. margin-bottom: 12rpx;
  423. }
  424. .empty-desc {
  425. font-size: calc(26rpx * var(--font-scale, 1));
  426. color: $facade-text-muted;
  427. text-align: center;
  428. line-height: 1.6;
  429. margin-bottom: 40rpx;
  430. }
  431. .empty-btn {
  432. background: linear-gradient(135deg, $status-success, $status-success-deep);
  433. padding: 16rpx 48rpx;
  434. border-radius: 24rpx;
  435. box-shadow: 0 4rpx 16rpx rgba(16, 185, 129, 0.3);
  436. }
  437. .empty-btn:active { opacity: 0.8; }
  438. .empty-btn text {
  439. color: $app-surface;
  440. font-size: calc(28rpx * var(--font-scale, 1));
  441. font-weight: 500;
  442. }
  443. .loading {
  444. display: flex;
  445. align-items: center;
  446. justify-content: center;
  447. padding: 80rpx;
  448. }
  449. .loading-text {
  450. font-size: calc(28rpx * var(--font-scale, 1));
  451. color: $facade-text-muted;
  452. }
  453. </style>