index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. <template>
  2. <div class="login-container">
  3. <div class="company-name" style="margin-top: -88px; margin-bottom: 90px">
  4. <!-- <img src="./images/logo.png"> -->
  5. <div class="shadow-font">马边县城市供水综合管理平台</div>
  6. <!-- 马边县城市供水综合管理平台 -->
  7. </div>
  8. <div class="fill-container">
  9. <div class="left">
  10. <img src="./images/supplierPipe.png" />
  11. </div>
  12. <div class="right">
  13. <div class="top">
  14. <!-- <span>欢迎登录</span>
  15. <span>智慧水务综合管理平台</span> -->
  16. <div
  17. class="left-img"
  18. style="
  19. width: 33%;
  20. float: left;
  21. margin-top: -14px;
  22. text-align: right;
  23. "
  24. >
  25. <img src="./images/left.png" />
  26. </div>
  27. <div
  28. class="center-span"
  29. style="
  30. width: 34%;
  31. float: left;
  32. font-size: 24px;
  33. font-weight: bold;
  34. text-align: center;
  35. color: #2f75e7;
  36. "
  37. >
  38. <span>欢迎登录</span>
  39. </div>
  40. <div
  41. class="right-img"
  42. style="width: 33%; float: left; margin-top: -14px"
  43. >
  44. <img src="./images/right.png" />
  45. </div>
  46. </div>
  47. <el-form
  48. ref="loginForm"
  49. :model="loginForm"
  50. :rules="loginRules"
  51. class="login-form middle"
  52. auto-complete="on"
  53. label-position="left"
  54. >
  55. <el-input
  56. ref="username"
  57. v-model="loginForm.username"
  58. suffix-icon="el-icon-user"
  59. placeholder="请输入账号"
  60. name="username"
  61. type="text"
  62. class="form-input"
  63. tabindex="1"
  64. auto-complete="on"
  65. />
  66. <el-input
  67. :key="passwordType"
  68. ref="password"
  69. v-model="loginForm.password"
  70. :type="passwordType"
  71. placeholder="请输入密码"
  72. name="password"
  73. tabindex="2"
  74. class="form-input"
  75. auto-complete="on"
  76. suffix-icon="el-icon-lock"
  77. @keyup.enter.native="handleLogin"
  78. />
  79. <div class="form-input">
  80. <el-input
  81. v-model="loginForm.verifyCode"
  82. name="verifyCode"
  83. placeholder="请输入验证码"
  84. style="float: left; width: calc(100% - 189px)"
  85. ></el-input>
  86. <img
  87. :src="captchaUrl"
  88. @click="refreshCaptcha"
  89. style="float: left; height: 34px; width: 188px; cursor: pointer"
  90. />
  91. </div>
  92. </el-form>
  93. <el-button
  94. class="login-btn"
  95. :loading="loading"
  96. @click.native.prevent="handleLogin"
  97. >登录</el-button
  98. >
  99. </div>
  100. </div>
  101. <el-dialog
  102. title="密码修改"
  103. :visible.sync="passwordDialog"
  104. append-to-body
  105. width="520px"
  106. top="25vh"
  107. :close-on-click-modal="false"
  108. :close-on-press-escape="false"
  109. :show-close="false"
  110. >
  111. <el-form
  112. ref="changePwdForm"
  113. :model="changePwd"
  114. :rules="pwdRules"
  115. label-width="100px"
  116. label-position="right"
  117. >
  118. <el-form-item label="密码:" prop="pass" style="margin-bottom: 25px">
  119. <el-input
  120. v-model="changePwd.pass"
  121. autocomplete="off"
  122. type="password"
  123. placeholder="请输入密码"
  124. suffix-icon="el-icon-lock"
  125. />
  126. </el-form-item>
  127. <el-form-item label="确认密码:" prop="checkPass">
  128. <el-input
  129. v-model="changePwd.checkPass"
  130. autocomplete="off"
  131. type="password"
  132. placeholder="请输入密码"
  133. suffix-icon="el-icon-lock"
  134. />
  135. </el-form-item>
  136. </el-form>
  137. <template slot="footer">
  138. <el-button @click="handleDialogBtnClick('cancel')">取消</el-button>
  139. <el-button type="primary" @click="handleDialogBtnClick('confirm')"
  140. >确定</el-button
  141. >
  142. </template>
  143. </el-dialog>
  144. </div>
  145. </template>
  146. <script>
  147. import { userFirstLogin } from "@/api/user";
  148. import { changePassword } from "@/api/base";
  149. import { regPassword } from "@/utils/reg";
  150. import { IP } from "@/utils/request.js";
  151. const sha1Hex = require("sha1-hex");
  152. export default {
  153. name: "Login",
  154. data() {
  155. const validatePwd1st = (rule, value, callback) => {
  156. if (value === "") {
  157. callback(new Error("请输入密码!"));
  158. } else {
  159. if (this.changePwd.pass !== "") {
  160. if (!regPassword().test(value)) {
  161. callback(
  162. new Error(
  163. "密码位数8-16位,必须包含大小写字母和数字,不可包含非法字符!"
  164. )
  165. );
  166. return;
  167. }
  168. }
  169. callback();
  170. }
  171. };
  172. const validatePwd2nd = (rule, value, callback) => {
  173. if (value === "") {
  174. callback(new Error("请再次输入密码"));
  175. } else if (value !== this.changePwd.pass && value !== "") {
  176. callback(new Error("两次输入密码不一致!"));
  177. } else {
  178. callback();
  179. }
  180. };
  181. return {
  182. url: "@/assets/images/login/logo.png",
  183. loginForm: {
  184. username: "",
  185. password: "",
  186. verifyCode: "",
  187. },
  188. loginRules: {
  189. username: [{ required: true, trigger: "blur", message: "请输入账号" }],
  190. password: [{ required: true, trigger: "blur", message: "请输入密码" }],
  191. verifyCode: [
  192. { required: true, trigger: "blur", message: "请输入验证码" },
  193. ],
  194. },
  195. loading: false,
  196. passwordType: "password",
  197. redirect: undefined,
  198. error: 1,
  199. // warning: true,
  200. msg: "",
  201. passwordDialog: false, // 重置密码用弹窗显隐控制
  202. changePwd: {
  203. pass: "", // 重置密码用新密码
  204. checkPass: "", // 重置密码用确认密码
  205. },
  206. pwdRules: {
  207. pass: [{ required: true, validator: validatePwd1st, trigger: "blur" }],
  208. checkPass: [
  209. { required: true, validator: validatePwd2nd, trigger: "blur" },
  210. ],
  211. },
  212. userId: "",
  213. captchaUrl: IP + "/auth/token/getVerifyCode",
  214. };
  215. },
  216. computed: {
  217. sysTitle() {
  218. return this.$store.state.settings.sysTitle;
  219. },
  220. },
  221. watch: {
  222. $route: {
  223. handler: function (route) {
  224. this.redirect = route.query && route.query.redirect;
  225. },
  226. immediate: true,
  227. },
  228. },
  229. methods: {
  230. // 是否显示密码
  231. showPwd() {
  232. if (this.passwordType === "password") {
  233. this.passwordType = "text";
  234. } else {
  235. this.passwordType = "password";
  236. }
  237. this.$nextTick(() => {
  238. this.$refs.password.focus();
  239. });
  240. },
  241. // 登录
  242. handleLogin() {
  243. this.$refs.loginForm.validate((valid) => {
  244. if (valid) {
  245. this.loading = true;
  246. this.$store
  247. .dispatch("user/login", this.loginForm)
  248. .then((res) => {
  249. const { id } = res.result;
  250. // 判断是否首次登录或者重置过密码
  251. userFirstLogin(id)
  252. .then((res) => {
  253. // 先判断用户是否被禁用了 如果是申请的用户 还需要要判断是否同意申请了
  254. const { auditstatus, enableFlag } = res.result;
  255. if (enableFlag === "0") {
  256. this.$message({
  257. message: "用户已被禁用,请先启用!",
  258. type: "error",
  259. });
  260. //this.loading = false
  261. sessionStorage.clear();
  262. return;
  263. }
  264. if (auditstatus !== "2" && auditstatus !== null) {
  265. this.$message({
  266. message:
  267. auditstatus === 1
  268. ? "账户还未审核通过!"
  269. : "账户审核未被通过!",
  270. type: "error",
  271. });
  272. //this.loading = false
  273. sessionStorage.clear();
  274. return;
  275. }
  276. // 是首次登录 打开弹窗 修改密码
  277. if (res.result.firstlog === "1") {
  278. this.userId = id;
  279. this.passwordDialog = true;
  280. // 清除掉用户id 防止用户没有修改密码刷新进入页面
  281. sessionStorage.removeItem("userId");
  282. this.$store.state.user.userId = undefined;
  283. } else {
  284. //this.loading = false
  285. this.$router.push({ path: "/" });
  286. }
  287. })
  288. .catch(() => {
  289. sessionStorage.clear();
  290. this.loading = false;
  291. });
  292. // this.$router.push({ path: '/' })
  293. })
  294. .catch(() => {
  295. this.loading = false;
  296. });
  297. } else {
  298. console.log("error submit!!");
  299. return false;
  300. }
  301. // this.$router.push('/dashboard')
  302. });
  303. },
  304. // 修改密码弹窗
  305. handleDialogBtnClick(type) {
  306. if (type === "cancel") {
  307. this.$nextTick(() => {
  308. this.$refs.changePwdForm.resetFields();
  309. });
  310. this.passwordDialog = false;
  311. this.changePwd.pass = "";
  312. this.changePwd.checkPass = "";
  313. sessionStorage.clear();
  314. this.loading = false;
  315. } else {
  316. this.$refs.changePwdForm.validate((valid) => {
  317. if (valid) {
  318. const originalPassword = "000000";
  319. const data = {
  320. originalPassword: sha1Hex(originalPassword),
  321. id: this.userId,
  322. firstlog: 0,
  323. password: sha1Hex(this.changePwd.checkPass),
  324. };
  325. changePassword(data).then((res) => {
  326. if (res.code !== -1) {
  327. this.$message({
  328. message: "密码修改成功,请您重新登录!",
  329. type: "success",
  330. });
  331. this.passwordDialog = false;
  332. this.loading = false;
  333. this.changePwd.pass = "";
  334. this.changePwd.checkPass = "";
  335. sessionStorage.clear();
  336. } else {
  337. this.$nextTick(() => {
  338. this.$refs.changePwdForm.resetFields();
  339. });
  340. this.passwordDialog = false;
  341. this.loading = false;
  342. this.changePwd.pass = "";
  343. this.changePwd.checkPass = "";
  344. sessionStorage.clear();
  345. this.$message({
  346. message: res.message,
  347. type: "error",
  348. });
  349. }
  350. });
  351. } else return false;
  352. });
  353. }
  354. },
  355. refreshCaptcha() {
  356. this.captchaUrl = `${IP}/auth/token/getVerifyCode?t=${new Date().getTime()}`; // 加时间戳防止缓存
  357. },
  358. },
  359. };
  360. </script>
  361. <style lang="scss" scoped>
  362. .login-container {
  363. width: 100%;
  364. height: 100%;
  365. display: flex;
  366. flex-direction: column;
  367. justify-content: center;
  368. align-items: center;
  369. background: url("./images/background.png") no-repeat fixed center/100%;
  370. img {
  371. user-select: none;
  372. height: 100%;
  373. }
  374. .fill-container {
  375. width: 900px;
  376. height: 434px;
  377. display: flex;
  378. border-radius: 10px;
  379. background-color: #ffffff;
  380. box-shadow: 3px 3px 4px
  381. linear-gradient(#333333 40%, #333333 60%, black 80%, blue 100%);
  382. .left {
  383. flex: 1;
  384. overflow: hidden;
  385. }
  386. .right {
  387. width: 362px;
  388. display: flex;
  389. flex-direction: column;
  390. align-items: center;
  391. padding-top: 60px;
  392. .top {
  393. position: relative;
  394. height: 48px;
  395. width: 100%;
  396. flex-direction: column;
  397. justify-content: center;
  398. align-items: center;
  399. font-size: 30px;
  400. color: #333333;
  401. margin-bottom: 52px;
  402. > span {
  403. line-height: 30px;
  404. &:nth-of-type(2) {
  405. margin-top: 16px;
  406. }
  407. }
  408. }
  409. .middle {
  410. width: 320px;
  411. height: 126px;
  412. margin-bottom: 80px;
  413. > .form-input {
  414. height: 36px;
  415. line-height: 36px;
  416. ::v-deep input {
  417. height: 36px;
  418. }
  419. &:nth-of-type(2) {
  420. margin-top: 34px;
  421. }
  422. &:nth-of-type(3) {
  423. margin-top: 34px;
  424. }
  425. }
  426. }
  427. .login-btn {
  428. width: 320px;
  429. height: 44px;
  430. border-radius: 22px;
  431. overflow: hidden;
  432. font-size: 16px;
  433. background: #2d74e7;
  434. transition: background 0.3s linear;
  435. color: #ffffff;
  436. &:hover {
  437. background: #2467d3;
  438. }
  439. }
  440. }
  441. }
  442. .shadow-font {
  443. color: #ffffff;
  444. font-size: 40px;
  445. font-weight: bold;
  446. letter-spacing: 6px;
  447. // -webkit-box-reflect: below 1px -webkit-gradient(linear, 0 0, 0 50%, from(transparent), color-stop(.2, transparent), to(rgba(3,3,3,.1)));
  448. }
  449. }
  450. </style>