index.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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. this.a()
  65. // if (this.code) {
  66. // this.loginByMp()
  67. // } else {
  68. // this.getWechatCode()
  69. // }
  70. },
  71. onShow() {
  72. if (uni.getStorageSync('AppToken')) {
  73. this.getliving()
  74. }
  75. },
  76. methods: {
  77. a() {
  78. uni.login({
  79. provider: "weixin",
  80. success: async loginRes => {
  81. let code = loginRes.code
  82. console.log("that.code",code)
  83. }
  84. })},
  85. open() {
  86. },
  87. close() {
  88. this.iskefu = !this.iskefu
  89. },
  90. longPress() {
  91. this.timeout = setTimeout(() => {
  92. this.isLongPress = true;
  93. // 执行保存图片的操作
  94. uni.saveImageToPhotosAlbum({
  95. filePath: this.livedata.qwQrCode, // 图片的本地路径或网络路径
  96. success: () => {
  97. uni.showToast({
  98. title: '保存成功'
  99. });
  100. },
  101. fail: () => {
  102. uni.showToast({
  103. title: '保存失败',
  104. icon: 'none'
  105. });
  106. }
  107. });
  108. }, 500); // 设置长按的阈值时间,这里是500毫秒
  109. },
  110. cancelLongPress() {
  111. clearTimeout(this.timeout);
  112. this.isLongPress = false;
  113. },
  114. getliving() {
  115. const param = {
  116. id: this.liveId
  117. }
  118. getlive(param).then(res => {
  119. if (res.code == 200) {
  120. this.livedata = res.data
  121. } else {
  122. uni.showToast({
  123. title: res.msg,
  124. icon: 'none',
  125. duration: 2000
  126. });
  127. }
  128. })
  129. },
  130. getWechatCode() {
  131. // 没有code
  132. if (isWechat) {
  133. let appid = "wx93ce67750e3cfba3"; //微信APPid
  134. let code = this.getUrlCode().code; //是否存在code
  135. // 换成本地就不行
  136. // let local = window.location.href; //这个是获取浏览器当前地址 有参数都会一起获取
  137. let local = window.location.href.split('#')[0];
  138. if (code == null || code === "") {
  139. window.location.href =
  140. "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" +
  141. appid +
  142. "&redirect_uri=" +
  143. encodeURIComponent(local) +
  144. "&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect";
  145. } else {
  146. this.code = code;
  147. this.loginByMp()
  148. }
  149. }
  150. },
  151. loginByMp() {
  152. if (this.code == null) {
  153. return;
  154. }
  155. uni.showLoading({
  156. title: "处理中..."
  157. });
  158. let that = this;
  159. var data = {
  160. code: this.code
  161. }
  162. loginByMp(data).then(res => {
  163. uni.hideLoading();
  164. if (res.code == 200) {
  165. // 登录后存token和用户信息
  166. console.log(res)
  167. uni.setStorageSync('AppToken', res.token);
  168. uni.setStorageSync('userInfo', JSON.stringify(res.user));
  169. let beforLoginUrl = uni.getStorageSync('beforLoginPage');
  170. // console.log(`登录成功后跳转${beforLoginUrl}`);
  171. //登录之后跳转的页面
  172. uni.reLaunch({
  173. url: beforLoginUrl
  174. });
  175. uni.showToast({
  176. title: '登录成功',
  177. icon: 'none'
  178. });
  179. this.getliving()
  180. } else {
  181. uni.showToast({
  182. title: res.msg,
  183. icon: 'none'
  184. });
  185. }
  186. },
  187. err => {}
  188. );
  189. },
  190. getUrlCode() {
  191. // 截取url中的code方法
  192. var url = location.search;
  193. var theRequest = new Object();
  194. if (url.indexOf("?") != -1) {
  195. var str = url.substr(1);
  196. var strs = str.split("&");
  197. for (var i = 0; i < strs.length; i++) {
  198. theRequest[strs[i].split("=")[0]] = strs[i].split("=")[1];
  199. }
  200. }
  201. return theRequest;
  202. },
  203. comelive() {
  204. uni.setStorageSync('AppToken', null);
  205. if(uni.getStorageSync('AppToken')){
  206. uni.navigateTo({
  207. url: "/pages/home/living"
  208. })
  209. }else{
  210. uni.showToast({
  211. title: '请登录授权!',
  212. icon: 'none'
  213. });
  214. uni.navigateTo({
  215. url: "/pages/auth/login"
  216. })
  217. }
  218. // let nowtoken =
  219. // "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzdWIiOiI2NjYiLCJpYXQiOjE3NTE4NzQ0NzEsImV4cCI6MTc4MzQxMDQ3MX0.3uxTTb0qXygmaY9ItovMclxJCNhNEi6kFEqmfLGg4lP2PYzCPODsVjW4PjXNu6EYsl5eYyESltHWcwBnaNkilQ&signature=ff21bfb41ddd5f2e31d6f5bf32ec565aab9c518614d139fa26727468ce701237"
  220. // uni.setStorageSync('AppToken', nowtoken);
  221. // if (this.isLogin) {
  222. // uni.navigateTo({
  223. // url: "/pages/home/living"
  224. // })
  225. // } else {
  226. // uni.navigateTo({
  227. // url: "/pages/login/login"
  228. // })
  229. // }
  230. // uni.navigateTo({
  231. // url: "/pages/home/live"
  232. // })
  233. }
  234. }
  235. }
  236. </script>
  237. <style lang="scss" scoped>
  238. page {
  239. background-color: #fff;
  240. }
  241. .jianjie {
  242. font-size: 32rpx;
  243. width: fit-content;
  244. border-bottom: $--base-color solid 4rpx;
  245. }
  246. .detail {
  247. border-top: solid #f5f5f5 12rpx;
  248. }
  249. .bot-box {
  250. border-top: #f5f5f5 solid 2rpx;
  251. position: fixed;
  252. bottom: 0;
  253. width: 100%;
  254. view {
  255. width: 80%;
  256. margin: 0 auto;
  257. height: 80rpx;
  258. display: flex;
  259. align-items: center;
  260. background-color: $--base-bg;
  261. color: #fff;
  262. border-radius: 100rpx;
  263. }
  264. }
  265. .addchat {
  266. height: 450rpx;
  267. }
  268. </style>