index.vue 12 KB

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