login.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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. };
  70. },
  71. onLoad: function () {
  72. // #ifdef APP-PLUS
  73. var that = this;
  74. plus.runtime.getProperty(plus.runtime.appid, function (wgtinfo) {
  75. that.version = wgtinfo.version;
  76. });
  77. // #endif
  78. },
  79. computed: {
  80. isSendSMSEnable() {
  81. return this.smsCountDown <= 0 && this.phoneNo.length > 4;
  82. },
  83. getSendBtnText() {
  84. if (this.smsCountDown > 0) {
  85. return this.smsCountDown + "秒后发送";
  86. } else {
  87. return "发送验证码";
  88. }
  89. },
  90. canSMSLogin() {
  91. return this.userName.length > 4 && this.smsCode.length > 4;
  92. },
  93. canPwdLogin() {
  94. return this.userName.length > 4 && this.password.length > 4;
  95. },
  96. },
  97. methods: {
  98. ...mapActions(["mLogin", "PhoneLogin", "ThirdLogin"]),
  99. onLogin: function () {
  100. if (!this.userName || this.userName.length == 0) {
  101. this.$tip.toast("请填写用户名");
  102. return;
  103. }
  104. if (!this.password || this.password.length == 0) {
  105. this.$tip.toast("请填写密码");
  106. return;
  107. }
  108. let loginParams = {
  109. username: this.userName,
  110. password: this.password,
  111. };
  112. this.loading = true;
  113. this.mLogin(loginParams)
  114. .then((res) => {
  115. this.loading = false;
  116. if (res.data.success) {
  117. // #ifdef APP-PLUS
  118. this.saveClientId();
  119. // #endif
  120. // #ifndef APP-PLUS
  121. this.$tip.success("登录成功!");
  122. this.$Router.replaceAll({ name: "index" });
  123. // #endif
  124. } else {
  125. this.$tip.alert(res.data.message);
  126. }
  127. })
  128. .catch((err) => {
  129. let msg = err.data.message || "请求出现错误,请稍后再试";
  130. this.loading = false;
  131. this.$tip.alert(msg);
  132. })
  133. .finally(() => {
  134. this.loading = false;
  135. });
  136. },
  137. saveClientId() {
  138. var info = plus.push.getClientInfo();
  139. var cid = info.clientid;
  140. this.$http
  141. .get("/sys/user/saveClientId", { params: { clientId: cid } })
  142. .then((res) => {
  143. console.log("res::saveClientId>", res);
  144. this.$tip.success("登录成功1!");
  145. uni.navigateTo({
  146. url: "/pages/index/index",
  147. });
  148. });
  149. },
  150. changePassword() {
  151. this.showPassword = !this.showPassword;
  152. },
  153. onSMSSend() {
  154. let smsParams = {};
  155. smsParams.mobile = this.phoneNo;
  156. smsParams.smsmode = "0";
  157. let checkPhone = new RegExp(/^[1]([3-9])[0-9]{9}$/);
  158. if (!smsParams.mobile || smsParams.mobile.length == 0) {
  159. this.$tip.toast("请输入手机号");
  160. return false;
  161. }
  162. if (!checkPhone.test(smsParams.mobile)) {
  163. this.$tip.toast("请输入正确的手机号");
  164. return false;
  165. }
  166. this.$http.post("/sys/sms", smsParams).then((res) => {
  167. if (res.data.success) {
  168. this.smsCountDown = 60;
  169. this.startSMSTimer();
  170. } else {
  171. this.smsCountDown = 0;
  172. this.$tip.toast(res.data.message);
  173. }
  174. });
  175. },
  176. startSMSTimer() {
  177. this.smsCountInterval = setInterval(() => {
  178. this.smsCountDown--;
  179. if (this.smsCountDown <= 0) {
  180. clearInterval(this.smsCountInterval);
  181. }
  182. }, 1000);
  183. },
  184. onSMSLogin() {
  185. let checkPhone = new RegExp(/^[1]([3-9])[0-9]{9}$/);
  186. if (!this.phoneNo || this.phoneNo.length == 0) {
  187. this.$tip.toast("请填写手机号");
  188. return;
  189. }
  190. if (!checkPhone.test(this.phoneNo)) {
  191. this.$tip.toast("请输入正确的手机号");
  192. return false;
  193. }
  194. if (!this.smsCode || this.smsCode.length == 0) {
  195. this.$tip.toast("请填短信验证码");
  196. return;
  197. }
  198. let loginParams = {
  199. mobile: this.phoneNo,
  200. captcha: this.smsCode,
  201. };
  202. this.PhoneLogin(loginParams)
  203. .then((res) => {
  204. console.log("res====》", res);
  205. if (res.data.success) {
  206. this.$tip.success("登录成功!");
  207. this.$Router.replaceAll({ name: "index" });
  208. } else {
  209. this.$tip.error(res.data.message);
  210. }
  211. })
  212. .catch((err) => {
  213. let msg =
  214. ((err.response || {}).data || {}).message ||
  215. err.data.message ||
  216. "请求出现错误,请稍后再试";
  217. this.$tip.error(msg);
  218. });
  219. },
  220. loginSuccess() {
  221. // 登陆成功,重定向到主页
  222. this.$Router.replace({ name: "index" });
  223. },
  224. requestFailed(err) {
  225. this.$message.warning("登录失败");
  226. },
  227. },
  228. beforeDestroy() {
  229. if (this.smsCountInterval) {
  230. clearInterval(this.smsCountInterval);
  231. }
  232. },
  233. };
  234. </script>
  235. <style>
  236. .login-paddingtop {
  237. padding-top: 100upx;
  238. }
  239. .zai-box {
  240. padding: 0 20upx;
  241. padding-top: 100upx;
  242. position: relative;
  243. }
  244. .zai-logo {
  245. width: 200upx;
  246. height: 150px;
  247. }
  248. .zai-title {
  249. margin-top: 20upx;
  250. font-size: 58upx;
  251. color: #000000;
  252. text-align: center;
  253. }
  254. .input-placeholder,
  255. .zai-input {
  256. color: #94afce;
  257. }
  258. .zai-label {
  259. padding: 60upx 0;
  260. text-align: center;
  261. font-size: 30upx;
  262. color: #a7b6d0;
  263. }
  264. .zai-btn {
  265. background: #ff65a3;
  266. color: #fff;
  267. border: 0;
  268. border-radius: 100upx;
  269. font-size: 36upx;
  270. }
  271. .zai-btn:after {
  272. border: 0;
  273. }
  274. /*按钮点击效果*/
  275. .zai-btn.button-hover {
  276. transform: translate(1upx, 1upx);
  277. }
  278. </style>