多租户商城-商户小程序端
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.

341 lines
8.0 KiB

2 years ago
2 years ago
2 years ago
  1. <template>
  2. <view class="container flex-items-plus flex-column">
  3. <global-loading />
  4. <view class="login-logoBox">
  5. <image class="login-logo" src="https://wechat.hnthee.com/ceres-local-file/image/logo_wechat.png"></image>
  6. </view>
  7. <view class="loginTitle-text flex-column-plus flex-items font-color-666 fs26">
  8. <text>为了给您提供更好的服务</text>
  9. <text>我们需要您的授权哦~</text>
  10. </view>
  11. <view>
  12. <!-- #ifdef MP-WEIXIN -->
  13. <button class="loginWxBut fs28" @click="GetUserInfo">微信登录</button>
  14. <button class="goToHome fs28" @click="goToHome">去首页逛逛</button>
  15. <!-- #endif -->
  16. <!-- #ifdef MP-ALIPAY -->
  17. <button class="loginWxBut fs28" @click="GetAliPayUserInfo">支付宝登录</button>
  18. <!-- #endif -->
  19. <!-- #ifndef MP-ALIPAY -->
  20. <view class="loginBut" v-if="noMp" @click="goLogin">手机号登录</view>
  21. <!-- #endif -->
  22. </view>
  23. <view class="flex-row-plus mar-top-30" v-if="noMp">
  24. <text class="font-color-C5AA7B">还没有账号</text>
  25. <view class="register-text" @click="goRegister">去注册</view>
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. const NET = require('../../utils/request')
  31. const API = require('../../config/api')
  32. export default {
  33. data() {
  34. return {
  35. WXloginQuery: {
  36. "code": "",
  37. "salesId": 0,
  38. "headImage": '',
  39. "terminal":1
  40. },
  41. noMp: false,
  42. // beforePage: undefined,
  43. // doubleBeforePage: undefined
  44. }
  45. },
  46. onLoad(options) {
  47. // #ifndef MP
  48. this.noMp = true
  49. // #endif
  50. const pages = getCurrentPages()
  51. uni.setStorageSync('last_page', pages[pages.length - 2].route);
  52. if (pages[pages.length - 2].options) {
  53. uni.setStorageSync('last_page_options', pages[pages.length - 2].options);
  54. }
  55. },
  56. onShow() {
  57. // 所有需要授权页面进登录页面取消loading
  58. uni.hideLoading()
  59. },
  60. onBackPress() {
  61. uni.switchTab({
  62. url: '../../pages/tabbar/index/index'
  63. })
  64. return true;
  65. },
  66. methods: {
  67. back() {
  68. uni.switchTab({
  69. url: '../../pages/tabbar/index/index'
  70. });
  71. },
  72. goLogin() {
  73. uni.navigateTo({
  74. url: 'accountLogin'
  75. })
  76. },
  77. goRegister() {
  78. uni.navigateTo({
  79. url: 'register'
  80. })
  81. },
  82. // 微信登录
  83. GetUserInfo() {
  84. // uni.showLoading({
  85. // title: '正在加载...',
  86. // mask: true
  87. // });
  88. const that = this
  89. // // #ifdef APP-PLUS
  90. // uni.login({
  91. // provider: 'weixin',
  92. // success: function(loginRes) {
  93. // // 获取用户信息
  94. // uni.getUserInfo({
  95. // provider: 'weixin',
  96. // success: function(infoRes) {
  97. // let wechatOpenId = infoRes.userInfo.openId
  98. // let avatarUrl = infoRes.userInfo.avatarUrl
  99. // NET.request(API.WxAppLogin, {
  100. // 'wechatOpenId': wechatOpenId
  101. // }, 'POST').then(res => {
  102. // let data = {
  103. // wechatOpenId: wechatOpenId,
  104. // headImage: avatarUrl
  105. // }
  106. // that.loginSuc(res.data, data)
  107. // }).catch(res => {
  108. // console.log('WxAppLogin failed: ', res)
  109. // })
  110. // },
  111. // fail: () => {
  112. // uni.showToast({
  113. // title: "微信登录授权失败",
  114. // icon: "none"
  115. // });
  116. // }
  117. // });
  118. // }
  119. // });
  120. // // #endif
  121. // #ifdef MP-WEIXIN
  122. uni.login({
  123. provider: 'weixin',
  124. success: (res2) => {
  125. uni.hideLoading()
  126. that.WXloginQuery.code = res2.code
  127. },
  128. fail: () => {
  129. uni.showToast({
  130. title: "微信登录授权失败",
  131. icon: "none"
  132. });
  133. }
  134. })
  135. uni.getUserProfile({
  136. desc: '正在获取', //不写不弹提示框
  137. success: function(res) {
  138. that.WXloginQuery.headImage = res.userInfo.avatarUrl
  139. NET.request(API.WxLogin, that.WXloginQuery, 'POST').then(res => {
  140. let data = {
  141. wechatOpenId: res.data.wechatOpenId,
  142. headImage: res.data.headImage
  143. }
  144. that.loginSuc(res.data, data)
  145. }).catch(err => {
  146. })
  147. },
  148. fail: function(err) {
  149. uni.showToast({
  150. title: "微信登录授权失败",
  151. icon: "none"
  152. });
  153. },
  154. });
  155. /* uni.getUserInfo({
  156. provider: 'weixin',
  157. success: function(infoRes) {
  158. },
  159. fail: () => {
  160. uni.showToast({
  161. title: "微信登录授权失败",
  162. icon: "none"
  163. });
  164. }
  165. }); */
  166. /* uni.getUserProfile({
  167. desc: '正在获取', //不写不弹提示框
  168. success: function(res) {
  169. console.dir(res)
  170. that.WXloginQuery.headImg = res.userInfo.avatarUrl
  171. // that.loginSuc({'ifFirst': 1}, {'headImg': res.userInfo.avatarUrl})
  172. },
  173. fail: function(err) {
  174. uni.showToast({
  175. title: "微信登录授权失败",
  176. icon: "none"
  177. });
  178. }
  179. }) */
  180. // #endif
  181. },
  182. GetAliPayUserInfo() {
  183. const that = this
  184. uni.login({
  185. provider: 'alipay',
  186. scopes: 'auth_user',
  187. success: function(loginRes) {
  188. that.alipayLogin(loginRes.authCode)
  189. }
  190. });
  191. },
  192. alipayLogin(authCode) {
  193. NET.request(API.AlipayLogin, {
  194. 'code': authCode
  195. }, 'POST').then(res => {
  196. this.loginSuc(res.data, {
  197. 'buyerUserId': res.data.buyerUserId
  198. })
  199. }).catch(err => {
  200. })
  201. },
  202. goToHome() {
  203. uni.switchTab({
  204. url: '/pages/tabbar/index/index'
  205. });
  206. },
  207. loginSuc(buyerUser, data) {
  208. if (buyerUser.ifFirst == 0) {
  209. uni.setStorageSync('storage_key', buyerUser);
  210. this.bindSalesCustomer()
  211. /* uni.switchTab({
  212. url: '/pages/tabbar/user/index',
  213. success() {
  214. uni.hideLoading()
  215. }
  216. }) */
  217. const last_page = uni.getStorageSync('last_page') || ''
  218. if (last_page) {
  219. const last_page_options = uni.getStorageSync('last_page_options') || ''
  220. const str = JSON.stringify(last_page_options).replaceAll('{', '').replaceAll('}', '').replaceAll(
  221. '"', '').replaceAll(':', '=').replaceAll(',', '&')
  222. // 保留其他路由,需跳转2下 到最后登录页面
  223. // uni.navigateBack({
  224. // delta: 1
  225. // })
  226. // uni.redirectTo({
  227. // url: `/${last_page}?${str}`,
  228. // // url: `/${last_page}?` + str
  229. // })
  230. // 清空其他路由,直接跳转最后登录页面
  231. uni.reLaunch({
  232. url: `/${last_page}?${str}`,
  233. // url: `/${last_page}?` + str
  234. })
  235. return
  236. } else {
  237. // #ifdef MP-ALIPAY
  238. uni.navigateTo({
  239. url: '/pages/tabbar/user/index'
  240. })
  241. // #endif
  242. // #ifndef MP-ALIPAY
  243. uni.switchTab({
  244. url: '/pages/tabbar/user/index'
  245. })
  246. // #endif
  247. }
  248. } else { // 第一次登录,绑定手机号
  249. uni.redirectTo({
  250. url: 'bindPhone?data=' + JSON.stringify(data)
  251. })
  252. }
  253. },
  254. bindSalesCustomer() {
  255. const shopId = uni.getStorageSync('shopId')
  256. const salesId = uni.getStorageSync('salesId')
  257. if (shopId && salesId && shopId !== '' && salesId !== '') {
  258. // 多次调用绑定方法,不提示任何信息即可
  259. NET.request(API.BindSalesCustomer, {
  260. shopId: shopId,
  261. distributorId: salesId
  262. }, 'POST').then(res => {
  263. uni.removeStorageSync('salesId');
  264. uni.removeStorageSync('shopId');
  265. }).catch(err => {
  266. console.dir(err)
  267. })
  268. }
  269. }
  270. }
  271. }
  272. </script>
  273. <style lang="scss">
  274. .container {
  275. background-color: #FFFFFF;
  276. height: 100vh;
  277. .login-logoBox {
  278. margin-top: -200rpx;
  279. .login-logo {
  280. width: 518rpx;
  281. height: 100rpx;
  282. }
  283. }
  284. .loginTitle-text {
  285. margin-top: 100rpx;
  286. }
  287. .goToHome {
  288. background: none;
  289. border: none;
  290. width: auto;
  291. margin-top: 50rpx;
  292. color: #999999;
  293. text-decoration: underline;
  294. &:after {
  295. display: none;
  296. }
  297. }
  298. .loginWxBut {
  299. background: #333333;
  300. color: #FFEBC4;
  301. height: 88rpx;
  302. width: 600rpx;
  303. text-align: center;
  304. line-height: 88rpx;
  305. margin-top: 49rpx;
  306. }
  307. .loginBut {
  308. background-color: #333333;
  309. color: #FFEBC4;
  310. height: 88rpx;
  311. width: 600rpx;
  312. text-align: center;
  313. line-height: 88rpx;
  314. margin-top: 30rpx;
  315. }
  316. .register-text {
  317. color: #C5AA7B;
  318. }
  319. }
  320. </style>
  321. <style scoped>
  322. .loginWxBut::after {
  323. border-radius: 0 !important;
  324. }
  325. </style>