index.vue 7.5 KB

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