index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. <template>
  2. <view class="container main">
  3. <view class="info">
  4. <scroll-view scroll-y="true" class="scroll-view">
  5. <view class="list-scroll-view">
  6. <view class="one">
  7. <image class="image" :src="info.file&&info.file.length>0?info.file[0].url:'/static/match.png'">
  8. </image>
  9. </view>
  10. <view class="two">
  11. <view class="two_1 name">{{info.name||'暂无活动名称'}}</view>
  12. <view class="two_1 text_color">
  13. <text class="t-icon t-icon-shizhong"></text>
  14. <span>{{getTime(info.start_time,info.end_time)||'暂无'}}</span>
  15. </view>
  16. <view class="two_1 text_color">
  17. <text class="t-icon t-icon-zuobiao"></text>
  18. <span>{{info.address||'在线活动'}}</span>
  19. </view>
  20. <view class="two_1 text_color">
  21. <text class="t-icon t-icon-dianzan"></text>
  22. <span>{{info.work||'暂无组织单位'}}</span>
  23. </view>
  24. </view>
  25. <view class="thr">
  26. <view class="thr_cont" v-if="info.rules&&info.rules.rules1">
  27. <view class="thr_1">大赛背景</view>
  28. <view class="thr_2">
  29. <rich-text :nodes="formatRichText(info.rules.rules1)"></rich-text>
  30. </view>
  31. </view>
  32. <view class="thr_cont" v-if="info.rules&&info.rules.rules2">
  33. <view class="thr_1">大赛主题和目标</view>
  34. <view class="thr_2">
  35. <rich-text :nodes="formatRichText(info.rules.rules2)"></rich-text>
  36. </view>
  37. </view>
  38. <view class="thr_cont" v-if="info.rules&&info.rules.rules3">
  39. <view class="thr_1">大赛基本情况介绍</view>
  40. <view class="thr_2">
  41. <rich-text :nodes="formatRichText(info.rules.rules3)"></rich-text>
  42. </view>
  43. </view>
  44. <view class="thr_cont" v-if="info.rules&&info.rules.rules4">
  45. <view class="thr_1">赛题任务</view>
  46. <view class="thr_2">
  47. <rich-text :nodes="formatRichText(info.rules.rules4)"></rich-text>
  48. </view>
  49. </view>
  50. <view class="thr_cont" v-if="info.rules&&info.rules.rules5">
  51. <view class="thr_1">赛程安排</view>
  52. <view class="thr_2">
  53. <rich-text :nodes="formatRichText(info.rules.rules5)"></rich-text>
  54. </view>
  55. </view>
  56. <view class="thr_cont" v-if="info.rules&&info.rules.rules6">
  57. <view class="thr_1">赛制阶段</view>
  58. <view class="thr_2">
  59. <rich-text :nodes="formatRichText(info.rules.rules6)"></rich-text>
  60. </view>
  61. </view>
  62. <view class="thr_cont" v-if="info.rules&&info.rules.rules7">
  63. <view class="thr_1">参赛资格</view>
  64. <view class="thr_2">
  65. <rich-text :nodes="formatRichText(info.rules.rules7)"></rich-text>
  66. </view>
  67. </view>
  68. <view class="thr_cont" v-if="info.rules&&info.rules.rules8">
  69. <view class="thr_1">参赛报名</view>
  70. <view class="thr_2">
  71. <rich-text :nodes="formatRichText(info.rules.rules8)"></rich-text>
  72. </view>
  73. </view>
  74. <view class="thr_cont" v-if="info.rules&&info.rules.rules9">
  75. <view class="thr_1">奖项设置与奖励办法</view>
  76. <view class="thr_2">
  77. <rich-text :nodes="formatRichText(info.rules.rules9)"></rich-text>
  78. </view>
  79. </view>
  80. <view class="thr_cont" v-if="info.rules&&info.rules.rules10">
  81. <view class="thr_1">组织单位</view>
  82. <view class="thr_2">
  83. <rich-text :nodes="formatRichText(info.rules.rules10)"></rich-text>
  84. </view>
  85. </view>
  86. <view class="thr_cont" v-if="info.rules&&info.rules.rules11">
  87. <view class="thr_1">赛事联络</view>
  88. <view class="thr_2">
  89. <rich-text :nodes="formatRichText(info.rules.rules11)"></rich-text>
  90. </view>
  91. </view>
  92. <view class="thr_cont" v-if="info.rules&&info.rules.rules12">
  93. <view class="thr_1">赛事交流</view>
  94. <view class="thr_2">
  95. <rich-text :nodes="formatRichText(info.rules.rules12)"></rich-text>
  96. </view>
  97. </view>
  98. </view>
  99. <view class="thr">
  100. <view class="thr_cont" v-if="info.brief">
  101. <view class="thr_1">常见问题</view>
  102. <view class="thr_2">
  103. <rich-text :nodes="formatRichText(info.brief)"></rich-text>
  104. </view>
  105. </view>
  106. </view>
  107. </view>
  108. </scroll-view>
  109. </view>
  110. <view class="foot">
  111. <view class="foot_text foot_1" @tap="toFriend()">分享给好友</view>
  112. <view class="foot_text foot_2" @tap="toSign()">报名活动</view>
  113. </view>
  114. <uni-popup ref="share" type="share" safeArea backgroundColor="#fff">
  115. <view class="popup_cont">
  116. <view class="popup_title">
  117. <text>分享到</text>
  118. </view>
  119. <view class="popup_share">
  120. <view class="share_1">
  121. <button type="primary" plain="true" open-type="share" @click="toShare">
  122. <text class="t-icon t-icon-weixin"></text>
  123. <text>分享给好友</text>
  124. </button>
  125. </view>
  126. <view class="share_1">
  127. <button type="primary" plain="true" open-type="share" @click="toPoster">
  128. <text class="t-icon t-icon-iconfontzhizuobiaozhunbduan36"></text>
  129. <text>生成活动海报</text>
  130. </button>
  131. </view>
  132. </view>
  133. </view>
  134. </uni-popup>
  135. </view>
  136. </template>
  137. <script>
  138. export default {
  139. data() {
  140. return {
  141. id: '',
  142. user: {},
  143. config: {},
  144. info: {},
  145. // 字典表
  146. statusList: []
  147. }
  148. },
  149. onLoad: async function(e) {
  150. const that = this;
  151. that.$set(that, `id`, e && e.id || '');
  152. that.searchConfig();
  153. await that.searchOther();
  154. await that.search();
  155. },
  156. onShow: async function() {
  157. const that = this;
  158. that.searchToken();
  159. },
  160. onUnload: function() {
  161. // 页面卸载,重新部署分享内容
  162. const that = this;
  163. if (that.config) {
  164. // 赋值默认值
  165. that.$config.share = {
  166. title: that.config.zhTitle,
  167. path: '/pages/index/index',
  168. imageUrl: that.config?.logoUrl[0]?.url
  169. }
  170. }
  171. },
  172. methods: {
  173. // 用户信息
  174. searchToken() {
  175. const that = this;
  176. try {
  177. const res = uni.getStorageSync('token');
  178. if (res) {
  179. const user = that.$jwt(res);
  180. that.$set(that, `user`, user);
  181. }
  182. } catch (e) {}
  183. },
  184. searchConfig() {
  185. const that = this;
  186. try {
  187. const res = uni.getStorageSync('config');
  188. if (res) that.$set(that, `config`, res);
  189. } catch (e) {}
  190. },
  191. // 查询其他信息
  192. async searchOther() {
  193. const that = this;
  194. let res;
  195. // 查询类型
  196. res = await that.$api(`/dictData`, 'GET', {
  197. code: 'matchStatus',
  198. is_use: '0',
  199. })
  200. if (res.errcode == '0') that.$set(that, `statusList`, res.data);
  201. },
  202. // 查询
  203. async search() {
  204. const that = this;
  205. if (that.id) {
  206. let res;
  207. res = await that.$api(`/match/${that.id}`, 'GET', {})
  208. if (res.errcode == '0') {
  209. that.$set(that, `info`, res.data)
  210. } else {
  211. uni.showToast({
  212. title: res.errmsg,
  213. });
  214. }
  215. }
  216. },
  217. // 处理时间
  218. getTime(start_time, end_time) {
  219. if (start_time && end_time) {
  220. const start = new Date(start_time);
  221. const end = new Date(end_time);
  222. const weekdays = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
  223. const day = start.getDate();
  224. const weekday = weekdays[start.getDay()];
  225. const month = start.getMonth();
  226. const start_hours = start.getHours();
  227. const start_minutes = start.getMinutes();
  228. const end_hours = end.getHours();
  229. const end_minutes = end.getMinutes();
  230. return `${month}/${day < 10 ? '0' + day : day} ${weekday} ${start_hours.toString().padStart(2, '0')}:${start_minutes.toString().padStart(2, '0')} - ${end_hours.toString().padStart(2, '0')}:${end_minutes.toString().padStart(2, '0')} `;
  231. }
  232. },
  233. // 处理富文本
  234. formatRichText(html) {
  235. if (html) {
  236. // 富文本内容格式化
  237. return html && html.replace(/<img[^>]*>/gi, function(match, capture) {
  238. // 查找所有的 img 元素
  239. return match.replace(/style=".*"/gi, '').replace(/style='.*'/gi,
  240. '')
  241. // 删除找到的所有 img 元素中的 style 属性
  242. }).replace(/\<img/gi, '<img style="width:100%;"') // 对 img 元素增加 style 属性,并设置宽度为 100%
  243. }
  244. },
  245. // 分享给好友
  246. toFriend() {
  247. const that = this;
  248. that.$refs.share.open()
  249. },
  250. // 活动报名
  251. toSign() {
  252. const that = this;
  253. if (that.info.match_status == '0') {
  254. uni.showToast({
  255. title: '活动未开始 暂不支持报名!',
  256. icon: 'none'
  257. })
  258. } else if (that.info.match_status == '1') {
  259. if (that.user && that.user.id) {
  260. uni.navigateTo({
  261. url: `/pagesHome/match/sign?id=${that.id}`
  262. })
  263. } else {
  264. uni.navigateTo({
  265. url: `/pagesHome/login/index`
  266. })
  267. }
  268. } else {
  269. uni.showToast({
  270. title: '比赛已结束!',
  271. icon: 'none'
  272. })
  273. }
  274. },
  275. // 分享给好友
  276. toShare() {
  277. const that = this;
  278. let info = that.info;
  279. let imageUrl = that.config?.logoUrl[0]?.url || info.file[0]?.url;
  280. that.$config.share = {
  281. title: info.name,
  282. path: `/pagesHome/match/index?id=${that.id}`,
  283. imageUrl: imageUrl
  284. }
  285. },
  286. // 生成海报
  287. toPoster() {
  288. console.log('生成海报');
  289. },
  290. }
  291. }
  292. </script>
  293. <style lang="scss" scoped>
  294. .main {
  295. .info {
  296. position: relative;
  297. flex-grow: 1;
  298. background-color: var(--f9Color);
  299. .one {
  300. .image {
  301. width: 100%;
  302. height: 50vw;
  303. }
  304. }
  305. .two {
  306. padding: 0 2vw;
  307. background-color: var(--mainColor);
  308. .two_1 {
  309. display: flex;
  310. align-items: center;
  311. padding: 3vw 0;
  312. border-bottom: 1px solid var(--f5Color);
  313. font-size: var(--font14Size);
  314. span {
  315. margin: 0 0 0 1vw;
  316. }
  317. .t-icon {
  318. width: var(--font15Size) !important;
  319. height: var(--font15Size) !important;
  320. }
  321. }
  322. .name {
  323. font-weight: bold;
  324. font-size: var(--font16Size);
  325. }
  326. .text_color {
  327. color: var(--f69Color);
  328. }
  329. }
  330. .thr {
  331. margin: 3vw 0 0 0;
  332. background-color: var(--mainColor);
  333. .thr_cont {
  334. margin: 2vw 0 0 0;
  335. .thr_1 {
  336. text-indent: 10px;
  337. border-left: 3px solid var(--f3CColor);
  338. font-weight: bold;
  339. font-size: var(--font16Size);
  340. }
  341. .thr_2 {
  342. padding: 2vw;
  343. }
  344. }
  345. }
  346. }
  347. .foot {
  348. width: 100%;
  349. height: 8vh;
  350. overflow: hidden;
  351. display: flex;
  352. align-items: center;
  353. .foot_text {
  354. display: flex;
  355. justify-content: center;
  356. align-items: center;
  357. width: 50%;
  358. height: 100%;
  359. color: var(--mainColor);
  360. }
  361. .foot_1 {
  362. background: linear-gradient(90deg, #FFCD1E, #FF8A18);
  363. }
  364. .foot_2 {
  365. background: linear-gradient(90deg, #1E83FF, #1071e6);
  366. }
  367. }
  368. .popup_cont {
  369. .popup_title {
  370. display: flex;
  371. flex-direction: row;
  372. align-items: center;
  373. justify-content: center;
  374. height: 40px;
  375. font-size: var(--font14Size);
  376. color: #666;
  377. }
  378. .popup_share {
  379. display: flex;
  380. align-items: center;
  381. padding: 2vw 0;
  382. .share_1 {
  383. width: 50%;
  384. button {
  385. background: none;
  386. border: none;
  387. display: flex;
  388. flex-direction: column;
  389. justify-content: center;
  390. align-items: center;
  391. .t-icon {
  392. width: 8vw;
  393. height: 8vw;
  394. }
  395. text {
  396. margin-top: 10px;
  397. font-size: var(--font14Size);
  398. color: #3B4144;
  399. }
  400. }
  401. }
  402. }
  403. }
  404. }
  405. .scroll-view {
  406. position: absolute;
  407. top: 0;
  408. left: 0;
  409. right: 0;
  410. bottom: 0;
  411. .list-scroll-view {
  412. display: flex;
  413. flex-direction: column;
  414. }
  415. }
  416. </style>