testDetails.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. <template>
  2. <view class="content">
  3. <view class="bg-box">
  4. <image src="https://zkzh-2025.oss-cn-beijing.aliyuncs.com/appimgs/71014b69fdcc4b56ae2a84bdc28f11c3.png"></image>
  5. <view class="title-box">
  6. <view class="title">
  7. {{item.name}}
  8. </view>
  9. </view>
  10. </view>
  11. <view class="cont">
  12. <view class="msg-box">
  13. <view class="msg">{{item.msg}}</view>
  14. </view>
  15. <view class="line"></view>
  16. <view class="desc-box">
  17. <view class="desc" v-html="item.descs"> </view>
  18. </view>
  19. <view class="btn-box">
  20. <view class="btn" @click="navTo('/pages/article/test?tempId='+item.tempId)">立即开始测试</view>
  21. <view class="btn share" @click="doShare()">邀请好友测试</view>
  22. </view>
  23. </view>
  24. <!-- 分享弹窗 -->
  25. <u-popup :show="showShare" @close="showShare = false" >
  26. <share-box :shareItem="shareItem" @closeShare='showShare = false' ></share-box>
  27. </u-popup>
  28. </view>
  29. </template>
  30. <script>
  31. import {getTestDetails} from '@/api/test.js'
  32. export default {
  33. data() {
  34. return {
  35. tempId:null,
  36. item:{},
  37. showShare:false,
  38. shareItem:{ imageUrl:"",title:"",path:"",isMini:true },
  39. };
  40. },
  41. onLoad(option) {
  42. this.tempId=option.tempId;
  43. },
  44. onUnload() {
  45. //this.handleBeforeUnload();
  46. },
  47. onHide(){
  48. //this.handleBeforeUnload();
  49. },
  50. mounted() {
  51. document.addEventListener('visibilitychange', this.handleVisibilityChange);
  52. },
  53. beforeDestroy() {
  54. document.removeEventListener('visibilitychange', this.handleVisibilityChange);
  55. },
  56. onShow() {
  57. if(!this.$isLogin()) {
  58. uni.navigateTo({
  59. url: '/pages/auth/loginIndex'
  60. })
  61. return
  62. }
  63. this.getTestDetails();
  64. },
  65. //发送给朋友
  66. onShareAppMessage(res) {
  67. if(this.$isLogin()){
  68. return {
  69. title: "健康自测",
  70. path: '/pages_index/testDetails?tempId='+this.tempId,
  71. imageUrl: 'https://zkzh-2025.oss-cn-beijing.aliyuncs.com/appimgs/minilogo.png' //分享图标,路径可以是本地文件路径、代码包文件路径或者网络图片路径.支持PNG及JPG。显示图片长宽比是 5:4
  72. }
  73. }
  74. },
  75. //分享到朋友圈
  76. onShareTimeline(res) {
  77. if(this.$isLogin()){
  78. return {
  79. title: "健康自测",
  80. path: '/pages_index/testDetails?tempId='+this.tempId,
  81. imageUrl: 'https://zkzh-2025.oss-cn-beijing.aliyuncs.com/appimgs/minilogo.png' //分享图标,路径可以是本地文件路径、代码包文件路径或者网络图片路径.支持PNG及JPG。显示图片长宽比是 5:4
  82. }
  83. }
  84. },
  85. methods:{
  86. handleVisibilityChange(){
  87. if (document.visibilityState === 'hidden') { // 用户正在离开页面
  88. console.log("handleBeforeUnload 退出onaLod");
  89. uni.showToast({title:"退出onaLod",icon:'none',duration:3000 });
  90. }
  91. },
  92. navTo(url) {
  93. if(!this.$isLogin()){
  94. uni.navigateTo({
  95. url: '/pages/auth/loginIndex'
  96. })
  97. return;
  98. }
  99. uni.navigateTo({
  100. url: url
  101. });
  102. },
  103. getTestDetails(){
  104. let data = {tempId:this.tempId};
  105. getTestDetails(data).then(
  106. res => {
  107. if(res.code==200){
  108. this.item=res.data;
  109. uni.setNavigationBarTitle({
  110. title: this.item.name+"自测"
  111. });
  112. }else{
  113. uni.showToast({
  114. icon:'none',
  115. title: "请求失败",
  116. });
  117. }
  118. },
  119. rej => {}
  120. );
  121. },
  122. doShare(){
  123. //#ifdef APP-PLUS
  124. this.shareItem.title= "健康自测";
  125. this.shareItem.imageUrl="https://zkzh-2025.oss-cn-beijing.aliyuncs.com/appimgs/71014b69fdcc4b56ae2a84bdc28f11c3.png";
  126. this.shareItem.compressImage = 1;
  127. this.shareItem.isMini=true;
  128. this.shareItem.path='/pages_index/testDetails?tempId='+this.tempId;
  129. let cdn=uni.getStorageSync('h5Path');
  130. this.shareItem.url=cdn+'/pages/article/testDetails?tempId='+this.tempId;
  131. this.showShare=true;
  132. //#endif
  133. }
  134. }
  135. }
  136. </script>
  137. <style lang="scss" scoped>
  138. page{
  139. height: 100%;
  140. }
  141. .content{
  142. position: relative;
  143. height: 100%;
  144. display: flex;
  145. flex-direction: column;
  146. .bg-box{
  147. position: absolute;
  148. width: 100%;
  149. height: 600rpx;
  150. .title-box{
  151. top: 50rpx;
  152. left:50rpx;
  153. position: absolute;
  154. .title{
  155. border-radius: 5rpx;
  156. border: 1rpx solid #fff;
  157. padding: 20rpx 30rpx;
  158. font-size: 36rpx;
  159. font-family: Source Han Sans CN;
  160. font-weight: bold;
  161. color: #fff;
  162. }
  163. }
  164. image{
  165. position: absolute;
  166. width: 100%;
  167. height: 100%;
  168. }
  169. }
  170. .cont{
  171. position: relative;
  172. margin-top: 550rpx;
  173. z-index: 9999;
  174. padding: 30rpx;
  175. height: 100%;
  176. display: flex;
  177. flex-direction: column;
  178. padding: 30rpx;
  179. background-color: #fff;
  180. border-radius: 30rpx 30rpx 0rpx 0rpx;
  181. .msg-box{
  182. .msg{
  183. font-size: 36rpx;
  184. font-family: Source Han Sans CN;
  185. font-weight: bold;
  186. color: #111;
  187. }
  188. }
  189. .line{
  190. margin: 15rpx 0rpx;
  191. background-color: #F6F6F6;
  192. height:5rpx;
  193. width: 100%;
  194. }
  195. .desc-box{
  196. margin-top: 20rpx;
  197. background: #FFFFFF;
  198. .desc{
  199. color: #814E1B;
  200. }
  201. }
  202. .logo{
  203. display: flex;
  204. align-items: center;
  205. justify-content: center;
  206. margin: 60rpx 0rpx;
  207. width: 100%;
  208. image{
  209. width: 200rpx;
  210. height:100rpx;
  211. }
  212. }
  213. .btn-box{
  214. margin-top: 60rpx;
  215. height: 140upx;
  216. width: 100%;
  217. box-sizing: border-box;
  218. display: flex;
  219. flex-direction: column;
  220. align-items: center;
  221. justify-content: center;
  222. .btn{
  223. width: 100%;
  224. height: 88upx;
  225. line-height: 88upx;
  226. text-align: center;
  227. font-size: 34upx;
  228. font-family: PingFang SC;
  229. font-weight: bold;
  230. color: #FFFFFF;
  231. background: #2583EB;
  232. border-radius: 50upx;
  233. }
  234. .share{
  235. color: #FFFFFF;
  236. background: #2583EB;
  237. margin-top: 20rpx;
  238. }
  239. }
  240. }
  241. }
  242. </style>