index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  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 { getGuideActivityList, 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. getGuideActivityList(self.currentFilter).then(function(res) {
  106. self.loading = false
  107. if (res && res.code === 200) {
  108. self.activities = (res.data && Array.isArray(res.data)) ? 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. },getImageUrl: function(path) {
  205. if (!path || path === 'null' || path === 'undefined' || path === '/null') return ''
  206. var s = String(path).trim()
  207. if (!s || s === 'null' || s === '/null') return ''
  208. if (s.indexOf('http://') === 0 || s.indexOf('https://') === 0) return s
  209. return config.API_BASE_URL + (s.charAt(0) === '/' ? s : '/' + s)
  210. }
  211. }
  212. }
  213. </script>
  214. <style scoped>
  215. .container {
  216. min-height: 100vh;
  217. background: #f5f7fa;
  218. padding-bottom: 40rpx;
  219. }
  220. .header {
  221. display: flex;
  222. flex-direction: row;
  223. justify-content: space-between;
  224. align-items: center;
  225. padding: 30rpx;
  226. background: #fff;
  227. }
  228. .title {
  229. font-size: 36rpx;
  230. font-weight: bold;
  231. color: #333;
  232. }
  233. .btn-create {
  234. background: linear-gradient(135deg, #10B981, #059669);
  235. padding: 14rpx 32rpx;
  236. border-radius: 32rpx;
  237. box-shadow: 0 4rpx 12rpx rgba(16, 185, 129, 0.3);
  238. }
  239. .btn-create:active { opacity: 0.8; }
  240. .btn-create-text {
  241. color: #fff;
  242. font-size: 28rpx;
  243. font-weight: 500;
  244. }
  245. .filter-bar {
  246. background: #fff;
  247. padding: 0 30rpx 20rpx;
  248. border-bottom: 1rpx solid #f0f0f0;
  249. }
  250. .filter-chips {
  251. display: flex;
  252. flex-direction: row;
  253. gap: 12rpx;
  254. overflow-x: auto;
  255. -webkit-overflow-scrolling: touch;
  256. }
  257. .filter-chip {
  258. flex-shrink: 0;
  259. padding: 10rpx 24rpx;
  260. border-radius: 20rpx;
  261. background: #f3f4f6;
  262. border: 1rpx solid #e5e7eb;
  263. }
  264. .filter-chip.active {
  265. background: #d1fae5;
  266. border-color: #10B981;
  267. }
  268. .filter-chip text {
  269. font-size: 26rpx;
  270. color: #666;
  271. }
  272. .filter-chip.active text {
  273. color: #059669;
  274. font-weight: 500;
  275. }
  276. .activity-list {
  277. padding: 20rpx 30rpx;
  278. display: flex;
  279. flex-direction: column;
  280. gap: 20rpx;
  281. }
  282. .activity-card {
  283. background: #fff;
  284. border-radius: 20rpx;
  285. overflow: hidden;
  286. box-shadow: 0 4rpx 16rpx rgba(0,0,0,0.05);
  287. display: flex;
  288. flex-direction: row;
  289. }
  290. .act-cover {
  291. width: 200rpx;
  292. height: 200rpx;
  293. flex-shrink: 0;
  294. }
  295. .cover-img {
  296. width: 100%;
  297. height: 100%;
  298. }
  299. .act-cover.placeholder {
  300. background: linear-gradient(135deg, #10B981 0%, #059669 100%);
  301. display: flex;
  302. align-items: center;
  303. justify-content: center;
  304. }
  305. .cover-placeholder-text {
  306. font-size: 60rpx;
  307. color: #fff;
  308. }
  309. .act-body {
  310. flex: 1;
  311. padding: 20rpx;
  312. display: flex;
  313. flex-direction: column;
  314. }
  315. .act-header {
  316. display: flex;
  317. flex-direction: row;
  318. justify-content: space-between;
  319. align-items: flex-start;
  320. margin-bottom: 8rpx;
  321. }
  322. .act-title {
  323. font-size: 30rpx;
  324. font-weight: bold;
  325. color: #333;
  326. flex: 1;
  327. margin-right: 12rpx;
  328. }
  329. .act-status {
  330. font-size: 22rpx;
  331. padding: 4rpx 14rpx;
  332. border-radius: 14rpx;
  333. flex-shrink: 0;
  334. }
  335. .status-draft { background: #f3f4f6; color: #666; }
  336. .status-published { background: #d1fae5; color: #059669; }
  337. .status-cancelled { background: #fee2e2; color: #dc2626; }
  338. .status-completed { background: #dbeafe; color: #2563eb; }
  339. .act-meta {
  340. display: flex;
  341. flex-direction: row;
  342. gap: 16rpx;
  343. margin-bottom: 6rpx;
  344. }
  345. .meta-item {
  346. font-size: 24rpx;
  347. color: #888;
  348. }
  349. .act-desc {
  350. font-size: 24rpx;
  351. color: #888;
  352. line-height: 1.4;
  353. margin-bottom: 8rpx;
  354. overflow: hidden;
  355. text-overflow: ellipsis;
  356. display: -webkit-box;
  357. -webkit-line-clamp: 2;
  358. -webkit-box-orient: vertical;
  359. }
  360. .act-stats {
  361. display: flex;
  362. flex-direction: row;
  363. gap: 16rpx;
  364. margin-bottom: 12rpx;
  365. }
  366. .stat-item {
  367. font-size: 24rpx;
  368. color: #666;
  369. }
  370. .stat-item.free {
  371. color: #10B981;
  372. font-weight: 500;
  373. }
  374. .act-actions {
  375. display: flex;
  376. flex-direction: row;
  377. flex-wrap: wrap;
  378. gap: 10rpx;
  379. margin-top: auto;
  380. border-top: 1rpx solid #f0f0f0;
  381. padding-top: 12rpx;
  382. }
  383. .act-btn {
  384. padding: 8rpx 20rpx;
  385. border-radius: 20rpx;
  386. font-size: 24rpx;
  387. }
  388. .act-btn:active { opacity: 0.7; }
  389. .act-btn.outline {
  390. background: #f9fafb;
  391. color: #374151;
  392. border: 1rpx solid #e5e7eb;
  393. }
  394. .act-btn.primary {
  395. background: #10B981;
  396. color: #fff;
  397. }
  398. .act-btn.warning {
  399. background: #fee2e2;
  400. color: #dc2626;
  401. }
  402. .act-btn.danger {
  403. background: #fee2e2;
  404. color: #dc2626;
  405. }
  406. .empty {
  407. display: flex;
  408. flex-direction: column;
  409. align-items: center;
  410. padding: 120rpx 40rpx 80rpx;
  411. }
  412. .empty-icon {
  413. font-size: 100rpx;
  414. margin-bottom: 20rpx;
  415. }
  416. .empty-title {
  417. font-size: 32rpx;
  418. color: #333;
  419. font-weight: bold;
  420. margin-bottom: 12rpx;
  421. }
  422. .empty-desc {
  423. font-size: 26rpx;
  424. color: #999;
  425. text-align: center;
  426. line-height: 1.6;
  427. margin-bottom: 40rpx;
  428. }
  429. .empty-btn {
  430. background: linear-gradient(135deg, #10B981, #059669);
  431. padding: 16rpx 48rpx;
  432. border-radius: 40rpx;
  433. box-shadow: 0 4rpx 16rpx rgba(16, 185, 129, 0.3);
  434. }
  435. .empty-btn:active { opacity: 0.8; }
  436. .empty-btn text {
  437. color: #fff;
  438. font-size: 28rpx;
  439. font-weight: 500;
  440. }
  441. .loading {
  442. display: flex;
  443. align-items: center;
  444. justify-content: center;
  445. padding: 80rpx;
  446. }
  447. .loading-text {
  448. font-size: 28rpx;
  449. color: #999;
  450. }
  451. </style>