index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  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. uni.setNavigationBarTitle({
  211. title: res.data.name
  212. });
  213. } else {
  214. uni.showToast({
  215. title: res.errmsg,
  216. });
  217. }
  218. }
  219. },
  220. // 处理时间
  221. getTime(start_time, end_time) {
  222. if (start_time && end_time) {
  223. const start = new Date(start_time);
  224. const end = new Date(end_time);
  225. const weekdays = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
  226. const day = start.getDate();
  227. const weekday = weekdays[start.getDay()];
  228. const month = start.getMonth();
  229. const start_hours = start.getHours();
  230. const start_minutes = start.getMinutes();
  231. const end_hours = end.getHours();
  232. const end_minutes = end.getMinutes();
  233. 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')} `;
  234. }
  235. },
  236. // 处理富文本
  237. formatRichText(html) {
  238. if (html) {
  239. // 富文本内容格式化
  240. return html && html.replace(/<img[^>]*>/gi, function(match, capture) {
  241. // 查找所有的 img 元素
  242. return match.replace(/style=".*"/gi, '').replace(/style='.*'/gi,
  243. '')
  244. // 删除找到的所有 img 元素中的 style 属性
  245. }).replace(/\<img/gi, '<img style="width:100%;"') // 对 img 元素增加 style 属性,并设置宽度为 100%
  246. }
  247. },
  248. // 分享给好友
  249. toFriend() {
  250. const that = this;
  251. that.$refs.share.open()
  252. },
  253. // 活动报名
  254. toSign() {
  255. const that = this;
  256. if (that.info.match_status == '0') {
  257. uni.showToast({
  258. title: '活动未开始 暂不支持报名!',
  259. icon: 'none'
  260. })
  261. } else if (that.info.match_status == '1') {
  262. if (that.user && that.user.id) {
  263. uni.navigateTo({
  264. url: `/pagesHome/match/sign?id=${that.id}`
  265. })
  266. } else {
  267. uni.navigateTo({
  268. url: `/pagesHome/login/index`
  269. })
  270. }
  271. } else {
  272. uni.showToast({
  273. title: '比赛已结束!',
  274. icon: 'none'
  275. })
  276. }
  277. },
  278. // 分享给好友
  279. toShare() {
  280. const that = this;
  281. let info = that.info;
  282. let imageUrl = that.config?.logoUrl[0]?.url || info.file[0]?.url;
  283. that.$config.share = {
  284. title: info.name,
  285. path: `/pagesHome/match/index?id=${that.id}`,
  286. imageUrl: imageUrl
  287. }
  288. },
  289. // 生成海报
  290. toPoster() {
  291. console.log('生成海报');
  292. },
  293. }
  294. }
  295. </script>
  296. <style lang="scss" scoped>
  297. .main {
  298. .info {
  299. position: relative;
  300. flex-grow: 1;
  301. background-color: var(--f9Color);
  302. .one {
  303. .image {
  304. width: 100%;
  305. height: 50vw;
  306. }
  307. }
  308. .two {
  309. padding: 0 2vw;
  310. background-color: var(--mainColor);
  311. .two_1 {
  312. display: flex;
  313. align-items: center;
  314. padding: 3vw 0;
  315. border-bottom: 1px solid var(--f5Color);
  316. font-size: var(--font14Size);
  317. span {
  318. margin: 0 0 0 1vw;
  319. }
  320. .t-icon {
  321. width: var(--font15Size) !important;
  322. height: var(--font15Size) !important;
  323. }
  324. }
  325. .name {
  326. font-weight: bold;
  327. font-size: var(--font16Size);
  328. }
  329. .text_color {
  330. color: var(--f69Color);
  331. }
  332. }
  333. .thr {
  334. margin: 3vw 0 0 0;
  335. background-color: var(--mainColor);
  336. .thr_cont {
  337. margin: 2vw 0 0 0;
  338. .thr_1 {
  339. text-indent: 10px;
  340. border-left: 3px solid var(--f3CColor);
  341. font-weight: bold;
  342. font-size: var(--font16Size);
  343. }
  344. .thr_2 {
  345. padding: 2vw;
  346. }
  347. }
  348. }
  349. }
  350. .foot {
  351. width: 100%;
  352. height: 8vh;
  353. overflow: hidden;
  354. display: flex;
  355. align-items: center;
  356. .foot_text {
  357. display: flex;
  358. justify-content: center;
  359. align-items: center;
  360. width: 50%;
  361. height: 100%;
  362. color: var(--mainColor);
  363. }
  364. .foot_1 {
  365. background: linear-gradient(90deg, #FFCD1E, #FF8A18);
  366. }
  367. .foot_2 {
  368. background: linear-gradient(90deg, #1E83FF, #1071e6);
  369. }
  370. }
  371. .popup_cont {
  372. .popup_title {
  373. display: flex;
  374. flex-direction: row;
  375. align-items: center;
  376. justify-content: center;
  377. height: 40px;
  378. font-size: var(--font14Size);
  379. color: #666;
  380. }
  381. .popup_share {
  382. display: flex;
  383. align-items: center;
  384. padding: 2vw 0;
  385. .share_1 {
  386. width: 50%;
  387. button {
  388. background: none;
  389. border: none;
  390. display: flex;
  391. flex-direction: column;
  392. justify-content: center;
  393. align-items: center;
  394. .t-icon {
  395. width: 8vw;
  396. height: 8vw;
  397. }
  398. text {
  399. margin-top: 10px;
  400. font-size: var(--font14Size);
  401. color: #3B4144;
  402. }
  403. }
  404. }
  405. }
  406. }
  407. }
  408. .scroll-view {
  409. position: absolute;
  410. top: 0;
  411. left: 0;
  412. right: 0;
  413. bottom: 0;
  414. .list-scroll-view {
  415. display: flex;
  416. flex-direction: column;
  417. }
  418. }
  419. </style>