register.vue 14 KB

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