index.vue 7.2 KB

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