index.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. <template>
  2. <view class="home column">
  3. <view class="justify-start align-center">
  4. <image src="../../static/images/shipin.png" class="wh50 p20"></image>
  5. <view class="fs32 bold">道中</view>
  6. </view>
  7. <image :src="livedata.liveImgUrl" mode="widthFix" class="w100"></image>
  8. <view class="p20">
  9. <view class="column">
  10. <text class="fs32">{{livedata.liveName}}</text>
  11. <text class="color9 fs24 mt20">
  12. 直播时间 {{livedata.startTime}} —— {{livedata.finishTime}}</text>
  13. </view>
  14. </view>
  15. <view class="p20 detail">
  16. <view class="jianjie mb20">简介</view>
  17. <view class="fs24 lh36" v-html="livedata.liveDesc"></view>
  18. </view>
  19. <view class="p12 bgf bot-box">
  20. <view class="center" @click="comelive">进入直播间</view>
  21. </view>
  22. <u-popup :show="iskefu" @close="close" @open="open" round='20rpx' bgColor='#fffee1'>
  23. <view class="addchat p20">
  24. <view class="u-flex-row-reverse u-flex">
  25. <u-icon name="close" size="18" @click="showadd=!showadd"></u-icon>
  26. </view>
  27. <view class="column align-center">
  28. <view class="fs36" style="color: #ff5c03;">扫码添加助教老师</view>
  29. <view class="fs28 color6">扫码添加助教老师</view>
  30. <view class="p10 mt40" style="border: #ff5c03 solid 2rpx;">
  31. <image :src="codeimg" class="wh180" @touchstart="longPress" @touchend="cancelLongPress">
  32. </image>
  33. </view>
  34. <view class="color6 mt20">长按识别二维码</view>
  35. </view>
  36. </view>
  37. </u-popup>
  38. </view>
  39. </template>
  40. <script>
  41. import {
  42. loginByMp,
  43. testlogin,
  44. getlive
  45. } from '@/api/home'
  46. // // 判断是否在微信环境
  47. const isWechat = () => {
  48. return String(navigator.userAgent.toLowerCase().match(/MicroMessenger/i)) === "micromessenger";
  49. }
  50. export default {
  51. data() {
  52. return {
  53. isLogin:false,
  54. code: '',
  55. livedata: {},
  56. path: 'http://live.ylrzcloud.com/prod-api',
  57. iskefu: false,
  58. isLongPress: false, // 是否长按
  59. timeout: null, // 计时器
  60. liveId: 2
  61. }
  62. },
  63. onLoad(option) {
  64. // if (this.code) {
  65. // this.loginByMp()
  66. // } else {
  67. // this.getWechatCode()
  68. // }
  69. },
  70. onShow() {
  71. if (uni.getStorageSync('AppToken')) {
  72. this.getliving()
  73. }
  74. },
  75. methods: {
  76. open() {
  77. },
  78. close() {
  79. this.iskefu = !this.iskefu
  80. },
  81. longPress() {
  82. this.timeout = setTimeout(() => {
  83. this.isLongPress = true;
  84. // 执行保存图片的操作
  85. uni.saveImageToPhotosAlbum({
  86. filePath: this.livedata.qwQrCode, // 图片的本地路径或网络路径
  87. success: () => {
  88. uni.showToast({
  89. title: '保存成功'
  90. });
  91. },
  92. fail: () => {
  93. uni.showToast({
  94. title: '保存失败',
  95. icon: 'none'
  96. });
  97. }
  98. });
  99. }, 500); // 设置长按的阈值时间,这里是500毫秒
  100. },
  101. cancelLongPress() {
  102. clearTimeout(this.timeout);
  103. this.isLongPress = false;
  104. },
  105. getliving() {
  106. const param = {
  107. id: this.liveId
  108. }
  109. getlive(param).then(res => {
  110. if (res.code == 200) {
  111. this.livedata = res.data
  112. } else {
  113. uni.showToast({
  114. title: res.msg,
  115. icon: 'none',
  116. duration: 2000
  117. });
  118. }
  119. })
  120. },
  121. getWechatCode() {
  122. // 没有code
  123. if (isWechat) {
  124. let appid = "wx93ce67750e3cfba3"; //微信APPid
  125. let code = this.getUrlCode().code; //是否存在code
  126. // 换成本地就不行
  127. // let local = window.location.href; //这个是获取浏览器当前地址 有参数都会一起获取
  128. let local = window.location.href.split('#')[0];
  129. if (code == null || code === "") {
  130. window.location.href =
  131. "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" +
  132. appid +
  133. "&redirect_uri=" +
  134. encodeURIComponent(local) +
  135. "&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect";
  136. } else {
  137. this.code = code;
  138. this.loginByMp()
  139. }
  140. }
  141. },
  142. loginByMp() {
  143. if (this.code == null) {
  144. return;
  145. }
  146. uni.showLoading({
  147. title: "处理中..."
  148. });
  149. let that = this;
  150. var data = {
  151. code: this.code
  152. }
  153. loginByMp(data).then(res => {
  154. uni.hideLoading();
  155. if (res.code == 200) {
  156. // 登录后存token和用户信息
  157. console.log(res)
  158. uni.setStorageSync('AppToken', res.token);
  159. uni.setStorageSync('userInfo', JSON.stringify(res.user));
  160. let beforLoginUrl = uni.getStorageSync('beforLoginPage');
  161. // console.log(`登录成功后跳转${beforLoginUrl}`);
  162. //登录之后跳转的页面
  163. uni.reLaunch({
  164. url: beforLoginUrl
  165. });
  166. uni.showToast({
  167. title: '登录成功',
  168. icon: 'none'
  169. });
  170. this.getliving()
  171. } else {
  172. uni.showToast({
  173. title: res.msg,
  174. icon: 'none'
  175. });
  176. }
  177. },
  178. err => {}
  179. );
  180. },
  181. getUrlCode() {
  182. // 截取url中的code方法
  183. var url = location.search;
  184. var theRequest = new Object();
  185. if (url.indexOf("?") != -1) {
  186. var str = url.substr(1);
  187. var strs = str.split("&");
  188. for (var i = 0; i < strs.length; i++) {
  189. theRequest[strs[i].split("=")[0]] = strs[i].split("=")[1];
  190. }
  191. }
  192. return theRequest;
  193. },
  194. comelive() {
  195. uni.setStorageSync('AppToken', null);
  196. if(uni.getStorageSync('AppToken')){
  197. uni.navigateTo({
  198. url: "/pages/home/living"
  199. })
  200. }else{
  201. uni.showToast({
  202. title: '请登录授权!',
  203. icon: 'none'
  204. });
  205. uni.navigateTo({
  206. url: "/pages/login/login"
  207. })
  208. }
  209. // let nowtoken =
  210. // "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzdWIiOiI2NjYiLCJpYXQiOjE3NTE4NzQ0NzEsImV4cCI6MTc4MzQxMDQ3MX0.3uxTTb0qXygmaY9ItovMclxJCNhNEi6kFEqmfLGg4lP2PYzCPODsVjW4PjXNu6EYsl5eYyESltHWcwBnaNkilQ&signature=ff21bfb41ddd5f2e31d6f5bf32ec565aab9c518614d139fa26727468ce701237"
  211. // uni.setStorageSync('AppToken', nowtoken);
  212. // if (this.isLogin) {
  213. // uni.navigateTo({
  214. // url: "/pages/home/living"
  215. // })
  216. // } else {
  217. // uni.navigateTo({
  218. // url: "/pages/login/login"
  219. // })
  220. // }
  221. // uni.navigateTo({
  222. // url: "/pages/home/live"
  223. // })
  224. }
  225. }
  226. }
  227. </script>
  228. <style lang="scss" scoped>
  229. page {
  230. background-color: #fff;
  231. }
  232. .jianjie {
  233. font-size: 32rpx;
  234. width: fit-content;
  235. border-bottom: $--base-color solid 4rpx;
  236. }
  237. .detail {
  238. border-top: solid #f5f5f5 12rpx;
  239. }
  240. .bot-box {
  241. border-top: #f5f5f5 solid 2rpx;
  242. position: fixed;
  243. bottom: 0;
  244. width: 100%;
  245. view {
  246. width: 80%;
  247. margin: 0 auto;
  248. height: 80rpx;
  249. display: flex;
  250. align-items: center;
  251. background-color: $--base-bg;
  252. color: #fff;
  253. border-radius: 100rpx;
  254. }
  255. }
  256. .addchat {
  257. height: 450rpx;
  258. }
  259. </style>