金诚优选前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

242 lines
5.4 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. <template>
  2. <view>
  3. <lf-nav title="登录/注册" :showIcon="true" bgColor="#fff"></lf-nav>
  4. <view class="illustration">
  5. <image class="img" src="../../../static/images/empty.png" mode="aspectFill"></image>
  6. </view>
  7. <view class="fixed-btn">
  8. <button class="btn1" hover-class="lf-opacity" @click="toPhoneLogin">手机号登录</button>
  9. <button class="btn2" hover-class="lf-opacity" @click="wxLogin">微信授权登录</button>
  10. </view>
  11. </view>
  12. </template>
  13. <script>
  14. import { config, wechat, GetUrl } from '@/common/js/utils.js';
  15. export default {
  16. data(){
  17. return {
  18. code: '',
  19. url: '',
  20. logo: '',
  21. author: config.PACKAGES.author,
  22. config: '',
  23. showAgreement: false,
  24. agreement: '',
  25. open_id: '',
  26. h5_url: ''
  27. }
  28. },
  29. onShow(){
  30. var token = this.$cookieStorage.get('user_token');
  31. // this.setData({
  32. // token: token
  33. // });
  34. this.token = token;
  35. var initInfo = this.$cookieStorage.get('init');
  36. if (initInfo && initInfo.shop_show_logo) {
  37. this.setData({
  38. logo: initInfo.shop_show_logo
  39. });
  40. }
  41. if (token) {
  42. wx.switchTab({
  43. url: '/pages/user/personal/personal'
  44. });
  45. } else {
  46. // #ifdef MP-WEIXIN
  47. this.wxLogin();
  48. // #endif
  49. }
  50. },
  51. onLoad(e){
  52. // 第三方平台配置颜色
  53. var bgConfig = this.$cookieStorage.get('globalConfig') || '';
  54. this.setData({
  55. config: bgConfig
  56. });
  57. if (e.url) {
  58. this.url = decodeURIComponent(e.url);
  59. console.log('this.url',this.url)
  60. }
  61. if (e.shop_id) {
  62. this.$cookieStorage.set('shop_id', e.shop_id);
  63. }
  64. this.getGreementInfo();
  65. },
  66. methods: {
  67. // 获取用户协议
  68. getGreementInfo() {
  69. console.log("获取协议")
  70. // this.$http.get({
  71. // api: 'api/user/agreement'
  72. // }).then(res => {
  73. // if (res.statusCode == 200) {
  74. // res = res.data;
  75. // if (res.status) {
  76. // this.setData({
  77. // agreement: res.data
  78. // });
  79. // }
  80. // }
  81. // });
  82. },
  83. wxLogin(){
  84. uni.showLoading({
  85. title: '正在自动登录',
  86. mask: true
  87. });
  88. uni.login({
  89. success: res => {
  90. console.log(res);
  91. if (res.code) {
  92. this.autoLogin(res.code);
  93. } else {
  94. this.$msg('获取code失败');
  95. }
  96. },
  97. });
  98. // uni.getUserProfile({
  99. // desc: '我们将获取到的信息用于展示',
  100. // lang: 'zh_CN',
  101. // complete: result => {
  102. // console.log(result);
  103. // if(result.errMsg == 'getUserProfile:ok'){
  104. // console.log("获取成功!");
  105. // }
  106. // }
  107. // })
  108. },
  109. autoLogin(code) {
  110. this.$http.post({
  111. api: 'api/oauth/miniprogram/login',
  112. data: {
  113. code: code,
  114. open_type: 'miniprogram',
  115. shop_id: this.$cookieStorage.get('shop_id') || '',
  116. agent_code: this.$cookieStorage.get('coupon_agent_code') || this.$cookieStorage.get('agent_code') || '',
  117. clerk_id: this.$cookieStorage.get('clerk_id') || '',
  118. agent_code_time: this.$cookieStorage.get('agent_code_time') || '',
  119. shop_id_time: this.$cookieStorage.get('shop_id_time') || ''
  120. }
  121. }).then(res => {
  122. res = res.data;
  123. if (res.data && res.data.open_id) {
  124. this.setData({
  125. open_id: res.data.open_id
  126. });
  127. } // 如果接口返回token就直接登录,如果没有则弹出授权
  128. if (res.data.access_token) {
  129. console.log('已经返回给我了token');
  130. wx.hideLoading();
  131. var access_token = res.data.token_type + ' ' + res.data.access_token;
  132. var expires_in = res.data.expires_in || 315360000;
  133. this.$cookieStorage.set("user_token", access_token, expires_in);
  134. if (this.url) {
  135. wx.redirectTo({
  136. url: "/" + this.url,
  137. fail: () => {
  138. wx.switchTab({
  139. url: "/" + this.url
  140. });
  141. }
  142. })
  143. } else {
  144. wx.switchTab({
  145. url: '/pages/user/personal/personal'
  146. });
  147. }
  148. } else {
  149. wx.hideLoading();
  150. }
  151. }).catch(rej => {
  152. wx.hideLoading();
  153. wx.showModal({
  154. content: '请求失败,请重试',
  155. showCancel: false,
  156. success: res => {
  157. if (res.confirm || !res.cancel && !res.confirm) {
  158. this.wxLogin();
  159. }
  160. }
  161. });
  162. });
  163. },
  164. toPhoneLogin(){
  165. this.$url('/pages/user/loginType/loginType');
  166. },
  167. setData: function(obj) {
  168. let that = this;
  169. let keys = [];
  170. let val, data;
  171. Object.keys(obj).forEach(function(key) {
  172. keys = key.split('.');
  173. val = obj[key];
  174. data = that.$data;
  175. keys.forEach(function(key2, index) {
  176. if (index + 1 == keys.length) {
  177. that.$set(data, key2, val);
  178. } else {
  179. if (!data[key2]) {
  180. that.$set(data, key2, {});
  181. }
  182. }
  183. data = data[key2];
  184. });
  185. });
  186. }
  187. }
  188. }
  189. </script>
  190. <style lang="scss" scoped>
  191. .illustration{
  192. width: 750rpx;
  193. height: 750rpx;
  194. position: fixed;
  195. top: 44%;
  196. left: 0;
  197. margin-top: -375rpx;
  198. .img{
  199. width: 100%;
  200. height: 100%;
  201. }
  202. }
  203. .fixed-btn{
  204. width: 630rpx;
  205. height: max-content;
  206. position: fixed;
  207. left: calc(50% - 315rpx);
  208. top: calc(46% + 375rpx);
  209. display: flex;
  210. justify-content: space-between;
  211. .btn1, .btn2{
  212. width: 300rpx;
  213. height: 100rpx;
  214. border-radius: 60rpx;
  215. border: 1rpx solid #15716E;
  216. box-sizing: border-box;
  217. line-height: 100rpx;
  218. font-size: 32rpx;
  219. }
  220. .btn1{
  221. background-color: #F3F8F8;
  222. color: #15716E;
  223. }
  224. .btn2{
  225. background-color: #15716E;
  226. color: #FFFFFF;
  227. }
  228. }
  229. </style>