register.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  1. <template>
  2. <view class="register_box">
  3. <template v-if="isRegister==0">
  4. <image src="https://cdn.his.cdwjyyh.com/minapp/kc_hb_bg1.png" class="imgbg" mode="widthFix"></image>
  5. <view class="kc_footer">
  6. <image src="https://cdn.his.cdwjyyh.com/minapp/kc_footer_bg.png" class="imgft" mode="widthFix"></image>
  7. <view class="kc_footer_btn" @click="getLink">{{isRegister==1?'注册成功':'立即注册'}}</view>
  8. </view>
  9. </template>
  10. <view v-else class="success_box">
  11. <image src="https://cdn.his.cdwjyyh.com/minapp/course_register_img.png" mode="heightFix"></image>
  12. <view>注册成功</view>
  13. </view>
  14. <u-popup :show="userlogo" mode="bottom" round='12'>
  15. <view class="userlogo column">
  16. <view class="mtb30 justify-start align-center ml20">
  17. <u-avatar :src="imgPath+'/app/image/logo.png'" size="50"></u-avatar>
  18. <view class="bold mlr20">丝路佳选</view>
  19. <view>申请</view>
  20. </view>
  21. <view class="bold fs36 ml20">授权你的昵称头像信息</view>
  22. <view class="mtb20 justify-between align-center plr20">
  23. <view class="justify-start align-center">
  24. <view class="boxweixin" :class="userinfos.nickname==''?'boxnosel':'boxsel'">
  25. <view v-if="userinfos.nickname">√</view>
  26. </view>
  27. <view class="ml20">
  28. <view class="base-color-3 bold">第一步</view>
  29. <view class="fs32 base-color-9">请点击授权微信昵称</view>
  30. </view>
  31. </view>
  32. <view class="button-container">
  33. <input
  34. type="nickname"
  35. class="hidden-input"
  36. @blur="onNickNameInput"
  37. @input="onNickNameInput"
  38. />
  39. <button class="custom-button" :class="nameuser==''?'subname':'subavt'">{{nameuser?"已授权":'允许授权'}}</button>
  40. </view>
  41. </view>
  42. <!-- <view class="mtb20 justify-between align-center plr20 mt40">
  43. <view class="justify-start align-center">
  44. <view class="boxweixin" :class="userinfos.nickname==''?'boxnosel':'boxsel'">
  45. <view v-if="userinfos.avatar">√</view>
  46. </view>
  47. <view class="ml20">
  48. <view class="base-color-3 bold">第二步</view>
  49. <view class="fs32 base-color-9">请点击授权微信头像</view>
  50. </view>
  51. </view>
  52. <view class="button-container">
  53. <button open-type="chooseAvatar" @chooseavatar="onChooseAvatar" class="hidden-input"
  54. v-if="nameuser">
  55. 允许授权
  56. </button>
  57. <button class="custom-button sub" @click="shouquan" v-if="nameuser==''">允许授权</button>
  58. <button class="custom-button " :class="avataruser==''?'subname':'subavt'"
  59. v-else>{{avataruser?"已授权":'允许授权'}}</button>
  60. </view>
  61. </view> -->
  62. <view class="submitname" @click="confimrname" :class="nameuser&&avataruser?'subact':'sub'">确定</view>
  63. </view>
  64. </u-popup>
  65. </view>
  66. </template>
  67. <script>
  68. import { mapGetters } from 'vuex';
  69. import {getRealLink,handleFsUserWx,isAddCompanyUser,loginByMp,editUser} from "@/api/course.js"
  70. export default {
  71. data() {
  72. return {
  73. isLogin: false,
  74. isRegister: 0,
  75. isLoading: false,
  76. urlOption: {},
  77. sortLink: '',
  78. isLoginH5:0, // 1服务号授权
  79. userlogo:false,
  80. imgname:'',
  81. userinfos:{
  82. nickname:"",
  83. avatar:""
  84. },
  85. chatId:''
  86. }
  87. },
  88. computed:{
  89. ...mapGetters(['coureLogin']),
  90. nameuser() {
  91. return this.userinfos.nickname
  92. },
  93. avataruser() {
  94. return this.userinfos.avatar
  95. },
  96. },
  97. watch: {
  98. coureLogin: {
  99. immediate: true, // 页面一进入就检查一次
  100. handler(val) {
  101. if (val == 2&&this.isLogin) {
  102. console.log("注册AppToken失效,请重新登录")
  103. uni.removeStorageSync('web_userInfo');
  104. uni.removeStorageSync('TOKEN_WEXIN');
  105. this.isLogin = false
  106. if(this.isLoginH5==0){
  107. this.goWXLogin()
  108. }else{
  109. this.goLogin()
  110. }
  111. }
  112. }
  113. }
  114. },
  115. onLoad(option) {
  116. this.urlOption = option.link ? JSON.parse(decodeURIComponent(option.link)) : {},
  117. this.sortLink = this.urlOption.link || ''
  118. console.log(this.sortLink)
  119. uni.$on('usercode',(data)=>{
  120. if(data) {
  121. this.goLogin(data)
  122. }
  123. })
  124. },
  125. beforeDestroy() {
  126. uni.$off('usercode')
  127. },
  128. onUnload() {
  129. uni.$off('usercode')
  130. },
  131. methods: {
  132. //修改用户昵称以及头像
  133. editUserA(){
  134. this.userinfos=uni.getStorageSync('userInfos')?uni.getStorageSync('userInfos'):this.userinfos
  135. const data={
  136. nickName:this.userinfos.nickname,
  137. // avatar:this.userinfos.avatar,
  138. }
  139. editUser(data).then(res=>{
  140. if(res.code==200){
  141. this.isLogin = true
  142. uni.showToast({
  143. icon:'none',
  144. title:'修改成功!',
  145. });
  146. setTimeout(()=>{
  147. // this.getIsAddKf()
  148. this.getAddCompanyUser()
  149. },100)
  150. }else{
  151. uni.removeStorageSync('userInfos')
  152. uni.showToast({
  153. icon:'none',
  154. title:res.msg+'请重新点击立即学习',
  155. });
  156. }
  157. })
  158. },
  159. shouquan(){
  160. if(this.userinfos.nickname==''){
  161. uni.showToast({
  162. icon:'none',
  163. title: "请先授权微信昵称",
  164. });
  165. }
  166. },
  167. confimrname(){
  168. if(this.userinfos.nickname==''){
  169. uni.showToast({
  170. icon:'none',
  171. title: "请授权微信昵称",
  172. });
  173. return
  174. }
  175. // if(this.userinfos.avatar==''){
  176. // uni.showToast({
  177. // icon:'none',
  178. // title: "请授权微信头像",
  179. // });
  180. // return
  181. // }
  182. uni.setStorageSync('userInfos',this.userinfos)
  183. this.editUserA()
  184. this.userlogo=false
  185. },
  186. onNickNameInput(e){
  187. console.log(e)
  188. this.userinfos.nickname=e.detail.value
  189. },
  190. onChooseAvatar(e){
  191. this.userinfos.avatar=e.detail.avatarUrl
  192. uni.uploadFile({
  193. url: 'https://h5api.his.cdwjyyh.com'+'/app/common/uploadOSS', //仅为示例,非真实的接口地址
  194. filePath: e.detail.avatarUrl,
  195. name: 'file',
  196. formData: {
  197. 'user': 'test' // 上传附带参数
  198. },
  199. success: (uploadFileRes) => {
  200. console.log(uploadFileRes)
  201. // 根据接口具体返回格式 赋值具体对应url
  202. var data=JSON.parse(uploadFileRes.data)
  203. this.headImg=uni.getStorageSync('requestPath')+data.fileName
  204. this.userinfos.avatar=data.url
  205. }
  206. });
  207. },
  208. getLink() {
  209. if(!this.sortLink){
  210. uni.showToast({
  211. title: '链接错误',
  212. icon: 'none'
  213. });
  214. return
  215. }
  216. let that = this;
  217. uni.showLoading({
  218. title: '注册中'
  219. })
  220. getRealLink({sortLink:this.sortLink}).then(res=>{
  221. uni.hideLoading()
  222. if(res.code == 200) {
  223. let linkurl=JSON.parse(res.realLink.split('?link=')[1])
  224. this.chatId=linkurl.chatId
  225. console.log(this.chatId)
  226. if(res.config&&res.config.userCourseAuthDomain) {
  227. uni.setStorageSync('weixinOauth',res.config.userCourseAuthDomain)
  228. if(this.isLoginH5==0) {
  229. this.utils.isLoginCourse().then(
  230. isLogin => {
  231. this.isLogin = isLogin
  232. if(this.isLogin) {
  233. // this.editUserA()
  234. if(this.chatId!=''||this.chatId){
  235. this.userlogo=true
  236. }else{
  237. this.getAddCompanyUser()
  238. }
  239. } else {
  240. this.goLogin()
  241. }
  242. },
  243. rej => {}
  244. );
  245. }else {
  246. this.utils.isLoginResCourse().then(
  247. isLogin => {
  248. this.isLogin = isLogin
  249. if(this.isLogin) {
  250. this.getAddCompanyUser()
  251. } else {
  252. this.goLogin()
  253. }
  254. },
  255. rej => {}
  256. );
  257. }
  258. }else {
  259. uni.showToast({
  260. title: '授权地址错误',
  261. icon: 'none'
  262. });
  263. }
  264. } else {
  265. uni.showToast({
  266. title: res.msg,
  267. icon: 'none'
  268. });
  269. }
  270. }).catch(err=>{
  271. uni.hideLoading()
  272. uni.showToast({
  273. title: '发生错误,请稍后再试',
  274. icon: 'none'
  275. });
  276. })
  277. },
  278. goLogin(data) {
  279. if(this.isLoginH5==0) {
  280. this.goWXLogin()
  281. return
  282. }
  283. if(data) {
  284. this.utils.getProvider().then(provider=>{
  285. console.log('当前的环境商',provider)
  286. if (!provider) {
  287. reject()
  288. }
  289. uni.login({
  290. provider: provider,
  291. success: loginRes => {
  292. console.log(loginRes)
  293. uni.getUserInfo({
  294. provider: provider,
  295. success: (infoRes)=> {
  296. const param = {
  297. code: loginRes.code, // 必填参数,不能为空,code参数缺失时会报错
  298. appId: getApp().globalData.appId, // 应用ID
  299. userId: data.userId // 用户id
  300. }
  301. uni.showLoading({
  302. title: '注册中'
  303. })
  304. handleFsUserWx(param).then(res=>{
  305. uni.hideLoading()
  306. if(res.code==200) {
  307. this.getAddCompanyUser()
  308. } else {
  309. uni.removeStorageSync('web_userInfo');
  310. uni.removeStorageSync('TOKEN_WEXIN');
  311. uni.showToast({
  312. title: res.msg,
  313. icon: 'none'
  314. });
  315. }
  316. }).catch(err=>{
  317. uni.hideLoading()
  318. })
  319. }
  320. });
  321. }
  322. })
  323. })
  324. } else {
  325. uni.setStorageSync('H5course',{
  326. companyId: this.urlOption.companyId,
  327. companyUserId:this.urlOption.companyUserId,
  328. })
  329. uni.navigateTo({
  330. url:'/pages_course/webview'
  331. })
  332. }
  333. },
  334. getAddCompanyUser() {
  335. isAddCompanyUser(this.urlOption).then(res=>{
  336. if(res.code==200) {
  337. this.isRegister = 1
  338. } else {
  339. uni.showToast({
  340. title: res.msg,
  341. icon: 'none'
  342. });
  343. }
  344. })
  345. },
  346. goWXLogin() {
  347. this.utils.getProvider().then(provider=>{
  348. console.log('当前的环境商',provider)
  349. if (!provider) {
  350. reject()
  351. }
  352. uni.login({
  353. provider: provider,
  354. success: async loginRes => {
  355. console.log(loginRes)
  356. uni.getUserInfo({
  357. provider: provider,
  358. success: (infoRes)=> {
  359. uni.showToast({
  360. title: '注册中...',
  361. icon: 'loading'
  362. });
  363. loginByMp({code: loginRes.code,encryptedData:infoRes.encryptedData,iv:infoRes.iv,appId:getApp().globalData.appId}).then(res=>{
  364. uni.hideLoading();
  365. if (res.code == 200) {
  366. // this.checkUserInfoA()
  367. this.$store.commit('setCoureLogin', 1);
  368. uni.setStorageSync('AppTokenmini_RTCourse', res.token);
  369. uni.setStorageSync('auto_userInfo', JSON.stringify(res.user));
  370. this.isLogin = true
  371. if(this.chatId!=''||this.chatId){
  372. this.userlogo=true
  373. }else{
  374. this.getAddCompanyUser()
  375. }
  376. } else {
  377. uni.showToast({
  378. title: res.msg,
  379. icon: 'none'
  380. });
  381. }
  382. }).catch(err=>{
  383. uni.hideLoading();
  384. uni.showToast({
  385. icon:'none',
  386. title: "登录失败,请重新登录",
  387. });
  388. });
  389. }
  390. });
  391. }
  392. })
  393. }).catch(err => {})
  394. }
  395. }
  396. }
  397. </script>
  398. <style>
  399. page {
  400. background-color: #fff;
  401. }
  402. </style>
  403. <style scoped lang="scss">
  404. .subname{
  405. background-color: #00aa00;
  406. color: #fff;
  407. }
  408. .subavt{
  409. background-color: #fff;
  410. border: 2rpx #0a0 solid;
  411. color: #00aa00;
  412. }
  413. .boxweixin{
  414. width: 44rpx;
  415. height: 44rpx;
  416. border-radius: 50%;
  417. text-align: center;
  418. line-height: 34rpx;
  419. color: #0a0;
  420. }
  421. .boxnosel{
  422. border: #757575 4rpx solid;
  423. }
  424. .boxsel{
  425. border: #0a0 4rpx solid;
  426. }
  427. .button-container {
  428. position: relative;
  429. width: 240rpx;
  430. }
  431. .hidden-input {
  432. position: absolute;
  433. top: 0;
  434. left: 0;
  435. width: 100%;
  436. height: 100%;
  437. opacity: 0;
  438. z-index: 2;
  439. }
  440. .custom-button {
  441. position: relative;
  442. z-index: 1;
  443. /* 其他样式 */
  444. width:100%;
  445. margin: 0 auto;
  446. height: 80rpx;
  447. line-height: 60rpx;
  448. font-size: 28rpx;
  449. padding: 10rpx 20rpx;
  450. }
  451. .submitname{
  452. width: 90%;
  453. margin: 0 auto;
  454. text-align: center;
  455. padding: 30rpx;
  456. margin-top: 40rpx;
  457. }
  458. .sub{
  459. background-color: #f0f0f0;
  460. color: #0a0;
  461. }
  462. .subact{
  463. background-color: #0a0;
  464. color: #fff;
  465. }
  466. .userlogo{
  467. height: 760rpx;
  468. }
  469. .timepopbox{
  470. width: 560rpx;
  471. padding: 32rpx;
  472. box-sizing: border-box;
  473. }
  474. .register_box {
  475. position: relative;
  476. min-height: 100vh;
  477. }
  478. @keyframes scaleAnimation {
  479. 0% {
  480. transform: translate(-50%, -50%) scale(1);
  481. }
  482. 50% {
  483. transform: translate(-50%, -50%) scale(1.05);
  484. }
  485. 100% {
  486. transform: translate(-50%, -50%) scale(1);
  487. }
  488. }
  489. .success_box {
  490. height: 100vh;
  491. width: 100%;
  492. display: flex;
  493. flex-direction: column;
  494. align-items: center;
  495. justify-content: center;
  496. font-family: PingFang SC, PingFang SC;
  497. font-weight: 500;
  498. font-size: 64rpx;
  499. color: #222222;
  500. image {
  501. width: 404rpx;
  502. height: 404rpx;
  503. margin-bottom: 26rpx;
  504. }
  505. }
  506. .imgbg {
  507. width: 100%;
  508. }
  509. .kc_footer {
  510. width: 100%;
  511. position: absolute;
  512. bottom: 0;
  513. left: 0;
  514. &_btn {
  515. width: 528rpx;
  516. height: 96rpx;
  517. background: #FF5C03;
  518. border-radius: 48rpx 48rpx 48rpx 48rpx;
  519. font-family: PingFang SC, PingFang SC;
  520. font-weight: 500;
  521. font-size: 32rpx;
  522. color: #FFFFFF;
  523. display: flex;
  524. align-items: center;
  525. justify-content: center;
  526. position: absolute;
  527. bottom: 20%;
  528. left: 50%;
  529. transform: translate(-50%, -50%) scale(1);
  530. // will-change: transform;
  531. // animation: scaleAnimation 1s ease infinite;
  532. }
  533. }
  534. .imgft {
  535. width: 100%;
  536. }
  537. </style>