index.vue 12 KB

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