index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  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-zuobiao"></text>
  17. <span>{{info.address||'在线活动'}}</span>
  18. </view>
  19. <view class="two_1 text_color">
  20. <text class="t-icon t-icon-dianzan"></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. }
  147. },
  148. onLoad: async function(e) {
  149. const that = this;
  150. that.$set(that, `id`, e && e.id || '');
  151. that.searchConfig();
  152. await that.searchOther();
  153. await that.search();
  154. },
  155. onShow: async function() {
  156. const that = this;
  157. that.searchToken();
  158. },
  159. onUnload: function() {
  160. // 页面卸载,重新部署分享内容
  161. const that = this;
  162. if (that.config) {
  163. // 赋值默认值
  164. that.$config.share = {
  165. title: that.config.zhTitle,
  166. path: '/pages/index/index',
  167. imageUrl: that.config?.logoUrl[0]?.url
  168. }
  169. }
  170. },
  171. methods: {
  172. // 用户信息
  173. searchToken() {
  174. const that = this;
  175. try {
  176. const res = uni.getStorageSync('token');
  177. if (res) {
  178. const user = that.$jwt(res);
  179. that.$set(that, `user`, user);
  180. }
  181. } catch (e) {}
  182. },
  183. searchConfig() {
  184. const that = this;
  185. try {
  186. const res = uni.getStorageSync('config');
  187. if (res) that.$set(that, `config`, res);
  188. } catch (e) {}
  189. },
  190. // 查询其他信息
  191. async searchOther() {
  192. const that = this;
  193. let res;
  194. // 查询类型
  195. res = await that.$api(`/dictData`, 'GET', {
  196. code: 'matchStatus',
  197. is_use: '0',
  198. })
  199. if (res.errcode == '0') that.$set(that, `statusList`, res.data);
  200. },
  201. // 查询
  202. async search() {
  203. const that = this;
  204. if (that.id) {
  205. let res;
  206. res = await that.$api(`/match/${that.id}`, 'GET', {})
  207. if (res.errcode == '0') {
  208. that.$set(that, `info`, res.data)
  209. } else {
  210. uni.showToast({
  211. title: res.errmsg,
  212. });
  213. }
  214. }
  215. },
  216. // 处理时间
  217. getTime(start_time, end_time) {
  218. if (start_time && end_time) {
  219. const start = new Date(start_time);
  220. const end = new Date(end_time);
  221. const weekdays = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
  222. const day = start.getDate();
  223. const weekday = weekdays[start.getDay()];
  224. const month = start.getMonth();
  225. const start_hours = start.getHours();
  226. const start_minutes = start.getMinutes();
  227. const end_hours = end.getHours();
  228. const end_minutes = end.getMinutes();
  229. 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')} `;
  230. }
  231. },
  232. // 图片处理
  233. getUrl(e) {
  234. const that = this;
  235. if (e && e.length > 0) return that.$config.serverFile + e[0].url
  236. else return '/static/match.png'
  237. },
  238. // 处理富文本
  239. formatRichText(html) {
  240. if (html) {
  241. html = html.replace(/<table[^>]*>/gi, match => {
  242. // 如果已有 style 属性,替换为新的样式;如果没有,添加新的 style 属性
  243. return match.replace(/style="[^"]+"/gi,
  244. `style="border-collapse: collapse; width: 100%;text-align: center;"`)
  245. .replace(/<table/gi,
  246. `<table style="border-collapse: collapse; width: 100%;text-align: center;"`);
  247. });
  248. html = html.replace(/<th[^>]*>/gi, match => {
  249. // 如果已有 style 属性,替换为新的样式;如果没有,添加新的 style 属性
  250. return match.replace(/style="[^"]+"/gi,
  251. `style="border: 1px solid #ddd; padding: 8px; background-color: #f2f2f2;text-align: center;"`
  252. )
  253. .replace(/<table/gi,
  254. `<table style="border: 1px solid #ddd; padding: 8px; background-color: #f2f2f2;text-align: center;"`
  255. );
  256. });
  257. html = html.replace(/<td[^>]*>/gi, match => {
  258. // 如果已有 style 属性,替换为新的样式;如果没有,添加新的 style 属性
  259. return match.replace(/style="[^"]+"/gi,
  260. `style="border: 1px solid #ddd; padding: 8px;text-align: center;"`)
  261. .replace(/<table/gi,
  262. `<table style="border: 1px solid #ddd; padding: 8px;text-align: center;"`);
  263. });
  264. // 富文本内容格式化
  265. return html && html.replace(/<img[^>]*>/gi, function(match, capture) {
  266. // 查找所有的 img 元素
  267. return match.replace(/style=".*"/gi, '').replace(/style='.*'/gi,
  268. '')
  269. // 删除找到的所有 img 元素中的 style 属性
  270. }).replace(/\<img/gi, '<img style="width:100%;"') // 对 img 元素增加 style 属性,并设置宽度为 100%
  271. }
  272. },
  273. // 分享给好友
  274. toFriend() {
  275. const that = this;
  276. that.$refs.share.open()
  277. },
  278. // 活动报名
  279. toSign() {
  280. const that = this;
  281. if (that.info.match_status == '0') {
  282. uni.showToast({
  283. title: '活动未开始 暂不支持报名!',
  284. icon: 'none'
  285. })
  286. } else if (that.info.match_status == '1') {
  287. if (that.user && that.user.id) {
  288. uni.navigateTo({
  289. url: `/pagesHome/match/sign?id=${that.id}`
  290. })
  291. } else {
  292. uni.navigateTo({
  293. url: `/pagesHome/login/index`
  294. })
  295. }
  296. } else {
  297. uni.showToast({
  298. title: '比赛已结束!',
  299. icon: 'none'
  300. })
  301. }
  302. },
  303. // 分享给好友
  304. toShare() {
  305. const that = this;
  306. let info = that.info;
  307. let imageUrl = that.config?.logoUrl[0]?.url || info.file[0]?.url;
  308. that.$config.share = {
  309. title: info.name,
  310. path: `/pagesHome/match/index?id=${that.id}`,
  311. imageUrl: imageUrl
  312. }
  313. },
  314. // 生成海报
  315. toPoster() {
  316. console.log('生成海报');
  317. },
  318. }
  319. }
  320. </script>
  321. <style lang="scss" scoped>
  322. .main {
  323. .info {
  324. position: relative;
  325. flex-grow: 1;
  326. background-color: var(--f9Color);
  327. .one {
  328. .image {
  329. width: 100%;
  330. height: 50vw;
  331. }
  332. }
  333. .two {
  334. padding: 0 2vw;
  335. background-color: var(--mainColor);
  336. .two_1 {
  337. display: flex;
  338. align-items: center;
  339. padding: 3vw 0;
  340. border-bottom: 1px solid var(--f5Color);
  341. font-size: var(--font14Size);
  342. span {
  343. margin: 0 0 0 1vw;
  344. }
  345. .t-icon {
  346. width: var(--font15Size) !important;
  347. height: var(--font15Size) !important;
  348. }
  349. }
  350. .name {
  351. font-weight: bold;
  352. font-size: var(--font16Size);
  353. }
  354. .text_color {
  355. color: var(--f69Color);
  356. }
  357. }
  358. .thr {
  359. margin: 3vw 0 0 0;
  360. background-color: var(--mainColor);
  361. .thr_cont {
  362. margin: 2vw 0 0 0;
  363. .thr_1 {
  364. text-indent: 10px;
  365. border-left: 3px solid var(--f3CColor);
  366. font-weight: bold;
  367. font-size: var(--font16Size);
  368. }
  369. .thr_2 {
  370. padding: 2vw;
  371. }
  372. }
  373. }
  374. }
  375. .foot {
  376. width: 100%;
  377. height: 8vh;
  378. overflow: hidden;
  379. display: flex;
  380. align-items: center;
  381. .foot_text {
  382. display: flex;
  383. justify-content: center;
  384. align-items: center;
  385. width: 50%;
  386. height: 100%;
  387. color: var(--mainColor);
  388. }
  389. .foot_1 {
  390. background: linear-gradient(90deg, #FFCD1E, #FF8A18);
  391. }
  392. .foot_2 {
  393. background: linear-gradient(90deg, #1E83FF, #1071e6);
  394. }
  395. }
  396. .popup_cont {
  397. .popup_title {
  398. display: flex;
  399. flex-direction: row;
  400. align-items: center;
  401. justify-content: center;
  402. height: 40px;
  403. font-size: var(--font14Size);
  404. color: #666;
  405. }
  406. .popup_share {
  407. display: flex;
  408. align-items: center;
  409. padding: 2vw 0;
  410. .share_1 {
  411. width: 50%;
  412. button {
  413. background: none;
  414. border: none;
  415. display: flex;
  416. flex-direction: column;
  417. justify-content: center;
  418. align-items: center;
  419. .t-icon {
  420. width: 8vw;
  421. height: 8vw;
  422. }
  423. text {
  424. margin-top: 10px;
  425. font-size: var(--font14Size);
  426. color: #3B4144;
  427. }
  428. }
  429. }
  430. }
  431. }
  432. }
  433. .scroll-view {
  434. position: absolute;
  435. top: 0;
  436. left: 0;
  437. right: 0;
  438. bottom: 0;
  439. .list-scroll-view {
  440. display: flex;
  441. flex-direction: column;
  442. }
  443. }
  444. </style>