index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. <template>
  2. <div class="login">
  3. <div class="login-bg">
  4. <img :src="BG" alt="" />
  5. <div class="footer">
  6. <img :src="footer" alt="" />
  7. </div>
  8. </div>
  9. <div class="login-main">
  10. <div class="logo-header">
  11. <p class="logo-header-title">Hello!</p>
  12. <p class="logo-header-tips">欢迎登录藏金·1745平台</p>
  13. </div>
  14. <div class="loginBox">
  15. <div class="loginBox-div">
  16. <div class="loginBox-bg">
  17. <img :src="loginBox" alt="" />
  18. </div>
  19. <van-form validate-first class="login-form">
  20. <ul class="ul">
  21. <li class="li-div">
  22. <ul class="clear">
  23. <li><img :src="user" alt="" /></li>
  24. <li>
  25. <div class="zdyDiv">
  26. <span class="zdyName">CJ1745</span>
  27. <van-field
  28. size="large"
  29. v-model="form.mobile"
  30. name="mobile"
  31. placeholder="xxxxxx"
  32. type="text"
  33. style="background: transparent"
  34. maxlength="9"
  35. :rules="[{ validator: asyncmobileValidator }]"
  36. >
  37. </van-field>
  38. </div>
  39. </li>
  40. </ul>
  41. </li>
  42. <li class="li-div">
  43. <ul class="clear">
  44. <li><img :src="pwod" alt="" /></li>
  45. <li>
  46. <van-field
  47. size="large"
  48. v-model="form.code"
  49. name="code"
  50. maxlength="6"
  51. style="background: transparent"
  52. placeholder="请输入密码"
  53. :rules="[{ validator: asyncpwodValidator }]"
  54. :type="!passwordStatus ? 'password' : 'text'"
  55. @click-right-icon="showPassword"
  56. ></van-field>
  57. <!-- :right-icon="!passwordStatus ? 'eye-o' : 'closed-eye'" -->
  58. </li>
  59. </ul>
  60. </li>
  61. </ul>
  62. </van-form>
  63. </div>
  64. </div>
  65. <div class="login-form-button clear">
  66. <van-button
  67. block
  68. type="info"
  69. :disabled="loadding"
  70. :loadding="loadding"
  71. loadding-text="加载中..."
  72. native-type="submit"
  73. @click="onSubmit()"
  74. >
  75. 登&nbsp;录
  76. </van-button>
  77. <span class="fr reset-span" @click="loginSuccess('/reset')">修改密码</span>
  78. </div>
  79. </div>
  80. </div>
  81. </template>
  82. <script>
  83. import { isnumber, validAlphabets } from "@/utils/validate";
  84. import resToken from "@/mixins/resToken";
  85. export default {
  86. mixins: [resToken],
  87. data() {
  88. return {
  89. passwordStatus: false, //默认隐藏密码
  90. BG: require("@/assets/images/active1/login.png"),
  91. user: require("@/assets/images/active1/cardNo.png"),
  92. pwod: require("@/assets/images/active1/password.png"),
  93. loginBox: require("@/assets/images/active1/loginBox.png"),
  94. footer: require("@/assets/images/active1/footer.png"),
  95. loadding: false,
  96. form: {
  97. mobile: "",
  98. code: "",
  99. },
  100. };
  101. },
  102. created(){
  103. // sessionStorage.setItem("type",'active1')
  104. },
  105. methods: {
  106. //主题
  107. theme(type) {
  108. sessionStorage.setItem("type",type)
  109. this.$store.commit('app/SET_TYPE', type);
  110. // document.querySelector("#app").setAttribute( "data-theme", type );
  111. window.document.documentElement.setAttribute( "data-theme", type );
  112. },
  113. // 点击 登陆按钮 后执行提交
  114. async onSubmit() {
  115. if (!this.loadding) {
  116. this.loadding = true;
  117. await this.asyncmobileValidator(this.form.mobile) //校验表单卡号
  118. .then(async (res) => {
  119. if (res === "ok") {
  120. let parmValue = {
  121. code: this.form.code,
  122. mobile: "CJ1745" + this.form.mobile,
  123. };
  124. await this.asyncpwodValidator(this.form.code)
  125. .then(async (res) => {
  126. if (res === "ok") {
  127. this.$store
  128. .dispatch("user/login", parmValue)
  129. .then((res) => {
  130. //登录成功后根据当前账号设置主题
  131. //截取输入框账号第一位进行判断
  132. let status = this.form.mobile.substr(0,1)
  133. if(isnumber(status)){
  134. this.theme("active2")
  135. }else{
  136. this.theme("active1")
  137. }
  138. // return;
  139. this.loadding = false;
  140. if (res.code === 0) {
  141. this.loginSuccess("/home/paddy");
  142. } else {
  143. this.show_title(res.msg);
  144. }
  145. })
  146. .catch((err) => {
  147. console.log(err);
  148. this.loadding = false;
  149. });
  150. } else {
  151. this.loadding = false;
  152. }
  153. })
  154. .catch(() => {
  155. this.loadding = false;
  156. });
  157. } else {
  158. this.loadding = false;
  159. }
  160. console.log(res);
  161. })
  162. .catch(() => {
  163. this.loadding = false;
  164. });
  165. }
  166. },
  167. async loginSuccess(path) {
  168. window.vm.$router.push({
  169. path: path,
  170. });
  171. },
  172. async asyncmobileValidator(val) {
  173. return new Promise((resolve) => {
  174. let type = true;
  175. if (val === "") {
  176. this.show_title("请输入卡号!");
  177. type = false;
  178. } else {
  179. if (val.length < 6) {
  180. this.show_title("卡号不正确!");
  181. type = false;
  182. }
  183. let patt = /[^\w\/]/ig
  184. if (patt.test(val)) {
  185. this.show_title("卡号不正确!");
  186. type = false;
  187. }
  188. }
  189. resolve(type ? "ok" : "error");
  190. });
  191. },
  192. async asyncpwodValidator(val) {
  193. return new Promise((resolve) => {
  194. let type = true;
  195. if (val === "") {
  196. this.show_title("请输入密码!");
  197. type = false;
  198. } else {
  199. if (val.length !== 6) {
  200. this.show_title("密码为2位字母+4位数字!");
  201. type = false;
  202. } else {
  203. let a = val.slice(0, 2);
  204. let b = val.slice(2, 4);
  205. if (!isnumber(b)) {
  206. this.show_title("密码为2位字母+4位数字!");
  207. type = false;
  208. }
  209. if (!validAlphabets(a)) {
  210. this.show_title("密码为2位字母+4位数字!");
  211. type = false;
  212. }
  213. }
  214. }
  215. resolve(type ? "ok" : "error");
  216. });
  217. },
  218. showPassword() {
  219. //展示/隐藏密码
  220. console.log(this.passwordStatus);
  221. this.passwordStatus = !this.passwordStatus;
  222. },
  223. },
  224. };
  225. </script>
  226. <style lang="scss" scoped>
  227. .login {
  228. box-sizing: border-box;
  229. // .van-field__control{
  230. // font-size: 15px!important;
  231. // }
  232. .login-bg {
  233. position: relative;
  234. z-index: 1;
  235. width: 100%;
  236. height: 100%;
  237. box-sizing: border-box;
  238. overflow: hidden;
  239. background: #e6e6dc;
  240. img {
  241. display: inline-block;
  242. box-sizing: border-box;
  243. width: 100%;
  244. }
  245. .footer {
  246. position: absolute;
  247. box-sizing: border-box;
  248. z-index: 2;
  249. bottom: 0;
  250. left: 0;
  251. img {
  252. display: inline-block;
  253. width: 100%;
  254. padding: 0 30px 30px 30px;
  255. }
  256. }
  257. }
  258. .login-main {
  259. position: absolute;
  260. width: 100%;
  261. height: 100%;
  262. z-index: 9;
  263. top: 0;
  264. left: 0;
  265. .logo-header {
  266. //上半部分登陆盒子,用来展示一张图片
  267. width: 100%;
  268. padding: 8vh 30px 30px 30px;
  269. .logo-header-title {
  270. font-size: 30px;
  271. // font-family: DIN;
  272. font-weight: bold;
  273. color: #daad70;
  274. margin: 12px 0;
  275. }
  276. .logo-header-tips {
  277. font-size: 15px;
  278. font-weight: 200;
  279. color: #daad70;
  280. margin: 10px 0;
  281. }
  282. }
  283. .loginBox {
  284. padding: 0 30px;
  285. box-sizing: border-box;
  286. position: relative;
  287. .loginBox-bg {
  288. position: relative;
  289. width: 100%;
  290. // height: 100px;
  291. img {
  292. width: 100%;
  293. display: inline-block;
  294. }
  295. }
  296. .login-form {
  297. position: absolute;
  298. top: 0;
  299. left: 30px;
  300. width: calc(100% - 60px);
  301. padding: 5.5vh 20px 0 14px;
  302. box-sizing: border-box;
  303. ul.ul {
  304. width: 100%;
  305. li.li-div {
  306. width: 100%;
  307. height: 55px;
  308. padding: 0 0 0.5vh;
  309. ul {
  310. li {
  311. float: left;
  312. &:first-child {
  313. width: 40px;
  314. height: 48px;
  315. line-height: 50px;
  316. text-align: center;
  317. img {
  318. display: inline-block;
  319. height: 18px;
  320. margin: 14px 0 0 0;
  321. }
  322. }
  323. &:last-child {
  324. width: calc(100% - 40px);
  325. }
  326. .zdyDiv {
  327. float: left;
  328. width: 100%;
  329. .zdyName {
  330. width: 55px;
  331. line-height: 48px;
  332. float: left;
  333. color: #000;
  334. text-align: right;
  335. font-size: 16px;
  336. }
  337. }
  338. .van-cell {
  339. float: left;
  340. background: transparent !important;
  341. padding-left: 1px;
  342. .van-cell__value {
  343. background: transparent !important;
  344. > div {
  345. background: transparent !important;
  346. input {
  347. background: transparent !important;
  348. }
  349. }
  350. }
  351. .van-field__control {
  352. font-size: 15px !important;
  353. }
  354. }
  355. }
  356. }
  357. &:first-child {
  358. ul {
  359. li {
  360. &:last-child {
  361. .van-cell {
  362. width: calc(100% - 55px);
  363. }
  364. }
  365. }
  366. }
  367. }
  368. }
  369. }
  370. }
  371. }
  372. .login-form-button {
  373. padding: 10vh 30px 0 30px;
  374. .van-button {
  375. background: linear-gradient(0deg, #a67e4b, #efc180);
  376. border-radius: 8px;
  377. overflow: hidden;
  378. color: #111111;
  379. border: 0;
  380. font-weight: bolder;
  381. }
  382. .reset-span{
  383. padding:10px;
  384. color: #454545;
  385. }
  386. }
  387. }
  388. }
  389. </style>