index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  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="getUrl(info.file)"></image>
  8. </view>
  9. <view class="two">
  10. <view class="two_1 name">{{info.name||'暂无活动名称'}}</view>
  11. <view class="two_1 text_color">
  12. <text class="t-icon t-icon-shizhong"></text>
  13. <span>{{getTime(info.start_time,info.end_time)||'暂无'}}</span>
  14. </view>
  15. <view class="two_1 text_color">
  16. <text class="t-icon t-icon-gonglve"></text>
  17. <span>{{getDict(info.match_type,'type')||'自办'}}</span>
  18. </view>
  19. <view class="two_1 text_color">
  20. <text class="t-icon t-icon-gongsi"></text>
  21. <span>{{info.work||'暂无组织单位'}}</span>
  22. </view>
  23. </view>
  24. <view class="thr">
  25. <view class="thr_cont" v-if="info.rules&&info.rules.rules1">
  26. <view class="thr_1">大赛背景</view>
  27. <view class="thr_2">
  28. <rich-text :nodes="formatRichText(info.rules.rules1)"></rich-text>
  29. </view>
  30. </view>
  31. <view class="thr_cont" v-if="info.rules&&info.rules.rules2">
  32. <view class="thr_1">大赛主题和目标</view>
  33. <view class="thr_2">
  34. <rich-text :nodes="formatRichText(info.rules.rules2)"></rich-text>
  35. </view>
  36. </view>
  37. <view class="thr_cont" v-if="info.rules&&info.rules.rules3">
  38. <view class="thr_1">大赛基本情况介绍</view>
  39. <view class="thr_2">
  40. <rich-text :nodes="formatRichText(info.rules.rules3)"></rich-text>
  41. </view>
  42. </view>
  43. <view class="thr_cont" v-if="info.rules&&info.rules.rules4">
  44. <view class="thr_1">赛题任务</view>
  45. <view class="thr_2">
  46. <rich-text :nodes="formatRichText(info.rules.rules4)"></rich-text>
  47. </view>
  48. </view>
  49. <view class="thr_cont" v-if="info.rules&&info.rules.rules5">
  50. <view class="thr_1">赛程安排</view>
  51. <view class="thr_2">
  52. <rich-text :nodes="formatRichText(info.rules.rules5)"></rich-text>
  53. </view>
  54. </view>
  55. <view class="thr_cont" v-if="info.rules&&info.rules.rules6">
  56. <view class="thr_1">赛制阶段</view>
  57. <view class="thr_2">
  58. <rich-text :nodes="formatRichText(info.rules.rules6)"></rich-text>
  59. </view>
  60. </view>
  61. <view class="thr_cont" v-if="info.rules&&info.rules.rules7">
  62. <view class="thr_1">参赛资格</view>
  63. <view class="thr_2">
  64. <rich-text :nodes="formatRichText(info.rules.rules7)"></rich-text>
  65. </view>
  66. </view>
  67. <view class="thr_cont" v-if="info.rules&&info.rules.rules8">
  68. <view class="thr_1">参赛报名</view>
  69. <view class="thr_2">
  70. <rich-text :nodes="formatRichText(info.rules.rules8)"></rich-text>
  71. </view>
  72. </view>
  73. <view class="thr_cont" v-if="info.rules&&info.rules.rules9">
  74. <view class="thr_1">奖项设置与奖励办法</view>
  75. <view class="thr_2">
  76. <rich-text :nodes="formatRichText(info.rules.rules9)"></rich-text>
  77. </view>
  78. </view>
  79. <view class="thr_cont" v-if="info.rules&&info.rules.rules10">
  80. <view class="thr_1">组织单位</view>
  81. <view class="thr_2">
  82. <rich-text :nodes="formatRichText(info.rules.rules10)"></rich-text>
  83. </view>
  84. </view>
  85. <view class="thr_cont" v-if="info.rules&&info.rules.rules11">
  86. <view class="thr_1">赛事联络</view>
  87. <view class="thr_2">
  88. <rich-text :nodes="formatRichText(info.rules.rules11)"></rich-text>
  89. </view>
  90. </view>
  91. <view class="thr_cont" v-if="info.rules&&info.rules.rules12">
  92. <view class="thr_1">赛事交流</view>
  93. <view class="thr_2">
  94. <rich-text :nodes="formatRichText(info.rules.rules12)"></rich-text>
  95. </view>
  96. </view>
  97. </view>
  98. <view class="thr">
  99. <view class="thr_cont" v-if="info.brief">
  100. <view class="thr_1">常见问题</view>
  101. <view class="thr_2">
  102. <rich-text :nodes="formatRichText(info.brief)"></rich-text>
  103. </view>
  104. </view>
  105. </view>
  106. </view>
  107. </scroll-view>
  108. </view>
  109. <view class="foot">
  110. <view class="foot_text foot_1" @tap="toFriend()">分享给好友</view>
  111. <view class="foot_text foot_2" @tap="toSign()">报名活动</view>
  112. </view>
  113. <uni-popup ref="share" type="share" safeArea backgroundColor="#fff">
  114. <view class="popup_cont">
  115. <view class="popup_title">
  116. <text>分享到</text>
  117. </view>
  118. <view class="popup_share">
  119. <view class="share_1">
  120. <button type="primary" plain="true" open-type="share" @click="toShare">
  121. <text class="t-icon t-icon-weixin"></text>
  122. <text>分享给好友</text>
  123. </button>
  124. </view>
  125. <view class="share_1">
  126. <button type="primary" plain="true" open-type="share" @click="toPoster">
  127. <text class="t-icon t-icon-iconfontzhizuobiaozhunbduan36"></text>
  128. <text>生成活动海报</text>
  129. </button>
  130. </view>
  131. </view>
  132. </view>
  133. </uni-popup>
  134. </view>
  135. </template>
  136. <script>
  137. export default {
  138. data() {
  139. return {
  140. id: '',
  141. user: {},
  142. config: {},
  143. info: {},
  144. // 字典表
  145. statusList: [],
  146. typeList: []
  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. res = await that.$api(`/dictData`, 'GET', {
  203. code: 'activeType',
  204. is_use: '0',
  205. })
  206. if (res.errcode == '0') that.$set(that, `typeList`, res.data)
  207. },
  208. // 查询
  209. async search() {
  210. const that = this;
  211. if (that.id) {
  212. let res;
  213. res = await that.$api(`/match/${that.id}`, 'GET', {})
  214. if (res.errcode == '0') {
  215. that.$set(that, `info`, res.data)
  216. } else {
  217. uni.showToast({
  218. title: res.errmsg,
  219. });
  220. }
  221. }
  222. },
  223. // 处理时间
  224. getTime(start_time, end_time) {
  225. if (start_time && end_time) {
  226. const start = new Date(start_time);
  227. const end = new Date(end_time);
  228. const weekdays = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
  229. const day = start.getDate();
  230. const weekday = weekdays[start.getDay()];
  231. const month = start.getMonth();
  232. const start_hours = start.getHours();
  233. const start_minutes = start.getMinutes();
  234. const end_hours = end.getHours();
  235. const end_minutes = end.getMinutes();
  236. 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')} `;
  237. }
  238. },
  239. // 处理字典表
  240. getDict(item, model) {
  241. const that = this;
  242. let res
  243. if (model == 'type') res = that.typeList.find(i => i.value == item)
  244. if (res) return res.label
  245. else return '暂无'
  246. },
  247. // 图片处理
  248. getUrl(e) {
  249. const that = this;
  250. if (e && e.length > 0) return that.$config.serverFile + e[0].url
  251. else return '/static/match.png'
  252. },
  253. // 处理富文本
  254. formatRichText(html) {
  255. if (html) {
  256. html = html.replace(/<table[^>]*>/gi, match => {
  257. // 如果已有 style 属性,替换为新的样式;如果没有,添加新的 style 属性
  258. return match.replace(/style="[^"]+"/gi,
  259. `style="border-collapse: collapse; width: 100%;text-align: center;"`)
  260. .replace(/<table/gi,
  261. `<table style="border-collapse: collapse; width: 100%;text-align: center;"`);
  262. });
  263. html = html.replace(/<th[^>]*>/gi, match => {
  264. // 如果已有 style 属性,替换为新的样式;如果没有,添加新的 style 属性
  265. return match.replace(/style="[^"]+"/gi,
  266. `style="border: 1px solid #ddd; padding: 8px; background-color: #f2f2f2;text-align: center;"`
  267. )
  268. .replace(/<table/gi,
  269. `<table style="border: 1px solid #ddd; padding: 8px; background-color: #f2f2f2;text-align: center;"`
  270. );
  271. });
  272. html = html.replace(/<td[^>]*>/gi, match => {
  273. // 如果已有 style 属性,替换为新的样式;如果没有,添加新的 style 属性
  274. return match.replace(/style="[^"]+"/gi,
  275. `style="border: 1px solid #ddd; padding: 8px;text-align: center;"`)
  276. .replace(/<table/gi,
  277. `<table style="border: 1px solid #ddd; padding: 8px;text-align: center;"`);
  278. });
  279. // 富文本内容格式化
  280. return html && html.replace(/<img[^>]*>/gi, function(match, capture) {
  281. // 查找所有的 img 元素
  282. return match.replace(/style=".*"/gi, '').replace(/style='.*'/gi,
  283. '')
  284. // 删除找到的所有 img 元素中的 style 属性
  285. }).replace(/\<img/gi, '<img style="width:100%;"') // 对 img 元素增加 style 属性,并设置宽度为 100%
  286. }
  287. },
  288. // 分享给好友
  289. toFriend() {
  290. const that = this;
  291. that.$refs.share.open()
  292. },
  293. // 活动报名
  294. toSign() {
  295. const that = this;
  296. if (that.info.match_status == '0') {
  297. uni.showToast({
  298. title: '活动未开始 暂不支持报名!',
  299. icon: 'none'
  300. })
  301. } else if (that.info.match_status == '1') {
  302. if (that.user && that.user.id) {
  303. uni.navigateTo({
  304. url: `/pagesHome/match/sign?id=${that.id}`
  305. })
  306. } else {
  307. uni.navigateTo({
  308. url: `/pagesHome/login/index`
  309. })
  310. }
  311. } else if (that.info.match_status == '2') {
  312. uni.showToast({
  313. title: '活动进行中 暂不支持报名!',
  314. icon: 'none'
  315. })
  316. } else {
  317. uni.showToast({
  318. title: '比赛已结束!',
  319. icon: 'none'
  320. })
  321. }
  322. },
  323. // 分享给好友
  324. toShare() {
  325. const that = this;
  326. let info = that.info;
  327. let imageUrl = that.config?.logoUrl[0]?.url || info.file[0]?.url;
  328. that.$config.share = {
  329. title: info.name,
  330. path: `/pagesHome/match/index?id=${that.id}`,
  331. imageUrl: imageUrl
  332. }
  333. },
  334. // 生成海报
  335. toPoster() {
  336. console.log('生成海报');
  337. },
  338. }
  339. }
  340. </script>
  341. <style lang="scss" scoped>
  342. .main {
  343. .info {
  344. position: relative;
  345. flex-grow: 1;
  346. background-color: var(--f9Color);
  347. .one {
  348. .image {
  349. width: 100%;
  350. height: 50vw;
  351. }
  352. }
  353. .two {
  354. padding: 0 2vw;
  355. background-color: var(--mainColor);
  356. .two_1 {
  357. display: flex;
  358. align-items: center;
  359. padding: 3vw 0;
  360. border-bottom: 1px solid var(--f5Color);
  361. font-size: var(--font14Size);
  362. span {
  363. margin: 0 0 0 1vw;
  364. }
  365. .t-icon {
  366. width: var(--font15Size) !important;
  367. height: var(--font15Size) !important;
  368. }
  369. }
  370. .name {
  371. font-weight: bold;
  372. font-size: var(--font16Size);
  373. }
  374. .text_color {
  375. color: var(--f69Color);
  376. }
  377. }
  378. .thr {
  379. margin: 3vw 0 0 0;
  380. background-color: var(--mainColor);
  381. .thr_cont {
  382. margin: 2vw 0 0 0;
  383. .thr_1 {
  384. text-indent: 10px;
  385. border-left: 3px solid var(--f3CColor);
  386. font-weight: bold;
  387. font-size: var(--font16Size);
  388. }
  389. .thr_2 {
  390. padding: 2vw;
  391. }
  392. }
  393. }
  394. }
  395. .foot {
  396. width: 100%;
  397. height: 8vh;
  398. overflow: hidden;
  399. display: flex;
  400. align-items: center;
  401. .foot_text {
  402. display: flex;
  403. justify-content: center;
  404. align-items: center;
  405. width: 50%;
  406. height: 100%;
  407. color: var(--mainColor);
  408. }
  409. .foot_1 {
  410. background: linear-gradient(90deg, #FFCD1E, #FF8A18);
  411. }
  412. .foot_2 {
  413. background: linear-gradient(90deg, #1E83FF, #1071e6);
  414. }
  415. }
  416. .popup_cont {
  417. .popup_title {
  418. display: flex;
  419. flex-direction: row;
  420. align-items: center;
  421. justify-content: center;
  422. height: 40px;
  423. font-size: var(--font14Size);
  424. color: #666;
  425. }
  426. .popup_share {
  427. display: flex;
  428. align-items: center;
  429. padding: 2vw 0;
  430. .share_1 {
  431. width: 50%;
  432. button {
  433. background: none;
  434. border: none;
  435. display: flex;
  436. flex-direction: column;
  437. justify-content: center;
  438. align-items: center;
  439. .t-icon {
  440. width: 8vw;
  441. height: 8vw;
  442. }
  443. text {
  444. margin-top: 10px;
  445. font-size: var(--font14Size);
  446. color: #3B4144;
  447. }
  448. }
  449. }
  450. }
  451. }
  452. }
  453. .scroll-view {
  454. position: absolute;
  455. top: 0;
  456. left: 0;
  457. right: 0;
  458. bottom: 0;
  459. .list-scroll-view {
  460. display: flex;
  461. flex-direction: column;
  462. }
  463. }
  464. </style>