index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  1. <template>
  2. <view class="container">
  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 { getActivityList, publishActivity, cancelActivity, deleteActivity } from '../../../utils/api.js'
  81. import config from '@/config.js'
  82. export default {
  83. data() {
  84. return {
  85. activities: [],
  86. currentFilter: '',
  87. loading: false,
  88. filterOptions: [
  89. { value: '', label: '全部' },
  90. { value: 'draft', label: '草稿' },
  91. { value: 'published', label: '已发布' },
  92. { value: 'cancelled', label: '已取消' },
  93. { value: 'completed', label: '已完成' }
  94. ]
  95. }
  96. },
  97. onShow() {
  98. this.loadActivities()
  99. },
  100. methods: {
  101. loadActivities() {
  102. var self = this
  103. self.loading = true
  104. getActivityList(self.currentFilter).then(function(res) {
  105. self.loading = false
  106. if (res.code === 200) {
  107. self.activities = res.data || []
  108. }
  109. }).catch(function() {
  110. self.loading = false
  111. })
  112. },
  113. onFilterChange(value) {
  114. this.currentFilter = value
  115. this.loadActivities()
  116. },
  117. goToCreate() {
  118. uni.navigateTo({ url: '/pages/guide/activities/detail?activityId=0' })
  119. },
  120. goToDetail(activityId) {
  121. uni.navigateTo({ url: '/pages/guide/activities/detail?activityId=' + activityId })
  122. },
  123. handlePublish(activityId) {
  124. var self = this
  125. uni.showModal({
  126. title: '确认发布',
  127. content: '发布后活动将对外展示,是否继续?',
  128. success: function(res) {
  129. if (res.confirm) {
  130. uni.showLoading({ title: '发布中...' })
  131. publishActivity(activityId).then(function(res) {
  132. uni.hideLoading()
  133. if (res.code === 200) {
  134. uni.showToast({ title: '发布成功', icon: 'success' })
  135. self.loadActivities()
  136. } else {
  137. uni.showToast({ title: res.message || '发布失败', icon: 'none' })
  138. }
  139. }).catch(function() {
  140. uni.hideLoading()
  141. uni.showToast({ title: '网络异常', icon: 'none' })
  142. })
  143. }
  144. }
  145. })
  146. },
  147. handleCancel(activityId) {
  148. var self = this
  149. uni.showModal({
  150. title: '确认取消',
  151. content: '取消后活动将不再对外展示,是否继续?',
  152. success: function(res) {
  153. if (res.confirm) {
  154. cancelActivity(activityId).then(function(r) {
  155. if (r.code === 200) {
  156. uni.showToast({ title: '已取消', icon: 'success' })
  157. self.loadActivities()
  158. } else {
  159. uni.showToast({ title: r.message || '操作失败', icon: 'none' })
  160. }
  161. }).catch(function() {})
  162. }
  163. }
  164. })
  165. },
  166. handleDelete(activityId) {
  167. var self = this
  168. uni.showModal({
  169. title: '确认删除',
  170. content: '删除后无法恢复,是否确定删除?',
  171. success: function(res) {
  172. if (res.confirm) {
  173. deleteActivity(activityId).then(function(r) {
  174. if (r.code === 200) {
  175. uni.showToast({ title: '已删除', icon: 'success' })
  176. self.loadActivities()
  177. } else {
  178. uni.showToast({ title: r.message || '删除失败', icon: 'none' })
  179. }
  180. }).catch(function() {})
  181. }
  182. }
  183. })
  184. },
  185. statusText(status) {
  186. var map = { draft: '草稿', published: '已发布', cancelled: '已取消', completed: '已完成' }
  187. return map[status] || status || '草稿'
  188. },
  189. categoryIcon(category) {
  190. var map = { outdoor: '&#x26F5;', nature: '&#x1F33F;', culture: '&#x1F3A8;', sports: '&#x26BD;', other: '&#x1F3E0;' }
  191. return map[category] || '&#x1F3E0;'
  192. },
  193. formatDate(dateStr) {
  194. if (!dateStr) return ''
  195. var d = new Date(dateStr)
  196. var y = d.getFullYear()
  197. var m = ('0' + (d.getMonth() + 1)).slice(-2)
  198. var day = ('0' + d.getDate()).slice(-2)
  199. var h = ('0' + d.getHours()).slice(-2)
  200. var mi = ('0' + d.getMinutes()).slice(-2)
  201. return y + '-' + m + '-' + day + ' ' + h + ':' + mi
  202. },
  203. getImageUrl: function(path) {
  204. return config.API_BASE_URL + path
  205. }
  206. }
  207. }
  208. </script>
  209. <style scoped>
  210. .container {
  211. min-height: 100vh;
  212. background: #f5f7fa;
  213. padding-bottom: 40rpx;
  214. }
  215. .header {
  216. display: flex;
  217. flex-direction: row;
  218. justify-content: space-between;
  219. align-items: center;
  220. padding: 30rpx;
  221. background: #fff;
  222. }
  223. .title {
  224. font-size: 36rpx;
  225. font-weight: bold;
  226. color: #333;
  227. }
  228. .btn-create {
  229. background: linear-gradient(135deg, #10B981, #059669);
  230. padding: 14rpx 32rpx;
  231. border-radius: 32rpx;
  232. box-shadow: 0 4rpx 12rpx rgba(16, 185, 129, 0.3);
  233. }
  234. .btn-create:active { opacity: 0.8; }
  235. .btn-create-text {
  236. color: #fff;
  237. font-size: 28rpx;
  238. font-weight: 500;
  239. }
  240. .filter-bar {
  241. background: #fff;
  242. padding: 0 30rpx 20rpx;
  243. border-bottom: 1rpx solid #f0f0f0;
  244. }
  245. .filter-chips {
  246. display: flex;
  247. flex-direction: row;
  248. gap: 12rpx;
  249. overflow-x: auto;
  250. -webkit-overflow-scrolling: touch;
  251. }
  252. .filter-chip {
  253. flex-shrink: 0;
  254. padding: 10rpx 24rpx;
  255. border-radius: 20rpx;
  256. background: #f3f4f6;
  257. border: 1rpx solid #e5e7eb;
  258. }
  259. .filter-chip.active {
  260. background: #d1fae5;
  261. border-color: #10B981;
  262. }
  263. .filter-chip text {
  264. font-size: 26rpx;
  265. color: #666;
  266. }
  267. .filter-chip.active text {
  268. color: #059669;
  269. font-weight: 500;
  270. }
  271. .activity-list {
  272. padding: 20rpx 30rpx;
  273. display: flex;
  274. flex-direction: column;
  275. gap: 20rpx;
  276. }
  277. .activity-card {
  278. background: #fff;
  279. border-radius: 20rpx;
  280. overflow: hidden;
  281. box-shadow: 0 4rpx 16rpx rgba(0,0,0,0.05);
  282. display: flex;
  283. flex-direction: row;
  284. }
  285. .act-cover {
  286. width: 200rpx;
  287. height: 200rpx;
  288. flex-shrink: 0;
  289. }
  290. .cover-img {
  291. width: 100%;
  292. height: 100%;
  293. }
  294. .act-cover.placeholder {
  295. background: linear-gradient(135deg, #10B981 0%, #059669 100%);
  296. display: flex;
  297. align-items: center;
  298. justify-content: center;
  299. }
  300. .cover-placeholder-text {
  301. font-size: 60rpx;
  302. color: #fff;
  303. }
  304. .act-body {
  305. flex: 1;
  306. padding: 20rpx;
  307. display: flex;
  308. flex-direction: column;
  309. }
  310. .act-header {
  311. display: flex;
  312. flex-direction: row;
  313. justify-content: space-between;
  314. align-items: flex-start;
  315. margin-bottom: 8rpx;
  316. }
  317. .act-title {
  318. font-size: 30rpx;
  319. font-weight: bold;
  320. color: #333;
  321. flex: 1;
  322. margin-right: 12rpx;
  323. }
  324. .act-status {
  325. font-size: 22rpx;
  326. padding: 4rpx 14rpx;
  327. border-radius: 14rpx;
  328. flex-shrink: 0;
  329. }
  330. .status-draft { background: #f3f4f6; color: #666; }
  331. .status-published { background: #d1fae5; color: #059669; }
  332. .status-cancelled { background: #fee2e2; color: #dc2626; }
  333. .status-completed { background: #dbeafe; color: #2563eb; }
  334. .act-meta {
  335. display: flex;
  336. flex-direction: row;
  337. gap: 16rpx;
  338. margin-bottom: 6rpx;
  339. }
  340. .meta-item {
  341. font-size: 24rpx;
  342. color: #888;
  343. }
  344. .act-desc {
  345. font-size: 24rpx;
  346. color: #888;
  347. line-height: 1.4;
  348. margin-bottom: 8rpx;
  349. overflow: hidden;
  350. text-overflow: ellipsis;
  351. display: -webkit-box;
  352. -webkit-line-clamp: 2;
  353. -webkit-box-orient: vertical;
  354. }
  355. .act-stats {
  356. display: flex;
  357. flex-direction: row;
  358. gap: 16rpx;
  359. margin-bottom: 12rpx;
  360. }
  361. .stat-item {
  362. font-size: 24rpx;
  363. color: #666;
  364. }
  365. .stat-item.free {
  366. color: #10B981;
  367. font-weight: 500;
  368. }
  369. .act-actions {
  370. display: flex;
  371. flex-direction: row;
  372. flex-wrap: wrap;
  373. gap: 10rpx;
  374. margin-top: auto;
  375. border-top: 1rpx solid #f0f0f0;
  376. padding-top: 12rpx;
  377. }
  378. .act-btn {
  379. padding: 8rpx 20rpx;
  380. border-radius: 20rpx;
  381. font-size: 24rpx;
  382. }
  383. .act-btn:active { opacity: 0.7; }
  384. .act-btn.outline {
  385. background: #f9fafb;
  386. color: #374151;
  387. border: 1rpx solid #e5e7eb;
  388. }
  389. .act-btn.primary {
  390. background: #10B981;
  391. color: #fff;
  392. }
  393. .act-btn.warning {
  394. background: #fee2e2;
  395. color: #dc2626;
  396. }
  397. .act-btn.danger {
  398. background: #fee2e2;
  399. color: #dc2626;
  400. }
  401. .empty {
  402. display: flex;
  403. flex-direction: column;
  404. align-items: center;
  405. padding: 120rpx 40rpx 80rpx;
  406. }
  407. .empty-icon {
  408. font-size: 100rpx;
  409. margin-bottom: 20rpx;
  410. }
  411. .empty-title {
  412. font-size: 32rpx;
  413. color: #333;
  414. font-weight: bold;
  415. margin-bottom: 12rpx;
  416. }
  417. .empty-desc {
  418. font-size: 26rpx;
  419. color: #999;
  420. text-align: center;
  421. line-height: 1.6;
  422. margin-bottom: 40rpx;
  423. }
  424. .empty-btn {
  425. background: linear-gradient(135deg, #10B981, #059669);
  426. padding: 16rpx 48rpx;
  427. border-radius: 40rpx;
  428. box-shadow: 0 4rpx 16rpx rgba(16, 185, 129, 0.3);
  429. }
  430. .empty-btn:active { opacity: 0.8; }
  431. .empty-btn text {
  432. color: #fff;
  433. font-size: 28rpx;
  434. font-weight: 500;
  435. }
  436. .loading {
  437. display: flex;
  438. align-items: center;
  439. justify-content: center;
  440. padding: 80rpx;
  441. }
  442. .loading-text {
  443. font-size: 28rpx;
  444. color: #999;
  445. }
  446. </style>