index.vue 8.3 KB

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