index.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  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: false,
  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. // uni.reLaunch({
  177. // url: '/packageOther/avatar/index'
  178. // })
  179. }, 500)
  180. },
  181. changeChecked(e) {
  182. this.checked = e
  183. },
  184. toCode() {
  185. if (!this.checked) {
  186. uni.$u.toast('请阅读并勾选底部协议');
  187. return
  188. }
  189. uni.navigateTo({
  190. url: '/pages/login/code'
  191. })
  192. },
  193. getBaseInfo() {
  194. $http.post('/api/v1/mp/user/getLoginUserinfo', { appSource: appId }).then(res => {
  195. uni.hideLoading();
  196. if (res.code == 0) {
  197. uni.setStorageSync('userInfo', res.data)
  198. if (res.data.openId) {
  199. uni.$u.toast('登录成功');
  200. setTimeout(() => {
  201. uni.navigateBack({
  202. delta: 1
  203. })
  204. }, 500)
  205. } else {
  206. this.authShow = true
  207. }
  208. }
  209. }).catch(() => {
  210. uni.hideLoading();
  211. })
  212. },
  213. getBaseInfoAli() {
  214. $http.post('/api/v1/mp/user/getLoginUserinfo', { appSource: appId }).then(res => {
  215. uni.hideLoading();
  216. if (res.code == 0) {
  217. uni.setStorageSync('userInfo', res.data)
  218. if (res.data.aliuserId) {
  219. uni.$u.toast('登录成功');
  220. setTimeout(() => {
  221. uni.navigateBack({
  222. delta: 1
  223. })
  224. }, 500)
  225. } else {
  226. this.authShow = true
  227. }
  228. }
  229. }).catch(() => {
  230. uni.hideLoading();
  231. })
  232. },
  233. onGetAuthorize(e) {
  234. let _this = this
  235. if (!_this.checked) {
  236. uni.$u.toast('请阅读并勾选底部协议');
  237. return
  238. }
  239. my.getPhoneNumber({
  240. success: (res) => {
  241. uni.showLoading({
  242. title: '登录中'
  243. });
  244. $http.post('/api/v1/mp/user/aliAuth/mobile', {
  245. encryptedData: res.response,
  246. identity: 1,
  247. noToken: true
  248. }).then(res => {
  249. if (res.code == 0) {
  250. uni.setStorageSync('token', res.token)
  251. _this.getBaseInfoAli()
  252. } else {
  253. uni.hideLoading();
  254. }
  255. })
  256. },
  257. })
  258. },
  259. }
  260. }
  261. </script>
  262. <style lang="scss" scoped>
  263. .container {
  264. height: 100vh;
  265. width: 100%;
  266. }
  267. .login {
  268. flex-direction: column;
  269. &-image {
  270. flex-direction: column;
  271. padding: 128rpx 0 200rpx;
  272. image {
  273. width: 296rpx;
  274. height: 296rpx;
  275. margin-bottom: 28rpx;
  276. }
  277. &-txt {
  278. text-align: center;
  279. line-height: 40rpx;
  280. font-weight: bold;
  281. margin-bottom: 20rpx;
  282. font-size: 28rpx;
  283. }
  284. }
  285. &-txt {
  286. text-align: center;
  287. line-height: 40rpx;
  288. font-weight: bold;
  289. margin-bottom: 20rpx;
  290. }
  291. &-title {
  292. text-align: center;
  293. font-size: 24rpx;
  294. font-weight: normal;
  295. margin-bottom: 50rpx;
  296. }
  297. &-btn {
  298. margin-bottom: 44rpx;
  299. button {
  300. width: 600rpx;
  301. height: 80rpx;
  302. line-height: 80rpx;
  303. border-radius: 40rpx;
  304. background-color: rgba(235, 112, 9, 100);
  305. color: rgba(255, 255, 255, 100);
  306. text-align: center;
  307. font-size: 28rpx;
  308. }
  309. }
  310. &-code {
  311. text-align: center;
  312. color: rgba(242, 113, 32, 100);
  313. }
  314. }
  315. .footer-fixed {
  316. position: fixed;
  317. bottom: var(--window-bottom);
  318. left: 0;
  319. right: 0;
  320. z-index: 11;
  321. background: #fff;
  322. // 设置ios刘海屏底部横线安全区域
  323. padding-bottom: constant(safe-area-inset-bottom);
  324. padding-bottom: env(safe-area-inset-bottom);
  325. .about {
  326. padding: 60rpx 0;
  327. font-size: 24rpx;
  328. .txt-about {
  329. color: #007aff;
  330. }
  331. }
  332. }
  333. </style>