register.vue 13 KB

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