index.vue 12 KB

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