shortLink.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. <template>
  2. <view class="content">
  3. <image class="bgimg" src="/static/home_top_bg.png" mode="widthFix"></image>
  4. <view class="header-nav"
  5. :style="{height: `calc(88rpx + ${statusBarHeight}px)`,paddingTop: statusBarHeight + 'px'}">
  6. 专属链接
  7. </view>
  8. <view v-if="isLogin" class="content-body" :style="{paddingTop: `calc(88rpx + ${statusBarHeight}px)`}">
  9. <view class="tip">
  10. 您的专属链接生成成功,为保障您的个人信息安全,请勿分享给别人
  11. </view>
  12. <view class="cardbox">
  13. <view class="x-f">
  14. <u-avatar :src="avatar||user.avatar" size="44"></u-avatar>
  15. <view class="ml24">
  16. <view class="fs36 username">{{username||user.nickName}}</view>
  17. <view class="userid mt12 fs26" v-if="user&&user.userId">ID {{user.userId}}</view>
  18. </view>
  19. </view>
  20. <u-line color="#eee" margin="30rpx 0"></u-line>
  21. <view class="x-f">
  22. <text class="label fs30 mr24">所属经销商</text>
  23. <text class="val fs30">{{qwUser.companyName}}</text>
  24. </view>
  25. <u-line color="#eee" margin="30rpx 0"></u-line>
  26. <view class="x-f mb24">
  27. <text class="label fs30 mr24">当前跟进人</text>
  28. <text class="val fs30">{{qwUser.qwUserName}}</text>
  29. </view>
  30. </view>
  31. <view class="button x-ac mt24" @click="handleCopy">复制链接</view>
  32. </view>
  33. <view v-if="!isLogin" :style="{paddingTop: `calc(88rpx + ${statusBarHeight}px)`}">
  34. <view class="login-loading x-ac">
  35. <courseLoading></courseLoading>
  36. <text class="mt30">邀请您生成您的专属链接</text>
  37. </view>
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. import courseLoading from './components/courseLoading.vue'
  43. import { mapGetters } from 'vuex';
  44. import{
  45. handleFsUserWx,
  46. getByAppId,loginByMp,getUserInfoByQwUser,encryptLink} from "@/api/course.js"
  47. export default {
  48. components:{
  49. courseLoading
  50. },
  51. data() {
  52. return {
  53. statusBarHeight: uni.getSystemInfoSync().statusBarHeight,
  54. shortLink: '',
  55. loading: true,
  56. isLogin: false,
  57. username: '',
  58. avatar: '',
  59. user:{},
  60. qwUser: {},
  61. urlOption: '',
  62. code:'',
  63. authType: 1, // 授权方式
  64. }
  65. },
  66. computed: {
  67. ...mapGetters(['coureLogin']),
  68. },
  69. watch: {
  70. coureLogin: {
  71. immediate: true, // 页面一进入就检查一次
  72. handler(val) {
  73. if (val == 2) {
  74. console.log("AppToken失效,请重新登录")
  75. this.isLogin = false
  76. this.goLogin()
  77. }
  78. }
  79. }
  80. },
  81. onLoad(option) {
  82. if (option.course) {
  83. this.urlOption = option.course ? JSON.parse(decodeURIComponent(option.course)) : {}
  84. } else if(option.s){
  85. this.urlOption = option.s ? JSON.parse(decodeURIComponent(option.s)) : {}
  86. } else {
  87. const keys = decodeURIComponent(Object.keys(option)[0]);
  88. this.urlOption = JSON.parse(keys.split('course=')[1])
  89. }
  90. uni.$on('usercode',(data)=>{
  91. if(data) {
  92. this.code=data.code
  93. this.loginFsUserWx(data)
  94. }
  95. })
  96. if(this.code) return;
  97. this.utils.isLoginCourse().then(
  98. res => {
  99. console.log("=====isLoginCourse=======sss",res)
  100. if(res){
  101. this.isLogin = true
  102. this.getUserInfoByQwUser()
  103. } else{
  104. this.isLogin = false
  105. this.goLogin()
  106. }
  107. },
  108. rej => {}
  109. );
  110. },
  111. onShow() {
  112. if(uni.getStorageSync('auto_userInfo') && JSON.stringify(uni.getStorageSync('auto_userInfo'))!='{}') {
  113. this.user = JSON.parse(uni.getStorageSync('auto_userInfo'))
  114. } else {
  115. this.user = {}
  116. }
  117. },
  118. onUnload() {
  119. uni.$off('usercode')
  120. },
  121. beforeDestroy() {
  122. uni.$off('usercode')
  123. },
  124. methods: {
  125. getUserInfoByQwUser() {
  126. const param = {
  127. ...this.urlOption,
  128. appId: getApp().globalData.appId
  129. }
  130. getUserInfoByQwUser(this.urlOption).then(res=>{
  131. if(res.code ==200) {
  132. this.qwUser = res.data.qwUser || {}
  133. this.username = res.data.user.nickName || ''
  134. this.avatar = res.data.user.avatar || ''
  135. } else {
  136. uni.showToast({
  137. title: res.msg,
  138. icon: 'none'
  139. })
  140. }
  141. })
  142. },
  143. handleCopy() {
  144. this.utils.isLoginCourse().then(res => {
  145. console.log("=====isLoginCourse=======sss",res)
  146. if(res){
  147. this.isLogin = true
  148. if(!this.shortLink) {
  149. this.encryptLink()
  150. } else {
  151. uni.setClipboardData({
  152. data: this.shortLink,
  153. success: () => {
  154. uni.showToast({
  155. title: '链接已成功复制到剪切板',
  156. icon: 'none'
  157. })
  158. }
  159. });
  160. }
  161. } else{
  162. this.isLogin = false
  163. this.goLogin(1)
  164. }
  165. });
  166. },
  167. encryptLink() {
  168. const param = {
  169. ...this.urlOption,
  170. token:uni.getStorageSync('AppTokenmini_RTCourse')
  171. }
  172. const str = JSON.stringify(param)
  173. encryptLink({url: str}).then(res=>{
  174. if(res.code==200){
  175. const path = res.data.encryptionLink? res.data.encryptionLink.split('?s=')[0] : ''
  176. const link = res.data.encryptionLink? res.data.encryptionLink.split('?s=')[1] : ''
  177. this.shortLink = path+ '?s=' + encodeURIComponent(link)
  178. uni.setClipboardData({
  179. data: this.shortLink,
  180. success: () => {
  181. uni.showToast({
  182. title: '链接已成功复制到剪切板',
  183. icon: 'success'
  184. })
  185. }
  186. });
  187. } else{
  188. uni.showToast({
  189. title: res.msg,
  190. icon: 'none'
  191. })
  192. }
  193. })
  194. },
  195. goWXLogin() {
  196. this.utils.getProvider().then(provider=>{
  197. console.log('当前的环境商',provider)
  198. if (!provider) {
  199. reject()
  200. }
  201. uni.login({
  202. provider: provider,
  203. success: async loginRes => {
  204. console.log(loginRes)
  205. uni.getUserInfo({
  206. provider: provider,
  207. success: (infoRes)=> {
  208. uni.showToast({
  209. title: '登录中...',
  210. icon: 'loading'
  211. });
  212. loginByMp({code: loginRes.code,encryptedData:infoRes.encryptedData,iv:infoRes.iv,appId: getApp().globalData.appId}).then(res=>{
  213. uni.showToast({
  214. title: '登录成功',
  215. icon: 'none'
  216. });
  217. uni.hideLoading();
  218. if (res.code == 200) {
  219. this.$store.commit('setCoureLogin', 1);
  220. uni.setStorageSync('AppTokenmini_RTCourse', res.token);
  221. uni.setStorageSync('auto_userInfo', JSON.stringify(res.user));
  222. this.user = res.user
  223. this.isLogin = true
  224. this.getUserInfoByQwUser()
  225. } else {
  226. uni.showToast({
  227. title: res.msg,
  228. icon: 'none'
  229. });
  230. }
  231. }).catch(err=>{
  232. uni.hideLoading();
  233. uni.showToast({
  234. icon:'none',
  235. title: "登录失败,请重新登录",
  236. });
  237. });
  238. }
  239. });
  240. }
  241. })
  242. }).catch(err => {})
  243. },
  244. goLogin() {
  245. this.getByAppId()
  246. },
  247. getByAppId(){
  248. getByAppId(getApp().globalData.appId).then(res=>{
  249. if(res.code == 200) {
  250. this.authType = res.config.authType || 1
  251. if(this.authType == 1) {
  252. this.code = ''
  253. this.goWXLogin()
  254. } else if(this.authType==2) {
  255. this.loginFsUserWx()
  256. }
  257. } else {
  258. uni.showToast({
  259. title: res.msg,
  260. icon: 'error'
  261. })
  262. }
  263. }).catch((err)=>{
  264. uni.showToast({
  265. title: JSON.stringify(err),
  266. icon: 'error'
  267. })
  268. })
  269. },
  270. async loginFsUserWx(data) {
  271. if(data){
  272. console.log('huoqu1222',data)
  273. uni.showLoading({
  274. title: '登录中'
  275. })
  276. uni.login({
  277. provider: "weixin",
  278. success: async loginRes => {
  279. console.log(loginRes)
  280. let code = loginRes.code // 获取开发code
  281. handleFsUserWx({
  282. code: code,
  283. appId:getApp().globalData.appId,
  284. userId:data.userId
  285. })
  286. .then( res => {
  287. uni.showToast({
  288. title: '登录成功',
  289. icon: 'none'
  290. });
  291. uni.hideLoading();
  292. if(res.code==200){
  293. this.code = ''
  294. console.log("loginFsUserWx:",res)
  295. // this.userinfos=uni.getStorageSync('userinfos')
  296. let token = uni.getStorageSync('TOKEN_WEXIN');
  297. let user = uni.getStorageSync('web_userInfo')
  298. // this.userInfo=uni.getStorageSync('userInfo');
  299. // this.isLogin = true
  300. this.$store.commit('setCoureLogin', 1);
  301. uni.setStorageSync('AppTokenmini_RTCourse', token);
  302. uni.setStorageSync('auto_userInfo', JSON.stringify(user));
  303. this.user = user
  304. this.isLogin = true
  305. this.getUserInfoByQwUser()
  306. }else{
  307. uni.showToast({
  308. icon:'none',
  309. title: res.msg,
  310. });
  311. }
  312. })
  313. },
  314. })
  315. }else{
  316. uni.setStorageSync('H5course',{
  317. companyId: this.urlOption.companyId,
  318. companyUserId:this.urlOption.companyUserId,
  319. })
  320. await this.$store.dispatch('getWebviewUrl');
  321. uni.navigateTo({
  322. url:'/pages_course/webview?H5course='+uni.getStorageSync('H5course')
  323. })
  324. }
  325. }
  326. }
  327. }
  328. </script>
  329. <style scoped lang="scss">
  330. .login-loading {
  331. background-color: #fff;
  332. border-radius: 24rpx;
  333. padding: 24rpx;
  334. position: relative;
  335. z-index: 999;
  336. margin: 100rpx 30rpx 30rpx 30rpx;
  337. flex-direction: column;
  338. font-size: 30rpx;
  339. color: #555;
  340. padding: 60rpx;
  341. }
  342. .content {
  343. min-height: 100vh;
  344. &-body {
  345. position: relative;
  346. z-index: 3;
  347. padding: 0 40rpx;
  348. min-height: 100vh;
  349. }
  350. .cardbox {
  351. border-radius: 20rpx;
  352. background-color: #fff;
  353. padding: 24rpx;
  354. margin-top: 30rpx;
  355. }
  356. .username {
  357. font-weight: bold;
  358. }
  359. .userid {
  360. color: #999;
  361. }
  362. .label {
  363. color: #555;
  364. }
  365. .button {
  366. width: 100%;
  367. height: 100rpx;
  368. background: linear-gradient(90deg, #FF5C03 0%, #F0964C 100%);
  369. border-radius: 16rpx 16rpx 16rpx 16rpx;
  370. font-family: PingFang SC, PingFang SC;
  371. font-weight: 600;
  372. font-size: 34rpx;
  373. color: #FFFFFF;
  374. }
  375. }
  376. .tip {
  377. color: #FF5C03;
  378. font-size: 28rpx;
  379. margin-top: 100rpx;
  380. }
  381. .bgimg {
  382. width: 100%;
  383. position: absolute;
  384. top: 0;
  385. left: 0;
  386. }
  387. .header-nav {
  388. position: fixed;
  389. top: 0;
  390. left: 0;
  391. z-index: 999;
  392. height: 88rpx;
  393. width: 100%;
  394. display: flex;
  395. align-items: center;
  396. justify-content: center;
  397. overflow: hidden;
  398. box-sizing: border-box;
  399. }
  400. </style>