login.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <template>
  2. <view class="zai-box">
  3. <scroll-view scroll-y class="page">
  4. <view class="text-center" :style="[{animation: 'show ' + 0.4+ 's 1'}]">
  5. <image src="/static/desk-img/144.png" mode='aspectFit' class="zai-logo "></image>
  6. <view class="zai-title text-shadow ">登 录</view>
  7. </view>
  8. <view class="text-center" :style="[{animation: 'show ' + 0.4+ 's 1'}]">
  9. <view class="zai-title text-shadow ">L O G O</view>
  10. </view>
  11. <view class="box padding-lr-xl login-paddingtop" :style="[{animation: 'show ' + 0.6+ 's 1'}]">
  12. <block>
  13. <view class="cu-form-group margin-top shadow-warp" :class="[shape=='round'?'round':'']">
  14. <view class="title"><text class="cuIcon-people margin-right-xs"></text>账号:</view>
  15. <input placeholder="请输入账号" name="input" v-model="userName"></input>
  16. </view>
  17. <view class="cu-form-group margin-top shadow-warp" :class="[shape=='round'?'round':'']">
  18. <view class="title"><text class="cuIcon-lock margin-right-xs"></text>密码:</view>
  19. <input class="uni-input" placeholder="请输入密码" :password="!showPassword" v-model="password" />
  20. <view class="action text-lg">
  21. <text :class="[showPassword ? 'cuIcon-attention' : 'cuIcon-attentionforbid']" @click="changePassword"></text>
  22. </view>
  23. </view>
  24. <view class="padding text-center margin-top">
  25. <button class="cu-btn bg-blue lg margin-right shadow" :loading="loading" :class="[shape=='round'?'round':'']"
  26. @tap="onLogin"><text space="emsp">{{loading ? "登录中...":" 登录 "}}</text>
  27. </button>
  28. </view>
  29. </block>
  30. <!-- #ifdef APP-PLUS -->
  31. <view class="padding flex flex-direction text-center">
  32. 当前版本:{{version}}
  33. </view>
  34. <!-- #endif -->
  35. </view>
  36. </scroll-view>
  37. <!-- 登录加载弹窗 -->
  38. <view class="cu-load load-modal" v-if="loading">
  39. <!-- <view class="cuIcon-emojifill text-orange"></view> -->
  40. <image src="/static/desk-img/144.png" mode="aspectFit" class="round"></image>
  41. <view class="gray-text">登录中...</view>
  42. </view>
  43. </view>
  44. </template>
  45. <script>
  46. import { ACCESS_TOKEN,USER_NAME,USER_INFO } from "@/common/util/constants"
  47. import { mapActions } from "vuex"
  48. import configService from '@/common/service/config.service.js';
  49. export default {
  50. data() {
  51. return {
  52. shape:'',//round 圆形
  53. loading: false,
  54. userName: 'admin',
  55. password: 'admin123admin',
  56. phoneNo: '',
  57. smsCode: '',
  58. showPassword: false, //是否显示明文
  59. smsCountDown: 0,
  60. smsCountInterval: null,
  61. toggleDelay: false,
  62. version:'',
  63. //第三方登录相关信息
  64. thirdType:"",
  65. thirdLoginInfo:"",
  66. thirdLoginState:false,
  67. bindingPhoneModal:false,
  68. thirdUserUuid:'',
  69. url: {
  70. bindingThirdPhone: '/sys/thirdLogin/bindingThirdPhone'
  71. }
  72. };
  73. },
  74. onLoad:function(){
  75. // #ifdef APP-PLUS
  76. var that=this
  77. plus.runtime.getProperty( plus.runtime.appid, function ( wgtinfo ) {
  78. that.version=wgtinfo.version
  79. });
  80. // #endif
  81. },
  82. computed: {
  83. isSendSMSEnable() {
  84. return this.smsCountDown <= 0 && this.phoneNo.length > 4;
  85. },
  86. getSendBtnText() {
  87. if (this.smsCountDown > 0) {
  88. return this.smsCountDown + '秒后发送';
  89. } else {
  90. return '发送验证码';
  91. }
  92. },
  93. canSMSLogin() {
  94. return this.userName.length > 4 && this.smsCode.length > 4;
  95. },
  96. canPwdLogin() {
  97. return this.userName.length > 4 && this.password.length > 4;
  98. },
  99. },
  100. methods: {
  101. ...mapActions([ "mLogin","PhoneLogin","ThirdLogin" ]),
  102. onLogin: function (){
  103. if(!this.userName || this.userName.length==0){
  104. this.$tip.toast('请填写用户名');
  105. return;
  106. }
  107. if(!this.password || this.password.length==0){
  108. this.$tip.toast('请填写密码');
  109. return;
  110. }
  111. let loginParams = {
  112. username:this.userName,
  113. password:this.password
  114. }
  115. this.loading=true;
  116. this.mLogin(loginParams).then((res) => {
  117. this.loading=false;
  118. if(res.data.success){
  119. // #ifdef APP-PLUS
  120. this.saveClientId()
  121. // #endif
  122. // #ifndef APP-PLUS
  123. this.$tip.success('登录成功!')
  124. this.$Router.replaceAll({name:'index'})
  125. // #endif
  126. }else{
  127. this.$tip.alert(res.data.message);
  128. }
  129. }).catch((err) => {
  130. let msg = err.data.message || "请求出现错误,请稍后再试"
  131. this.loading=false;
  132. this.$tip.alert(msg);
  133. }).finally(()=>{
  134. this.loading=false;
  135. })
  136. },
  137. saveClientId(){
  138. var info = plus.push.getClientInfo();
  139. var cid = info.clientid;
  140. this.$http.get("/sys/user/saveClientId",{params:{clientId:cid}}).then(res=>{
  141. console.log("res::saveClientId>",res)
  142. this.$tip.success('登录成功!')
  143. this.$Router.replaceAll({name:'index'})
  144. })
  145. },
  146. changePassword() {
  147. this.showPassword = !this.showPassword;
  148. },
  149. onSMSSend() {
  150. let smsParams = {};
  151. smsParams.mobile=this.phoneNo;
  152. smsParams.smsmode="0";
  153. let checkPhone = new RegExp(/^[1]([3-9])[0-9]{9}$/);
  154. if(!smsParams.mobile || smsParams.mobile.length==0){
  155. this.$tip.toast('请输入手机号');
  156. return false
  157. }
  158. if(!checkPhone.test(smsParams.mobile)){
  159. this.$tip.toast('请输入正确的手机号');
  160. return false
  161. }
  162. this.$http.post("/sys/sms",smsParams).then(res=>{
  163. if(res.data.success){
  164. this.smsCountDown = 60;
  165. this.startSMSTimer();
  166. }else{
  167. this.smsCountDown = 0;
  168. this.$tip.toast(res.data.message);
  169. }
  170. });
  171. },
  172. startSMSTimer() {
  173. this.smsCountInterval = setInterval(() => {
  174. this.smsCountDown--;
  175. if (this.smsCountDown <= 0) {
  176. clearInterval(this.smsCountInterval);
  177. }
  178. }, 1000);
  179. },
  180. onSMSLogin() {
  181. let checkPhone = new RegExp(/^[1]([3-9])[0-9]{9}$/);
  182. if(!this.phoneNo || this.phoneNo.length==0){
  183. this.$tip.toast('请填写手机号');
  184. return;
  185. }
  186. if(!checkPhone.test(this.phoneNo)){
  187. this.$tip.toast('请输入正确的手机号');
  188. return false
  189. }
  190. if(!this.smsCode || this.smsCode.length==0){
  191. this.$tip.toast('请填短信验证码');
  192. return;
  193. }
  194. let loginParams = {
  195. mobile:this.phoneNo,
  196. captcha:this.smsCode
  197. };
  198. this.PhoneLogin(loginParams).then((res) => {
  199. console.log("res====》",res)
  200. if(res.data.success){
  201. this.$tip.success('登录成功!')
  202. this.$Router.replaceAll({name:'index'})
  203. }else{
  204. this.$tip.error(res.data.message);
  205. }
  206. }).catch((err) => {
  207. let msg = ((err.response || {}).data || {}).message || err.data.message || "请求出现错误,请稍后再试"
  208. this.$tip.error(msg);
  209. });
  210. },
  211. loginSuccess() {
  212. // 登陆成功,重定向到主页
  213. this.$Router.replace({name:'index'})
  214. },
  215. requestFailed(err) {
  216. this.$message.warning("登录失败")
  217. },
  218. },
  219. beforeDestroy() {
  220. if (this.smsCountInterval) {
  221. clearInterval(this.smsCountInterval);
  222. }
  223. },
  224. }
  225. </script>
  226. <style>
  227. .login-paddingtop {
  228. padding-top: 100upx;
  229. }
  230. .zai-box {
  231. padding: 0 20upx;
  232. padding-top: 100upx;
  233. position: relative;
  234. }
  235. .zai-logo {
  236. width: 200upx;
  237. height: 150px;
  238. }
  239. .zai-title {
  240. margin-top: 20upx;
  241. font-size: 58upx;
  242. color: #000000;
  243. text-align: center;
  244. }
  245. .input-placeholder, .zai-input {
  246. color: #94afce;
  247. }
  248. .zai-label {
  249. padding: 60upx 0;
  250. text-align: center;
  251. font-size: 30upx;
  252. color: #a7b6d0;
  253. }
  254. .zai-btn {
  255. background: #ff65a3;
  256. color: #fff;
  257. border: 0;
  258. border-radius: 100upx;
  259. font-size: 36upx;
  260. }
  261. .zai-btn:after {
  262. border: 0;
  263. }
  264. /*按钮点击效果*/
  265. .zai-btn.button-hover {
  266. transform: translate(1upx, 1upx);
  267. }
  268. </style>