testDetails.vue 6.0 KB

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