index.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <template>
  2. <view>
  3. <view class="ceng" @tap="hidePopupLogin"></view>
  4. <view class="popup-login">
  5. <view class="close" @tap="hidePopupLogin">
  6. <image class="image" src="/static/pages/images/close.png"></image>
  7. </view>
  8. <image :src="about.CONFIG_PROJECT_LOGO" mode="aspectFill" class="logo"></image>
  9. <view class="title">{{about.CONFIG_PROJECT_TITLE}}</view>
  10. <view class="l-btn" @click="getWXUserProfile()">授权登录</view>
  11. </view>
  12. </view>
  13. </template>
  14. <script>
  15. const app = getApp();
  16. const req = require("../../utils/request");
  17. export default {
  18. data() {
  19. return {
  20. sessionKey: '',
  21. openid:''
  22. };
  23. },
  24. props: {
  25. about: Object,
  26. },
  27. watch: {},
  28. options: {},
  29. mounted() {
  30. app.globalData.getCheckSessoin(json => {
  31. this.sessionKey = json.session_key;
  32. this.openid = json.openid;
  33. if(json.unionid){
  34. this.unionid = json.unionid;
  35. }
  36. });
  37. },
  38. methods: {
  39. hidePopupLogin() {
  40. this.$emit('hidePopupLogin');
  41. },
  42. getWXUserProfile() {
  43. uni.getUserProfile({
  44. desc: '注册',
  45. success: res => {
  46. this.toSubmitLogin(res.iv, res.encryptedData);
  47. },
  48. fail: res => {
  49. req.msg(res);
  50. }
  51. });
  52. },
  53. toSubmitLogin(iv, encryptedData) {
  54. let that = this;
  55. if (!encryptedData || !iv) return false;
  56. let _params = {
  57. sessionKey: this.sessionKey,
  58. openId: this.openid,
  59. iv: iv,
  60. encryptedData: encryptedData
  61. };
  62. if (req.getStorage('pidCode')) {
  63. _params.parentId = req.getStorage('pidCode');
  64. }
  65. if (that.unionid) {
  66. _params.unionid = that.unionid;
  67. }
  68. req.postRequest('/api/login', _params, json => {
  69. let params = json;
  70. req.setStorage('userInfo', json);
  71. that.hidePopupLogin();
  72. });
  73. },
  74. }
  75. };
  76. </script>
  77. <style scoped>
  78. @import "./index.css";
  79. </style>