login.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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="login"></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 loginMpWx from './mixin/login-mp-wx.js'
  79. import loginAppWx from './mixin/login-app-wx.js'
  80. export default{
  81. mixins: [loginMpWx, loginAppWx],
  82. data(){
  83. return {
  84. loginType: 'code', // 登录方式,code 验证码;password 密码
  85. mobile: '',
  86. code: '',
  87. password: '',
  88. agreement: true,
  89. }
  90. },
  91. onLoad() {
  92. },
  93. methods: {
  94. loginSuccessCallBack(data){
  95. this.$util.msg('登录成功');
  96. this.$store.commit('setToken', data);
  97. setTimeout(()=>{
  98. uni.navigateBack();
  99. }, 1000)
  100. },
  101. // 手机号登录
  102. async login(){
  103. // 参数校验
  104. if (!this.agreement){
  105. this.$util.msg('请阅读并同意用户服务及隐私协议');
  106. this.$refs.confirmBtn.stop();
  107. return;
  108. }
  109. const {mobile, code, password} = this;
  110. if (!checkStr(mobile, 'mobile')){
  111. this.$util.msg('请输入正确的手机号码');
  112. this.$refs.confirmBtn.stop();
  113. return;
  114. }
  115. if (!checkStr(code, 'mobileCode')) {
  116. this.$util.msg('验证码错误');
  117. this.$refs.confirmBtn.stop();
  118. return;
  119. }
  120. // 执行登陆
  121. const res = await this.$request('user', 'login', {mobile,code});
  122. this.$refs.confirmBtn.stop();
  123. if (res.status === 1){
  124. this.loginSuccessCallBack(res.data);
  125. } else{
  126. this.$util.msg(res.msg);
  127. }
  128. },
  129. navBack(){
  130. uni.navigateBack();
  131. },
  132. setLoginType(loginType) {
  133. this.loginType = loginType;
  134. },
  135. //同意协议
  136. checkAgreement(){
  137. this.agreement = !this.agreement;
  138. },
  139. //打开协议
  140. navToAgreementDetail(type){
  141. this.navTo('/pages/public/article?param=' + JSON.stringify({
  142. module: 'article',
  143. operation: 'getAgreement',
  144. data: {
  145. type
  146. }
  147. }))
  148. },
  149. }
  150. }
  151. </script>
  152. <style>
  153. page{
  154. background: #fff;
  155. }
  156. </style>
  157. <style scoped lang='scss'>
  158. .app {
  159. padding-top: 15vh;
  160. position:relative;
  161. width: 100vw;
  162. height: 100vh;
  163. overflow: hidden;
  164. background: #fff;
  165. }
  166. .wrapper {
  167. position:relative;
  168. z-index: 90;
  169. padding-bottom: 40rpx;
  170. .welcome {
  171. position:relative;
  172. left: 50rpx;
  173. top: -90rpx;
  174. font-size: 46rpx;
  175. color: #555;
  176. text-shadow: 1px 0px 1px rgba(0,0,0,.3);
  177. }
  178. }
  179. .back-btn {
  180. position:absolute;
  181. left: 20rpx;
  182. top: calc(var(--status-bar-height) + 20rpx);
  183. z-index: 90;
  184. padding: 20rpx;
  185. font-size: 32rpx;
  186. color: #606266;
  187. }
  188. .left-top-sign {
  189. font-size: 120rpx;
  190. color: #f8f8f8;
  191. position:relative;
  192. left: -12rpx;
  193. }
  194. .left-bottom-sign {
  195. position: absolute;
  196. left: -270rpx;
  197. bottom: -320rpx;
  198. border: 100rpx solid #d0d1fd;
  199. border-radius: 50%;
  200. padding: 180rpx;
  201. }
  202. .right-top-sign {
  203. position:absolute;
  204. top: 80rpx;
  205. right: -30rpx;
  206. z-index: 95;
  207. &:before, &:after{
  208. display:block;
  209. content:"";
  210. width: 400rpx;
  211. height: 80rpx;
  212. background: #b4f3e2;
  213. }
  214. &:before{
  215. transform: rotate(50deg);
  216. border-top-right-radius: 50px;
  217. }
  218. &:after{
  219. position: absolute;
  220. right: -198rpx;
  221. top: 0;
  222. transform: rotate(-50deg);
  223. border-top-left-radius: 50px;
  224. }
  225. }
  226. /** 手机登录部分 */
  227. .input-content {
  228. padding: 0 60rpx;
  229. .input-item {
  230. display:flex;
  231. flex-direction: column;
  232. align-items:flex-start;
  233. justify-content: center;
  234. padding: 0 30rpx;
  235. background: #f8f6fc;
  236. height: 120rpx;
  237. border-radius: 4px;
  238. margin-bottom: 50rpx;
  239. &:last-child{
  240. margin-bottom: 0;
  241. }
  242. .row{
  243. width: 100%;
  244. }
  245. .title{
  246. height: 50rpx;
  247. line-height: 56rpx;
  248. font-size: 26rpx;
  249. color: #606266;
  250. }
  251. input {
  252. flex: 1;
  253. height: 60rpx;
  254. font-size: 30rpx;
  255. color: #303133;
  256. width: 100%;
  257. }
  258. }
  259. .login-type {
  260. display: flex;
  261. justify-content: flex-end;
  262. font-size: 13px;
  263. color: #40a2ff;
  264. margin-top: 20rpx;
  265. }
  266. }
  267. /* 其他登录方式 */
  268. .other-wrapper{
  269. display: flex;
  270. flex-direction: column;
  271. align-items: center;
  272. padding-top: 20rpx;
  273. margin-top: 80rpx;
  274. .line{
  275. margin-bottom: 40rpx;
  276. .title {
  277. margin: 0 32rpx;
  278. font-size: 24rpx;
  279. color: #606266;
  280. }
  281. &:before, &:after{
  282. content: '';
  283. width: 160rpx;
  284. height: 0;
  285. border-top: 1px solid #e0e0e0;
  286. }
  287. }
  288. .item{
  289. font-size: 24rpx;
  290. color: #606266;
  291. background-color: #fff;
  292. border: 0;
  293. &:after{
  294. border: 0;
  295. }
  296. }
  297. .icon{
  298. width: 90rpx;
  299. height: 90rpx;
  300. margin: 0 24rpx 16rpx;
  301. }
  302. }
  303. .agreement{
  304. position: absolute;
  305. left: 0;
  306. bottom: 6vh;
  307. z-index: 1;
  308. width: 750rpx;
  309. height: 90rpx;
  310. font-size: 24rpx;
  311. color: #999;
  312. .mix-icon{
  313. font-size: 36rpx;
  314. color: #ccc;
  315. margin-right: 8rpx;
  316. margin-top: 1px;
  317. &.active{
  318. color: $base-color;
  319. }
  320. }
  321. .title {
  322. color: #40a2ff;
  323. }
  324. }
  325. </style>