login.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. <template>
  2. <view class="app">
  3. <!-- 左下角的环 -->
  4. <view class="left-bottom-sign"></view>
  5. <!-- 右上角的折角 -->
  6. <view class="right-top-sign"></view>
  7. <!-- 左上角的 x 关闭 -->
  8. <view class="back-btn mix-icon icon-guanbi" @click="navBack"></view>
  9. <!-- 用户协议 -->
  10. <view class="agreement center">
  11. <text class="mix-icon icon-xuanzhong" :class="{active: agreement}" @click="checkAgreement"></text>
  12. <text @click="checkAgreement">请认真阅读并同意</text>
  13. <text class="title" @click="navToAgreementDetail(1)">《用户服务协议》</text>
  14. <text class="title" @click="navToAgreementDetail(2)">《隐私权政策》</text>
  15. </view>
  16. <!-- 登录表单 -->
  17. <view class="wrapper">
  18. <view class="left-top-sign">LOGIN</view>
  19. <view class="welcome">手机登录/注册</view>
  20. <!-- 手机验证码登录 -->
  21. <view class="input-content">
  22. <view class="input-item">
  23. <text class="title">手机号码</text>
  24. <view class="row">
  25. <input v-model="mobile" type="number" maxlength="11"
  26. placeholder="请输入手机号码" placeholder-style="color: #909399"/>
  27. </view>
  28. </view>
  29. <!-- 判断使用验证码还是密码 -->
  30. <view class="input-item" v-if="loginType == 'code'">
  31. <text class="title">验证码</text>
  32. <view class="row">
  33. <input v-model="code" type="number" maxlength="6"
  34. placeholder="请输入手机验证码" placeholder-style="color: #909399">
  35. <mix-code :mobile="mobile" templateCode="SMS_194050994"></mix-code>
  36. </view>
  37. </view>
  38. <view class="input-item" v-else>
  39. <text class="title">密码</text>
  40. <view class="row">
  41. <input v-model="password" type="password" maxlength="16"
  42. placeholder="请输入密码" placeholder-style="color: #909399"/>
  43. </view>
  44. </view>
  45. <mix-button ref="confirmBtn" text="立即登录" marginTop="60rpx" @onConfirm="mobileLogin"></mix-button>
  46. <!-- 切换登陆 -->
  47. <view class="login-type" v-if="loginType == 'code'" @click="setLoginType('password')">账号密码登录</view>
  48. <view class="login-type" v-else @click="setLoginType('code')">免密登录</view>
  49. </view>
  50. <!-- 快捷登录 -->
  51. <!-- #ifdef APP-PLUS || MP-WEIXIN -->
  52. <view class="other-wrapper">
  53. <view class="line center">
  54. <text class="title">快捷登录</text>
  55. </view>
  56. <view class="list row">
  57. <!-- #ifdef MP-WEIXIN -->
  58. <view class="item column center" @click="mpWxGetUserInfo">
  59. <image class="icon" src="/static/icon/login-wx.png"></image>
  60. </view>
  61. <!-- #endif -->
  62. <!-- #ifdef APP-PLUS -->
  63. <view class="item column center" style="width: 180rpx;" @click="loginByWxApp">
  64. <image class="icon" src="/static/icon/login-wx.png"></image>
  65. <text>微信登录</text>
  66. </view>
  67. <!-- #endif -->
  68. </view>
  69. </view>
  70. <!-- #endif -->
  71. </view>
  72. <!-- Loading 框 -->
  73. <mix-loading v-if="isLoading"></mix-loading>
  74. </view>
  75. </template>
  76. <script>
  77. import { checkStr } from '@/common/js/util'
  78. import { login, smsLogin } from '@/api/system/auth.js'
  79. import loginMpWx from './mixin/login-mp-wx.js'
  80. import loginAppWx from './mixin/login-app-wx.js'
  81. export default{
  82. mixins: [loginMpWx, loginAppWx],
  83. data(){
  84. return {
  85. loginType: 'code', // 登录方式,code 验证码;password 密码
  86. mobile: '',
  87. code: '',
  88. password: '',
  89. agreement: true,
  90. }
  91. },
  92. onLoad() {
  93. },
  94. methods: {
  95. // 手机号登录
  96. async mobileLogin() {
  97. // 参数校验 TODO 芋艿:表单校验的支持
  98. if (!this.agreement) {
  99. this.$util.msg('请阅读并同意用户服务及隐私协议');
  100. this.$refs.confirmBtn.stop();
  101. return;
  102. }
  103. const {mobile, code, password} = this;
  104. if (!checkStr(mobile, 'mobile')){
  105. this.$util.msg('请输入正确的手机号码');
  106. this.$refs.confirmBtn.stop();
  107. return;
  108. }
  109. if (this.loginType === 'code' && !checkStr(code, 'mobileCode')) {
  110. this.$util.msg('验证码格式错误');
  111. this.$refs.confirmBtn.stop();
  112. return;
  113. }
  114. if (this.loginType === 'password' && !checkStr(password, 'pwd')) {
  115. this.$util.msg('密码格式错误');
  116. this.$refs.confirmBtn.stop();
  117. return;
  118. }
  119. // 执行登陆
  120. try {
  121. const data = this.loginType === 'code' ? await smsLogin(mobile, code)
  122. : await login(mobile, password);
  123. // 登陆成功
  124. this.loginSuccessCallBack(data);
  125. } finally {
  126. this.$refs.confirmBtn.stop();
  127. }
  128. },
  129. // 登陆成功的处理逻辑
  130. loginSuccessCallBack(data){
  131. this.$util.msg('登录成功');
  132. this.$store.commit('setToken', data);
  133. // TODO 芋艿:如果当前页是第一页,则无法返回。期望是能够回到首页
  134. setTimeout(()=>{
  135. uni.navigateBack();
  136. }, 1000)
  137. },
  138. navBack() {
  139. uni.navigateBack();
  140. },
  141. setLoginType(loginType) {
  142. this.loginType = loginType;
  143. },
  144. //同意协议
  145. checkAgreement(){
  146. this.agreement = !this.agreement;
  147. },
  148. //打开协议
  149. navToAgreementDetail(type){
  150. this.navTo('/pages/public/article?param=' + JSON.stringify({
  151. module: 'article',
  152. operation: 'getAgreement',
  153. data: {
  154. type
  155. }
  156. }))
  157. },
  158. }
  159. }
  160. </script>
  161. <style>
  162. page{
  163. background: #fff;
  164. }
  165. </style>
  166. <style scoped lang='scss'>
  167. .app {
  168. padding-top: 15vh;
  169. position:relative;
  170. width: 100vw;
  171. height: 100vh;
  172. overflow: hidden;
  173. background: #fff;
  174. }
  175. .wrapper {
  176. position:relative;
  177. z-index: 90;
  178. padding-bottom: 40rpx;
  179. .welcome {
  180. position:relative;
  181. left: 50rpx;
  182. top: -90rpx;
  183. font-size: 46rpx;
  184. color: #555;
  185. text-shadow: 1px 0px 1px rgba(0,0,0,.3);
  186. }
  187. }
  188. .back-btn {
  189. position:absolute;
  190. left: 20rpx;
  191. top: calc(var(--status-bar-height) + 20rpx);
  192. z-index: 90;
  193. padding: 20rpx;
  194. font-size: 32rpx;
  195. color: #606266;
  196. }
  197. .left-top-sign {
  198. font-size: 120rpx;
  199. color: #f8f8f8;
  200. position:relative;
  201. left: -12rpx;
  202. }
  203. .left-bottom-sign {
  204. position: absolute;
  205. left: -270rpx;
  206. bottom: -320rpx;
  207. border: 100rpx solid #d0d1fd;
  208. border-radius: 50%;
  209. padding: 180rpx;
  210. }
  211. .right-top-sign {
  212. position:absolute;
  213. top: 80rpx;
  214. right: -30rpx;
  215. z-index: 95;
  216. &:before, &:after{
  217. display:block;
  218. content:"";
  219. width: 400rpx;
  220. height: 80rpx;
  221. background: #b4f3e2;
  222. }
  223. &:before{
  224. transform: rotate(50deg);
  225. border-top-right-radius: 50px;
  226. }
  227. &:after{
  228. position: absolute;
  229. right: -198rpx;
  230. top: 0;
  231. transform: rotate(-50deg);
  232. border-top-left-radius: 50px;
  233. }
  234. }
  235. /** 手机登录部分 */
  236. .input-content {
  237. padding: 0 60rpx;
  238. .input-item {
  239. display:flex;
  240. flex-direction: column;
  241. align-items:flex-start;
  242. justify-content: center;
  243. padding: 0 30rpx;
  244. background: #f8f6fc;
  245. height: 120rpx;
  246. border-radius: 4px;
  247. margin-bottom: 50rpx;
  248. &:last-child{
  249. margin-bottom: 0;
  250. }
  251. .row{
  252. width: 100%;
  253. }
  254. .title{
  255. height: 50rpx;
  256. line-height: 56rpx;
  257. font-size: 26rpx;
  258. color: #606266;
  259. }
  260. input {
  261. flex: 1;
  262. height: 60rpx;
  263. font-size: 30rpx;
  264. color: #303133;
  265. width: 100%;
  266. }
  267. }
  268. .login-type {
  269. display: flex;
  270. justify-content: flex-end;
  271. font-size: 13px;
  272. color: #40a2ff;
  273. margin-top: 20rpx;
  274. }
  275. }
  276. /* 其他登录方式 */
  277. .other-wrapper{
  278. display: flex;
  279. flex-direction: column;
  280. align-items: center;
  281. padding-top: 20rpx;
  282. margin-top: 80rpx;
  283. .line{
  284. margin-bottom: 40rpx;
  285. .title {
  286. margin: 0 32rpx;
  287. font-size: 24rpx;
  288. color: #606266;
  289. }
  290. &:before, &:after{
  291. content: '';
  292. width: 160rpx;
  293. height: 0;
  294. border-top: 1px solid #e0e0e0;
  295. }
  296. }
  297. .item{
  298. font-size: 24rpx;
  299. color: #606266;
  300. background-color: #fff;
  301. border: 0;
  302. &:after{
  303. border: 0;
  304. }
  305. }
  306. .icon{
  307. width: 90rpx;
  308. height: 90rpx;
  309. margin: 0 24rpx 16rpx;
  310. }
  311. }
  312. .agreement{
  313. position: absolute;
  314. left: 0;
  315. bottom: 6vh;
  316. z-index: 1;
  317. width: 750rpx;
  318. height: 90rpx;
  319. font-size: 24rpx;
  320. color: #999;
  321. .mix-icon{
  322. font-size: 36rpx;
  323. color: #ccc;
  324. margin-right: 8rpx;
  325. margin-top: 1px;
  326. &.active{
  327. color: $base-color;
  328. }
  329. }
  330. .title {
  331. color: #40a2ff;
  332. }
  333. }
  334. </style>