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