index.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. <template>
  2. <view class="container">
  3. <!-- #ifdef MP-ALIPAY -->
  4. <u-navbar :placeholder="true" bgColor="#fff" :autoBack="true" title="登录" leftIconSize="0"></u-navbar>
  5. <!-- #endif -->
  6. <!-- #ifndef MP-ALIPAY -->
  7. <u-navbar :placeholder="true" bgColor="#fff" :autoBack="true" title="登录"></u-navbar>
  8. <!-- #endif -->
  9. <view class="flex login">
  10. <view class="flex login-image">
  11. <image src="../../static/public/logo.png" mode="scaleToFill"></image>
  12. <view class="login-image-txt">盲票</view>
  13. </view>
  14. <!-- #ifdef MP-ALIPAY -->
  15. <view class="login-btn">
  16. <button open-type="getAuthorize" @getAuthorize="onGetAuthorize" @error="onAuthError" scope='phoneNumber'>支付宝登录</button>
  17. </view>
  18. <!-- #endif -->
  19. <!-- #ifndef MP-ALIPAY -->
  20. <view class="login-btn">
  21. <button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber" v-if="checked">微信登录</button>
  22. <button @click="getPhoneNumber" v-else>微信登录</button>
  23. </view>
  24. <!-- #endif -->
  25. <view class="flex login-code" @click="toCode">手机号登录/注册</view>
  26. </view>
  27. <view class="footer-fixed">
  28. <view class="flex about">
  29. <view class="checked">
  30. <u-checkbox-group>
  31. <u-checkbox :value="checked" :checked="checked" size="20" shape="circle" activeColor="#E96737"
  32. @change="changeChecked"></u-checkbox>
  33. </u-checkbox-group>
  34. </view>
  35. <view class="txt">登录代表您已同意</view>
  36. <navigator hover-class="none" class="txt-about" url="/packageOther/about/protect">《用户使用协议》</navigator>
  37. <navigator hover-class="none" class="txt-about" url="/packageOther/about/conceal">、《隐私保护声明》</navigator>
  38. </view>
  39. </view>
  40. <auth :auth-show="authShow" :auth-token="token" @close="authClose" />
  41. </view>
  42. </template>
  43. <script>
  44. import $http from '@/utils/request.js'
  45. import log from '@/common/log.js'
  46. import Auth from '../../components/auth/auth.vue'
  47. export default {
  48. components: {
  49. Auth
  50. },
  51. data() {
  52. return {
  53. authShow: false,
  54. token: '',
  55. checked: true,
  56. };
  57. },
  58. methods: {
  59. getPhoneNumber(e) {
  60. let _this = this
  61. if (!_this.checked) {
  62. uni.$u.toast('请阅读并勾选底部协议');
  63. return
  64. }
  65. if (e.detail.errMsg == 'getPhoneNumber:ok') {
  66. uni.showLoading({
  67. title: '登录中'
  68. });
  69. if (e.detail & e.detail.code) {
  70. $http.post('/api/v1/mp/user/wxauth/mobile', {
  71. ...e.detail,
  72. identity: 1,
  73. noToken: true
  74. }).then(res => {
  75. uni.hideLoading();
  76. if (res.code == 0) {
  77. uni.setStorageSync('token', res.token)
  78. _this.getBaseInfo()
  79. } else {
  80. uni.getSystemInfo({
  81. success(res) {
  82. log.info(
  83. `错误信息:===基础库:${ res.SDKVersion },设备:${ res.model }-${ res.system }.===`
  84. )
  85. }
  86. })
  87. }
  88. }).catch(() => {
  89. uni.hideLoading();
  90. uni.getSystemInfo({
  91. success(res) {
  92. log.info(
  93. `错误信息:===基础库:${ res.SDKVersion },设备:${ res.model }-${ res.system }.===`
  94. )
  95. }
  96. })
  97. })
  98. } else {
  99. uni.login({
  100. success(res) {
  101. $http.post('/api/v1/mp/user/wxauth/mobile', {
  102. ...e.detail,
  103. loginCode: res.code,
  104. identity: 1,
  105. noToken: true
  106. }).then(res => {
  107. uni.hideLoading();
  108. if (res.code == 0) {
  109. uni.setStorageSync('token', res.token)
  110. _this.getBaseInfo()
  111. } else {
  112. uni.getSystemInfo({
  113. success(res) {
  114. log.info(
  115. `错误信息:===基础库:${ res.SDKVersion },设备:${ res.model }-${ res.system }.===`
  116. )
  117. }
  118. })
  119. }
  120. }).catch(() => {
  121. uni.hideLoading();
  122. uni.getSystemInfo({
  123. success(res) {
  124. log.info(
  125. `错误信息:===基础库:${ res.SDKVersion },设备:${ res.model }-${ res.system }.===`
  126. )
  127. }
  128. })
  129. })
  130. }
  131. })
  132. }
  133. }
  134. },
  135. // 关闭授权
  136. authClose() {
  137. this.authShow = false
  138. setTimeout(() => {
  139. uni.navigateBack({
  140. delta: 1
  141. })
  142. }, 500)
  143. },
  144. changeChecked(e) {
  145. this.checked = e
  146. },
  147. toCode() {
  148. if (!this.checked) {
  149. uni.$u.toast('请阅读并勾选底部协议');
  150. return
  151. }
  152. uni.navigateTo({
  153. url: '/pages/login/code'
  154. })
  155. },
  156. getBaseInfo() {
  157. $http.post('/api/v1/mp/user/getLoginUserinfo', {}).then(res => {
  158. uni.hideLoading();
  159. if (res.code == 0) {
  160. uni.setStorageSync('userInfo', res.data)
  161. if (res.data.openId) {
  162. uni.$u.toast('登录成功');
  163. setTimeout(() => {
  164. uni.navigateBack({
  165. delta: 1
  166. })
  167. }, 500)
  168. } else {
  169. this.authShow = true
  170. }
  171. }
  172. }).catch(() => {
  173. uni.hideLoading();
  174. })
  175. },
  176. getBaseInfoAli(){
  177. $http.post('/api/v1/mp/user/getLoginUserinfo', {}).then(res => {
  178. uni.hideLoading();
  179. if (res.code == 0) {
  180. uni.setStorageSync('userInfo', res.data)
  181. if (res.data.aliuserId) {
  182. uni.$u.toast('登录成功');
  183. setTimeout(() => {
  184. uni.navigateBack({
  185. delta: 1
  186. })
  187. }, 500)
  188. } else {
  189. this.authShow = true
  190. }
  191. }
  192. }).catch(() => {
  193. uni.hideLoading();
  194. })
  195. },
  196. onGetAuthorize(e){
  197. let _this = this
  198. if (!_this.checked) {
  199. uni.$u.toast('请阅读并勾选底部协议');
  200. return
  201. }
  202. my.getPhoneNumber({
  203. success: (res) => {
  204. uni.showLoading({
  205. title: '登录中'
  206. });
  207. $http.post('/api/v1/mp/user/aliAuth/mobile', {
  208. encryptedData: res.response,
  209. identity: 1,
  210. noToken: true
  211. }).then(res=>{
  212. if(res.code == 0){
  213. uni.setStorageSync('token', res.token)
  214. _this.getBaseInfoAli()
  215. }else{
  216. uni.hideLoading();
  217. }
  218. })
  219. },
  220. })
  221. },
  222. }
  223. }
  224. </script>
  225. <style lang="scss" scoped>
  226. .container {
  227. height: 100vh;
  228. width: 100%;
  229. }
  230. .login {
  231. flex-direction: column;
  232. &-image {
  233. flex-direction: column;
  234. padding: 128rpx 0 200rpx;
  235. image {
  236. width: 296rpx;
  237. height: 296rpx;
  238. margin-bottom: 28rpx;
  239. }
  240. &-txt {
  241. text-align: center;
  242. line-height: 40rpx;
  243. font-weight: bold;
  244. margin-bottom: 20rpx;
  245. font-size: 28rpx;
  246. }
  247. }
  248. &-txt {
  249. text-align: center;
  250. line-height: 40rpx;
  251. font-weight: bold;
  252. margin-bottom: 20rpx;
  253. }
  254. &-title {
  255. text-align: center;
  256. font-size: 24rpx;
  257. font-weight: normal;
  258. margin-bottom: 50rpx;
  259. }
  260. &-btn {
  261. margin-bottom: 44rpx;
  262. button {
  263. width: 600rpx;
  264. height: 80rpx;
  265. line-height: 80rpx;
  266. border-radius: 40rpx;
  267. background-color: rgba(235, 112, 9, 100);
  268. color: rgba(255, 255, 255, 100);
  269. text-align: center;
  270. font-size: 28rpx;
  271. }
  272. }
  273. &-code {
  274. text-align: center;
  275. color: rgba(242, 113, 32, 100);
  276. }
  277. }
  278. .footer-fixed {
  279. position: fixed;
  280. bottom: var(--window-bottom);
  281. left: 0;
  282. right: 0;
  283. z-index: 11;
  284. background: #fff;
  285. // 设置ios刘海屏底部横线安全区域
  286. padding-bottom: constant(safe-area-inset-bottom);
  287. padding-bottom: env(safe-area-inset-bottom);
  288. .about {
  289. padding: 60rpx 0;
  290. font-size: 24rpx;
  291. .txt-about {
  292. color: #007aff;
  293. }
  294. }
  295. }
  296. </style>