移动端
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

onlineHomeLogin.vue 14 KiB

3 anni fa
3 anni fa
3 anni fa
3 anni fa
3 anni fa
3 anni fa
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. <template>
  2. <div class="app-container">
  3. <div class="title">
  4. <img style="display: inline-block;margin-right: 10px;" src="../../static/images/onlineHome/OHlogo1.png" alt="">
  5. <img style="display: inline-block;" src="../../static/images/onlineHome/OHlogoWord.png" alt="">
  6. </div>
  7. <van-tabs v-model="active" :swipeable="true" style="margin-top:0.5rem;padding:0 10px;">
  8. <van-tab title="登录" name="1">
  9. <van-form style="margin:50px 0;" v-if="!showMessage">
  10. <van-field
  11. v-model="formData.username"
  12. placeholder="请输入手机号/账号"
  13. :rules="[{ required: true, message:'' }]"
  14. />
  15. <van-field
  16. v-model="formData.password"
  17. type="password"
  18. style="margin-top: 20px"
  19. placeholder="请输入密码"
  20. :rules="[{ required: true, message:'' }]"
  21. />
  22. <van-field
  23. v-model="formData.code"
  24. center
  25. clearable
  26. label="验证码"
  27. :rules="[{ required: true, }]"
  28. placeholder="图形验证码"
  29. >
  30. <template #button>
  31. <img style="width: 100px" :src="codeUrl" @click="getCode" />
  32. </template>
  33. </van-field>
  34. <van-checkbox style="float: left;margin-top:10px;margin-left:20px;" v-model="formData.rememberMe" shape="square">{{showMessage ? "记住手机号" : "记住密码"}}</van-checkbox>
  35. <p style="float: right;margin-top:10px;margin-right:20px;color:#1D6FE9 ">忘记密码</p>
  36. <div class="clear"></div>
  37. <div style="margin: 50px 16px 16px;">
  38. <van-button block type="info" native-type="submit" @click="handleLogin">登录</van-button>
  39. <p style="text-align: center;margin-top: 20px;color:#878787 " @click="showMessagePop">短信验证码登录</p>
  40. </div>
  41. </van-form>
  42. <van-form style="margin:50px 0;" v-if="showMessage">
  43. <van-field
  44. v-model="formData.mobile"
  45. name="请输入手机号"
  46. placeholder="请输入手机号"
  47. :rules="[{ required: true, message: '' }]"
  48. />
  49. <van-field
  50. v-model="formData.code"
  51. center
  52. clearable
  53. label="验证码"
  54. placeholder="图形验证码"
  55. >
  56. <template #button>
  57. <img style="width: 100px" :src="codeUrl" @click="getCode" />
  58. </template>
  59. </van-field>
  60. <div style="margin: 50px 16px 16px;">
  61. <van-button block type="info" native-type="submit" @click="getSmsCode">获取验证码</van-button>
  62. <p style="text-align: center;margin-top: 20px;color:#878787 " @click="showMessagePop">密码登录</p>
  63. </div>
  64. </van-form>
  65. </van-tab>
  66. <van-tab title="注册" name="2">
  67. <van-form style="margin:50px 0;">
  68. <van-field
  69. v-model="formData.memberName"
  70. name="请输入姓名"
  71. placeholder="请输入姓名"
  72. :rules="[{ required: true, message: '请填写姓名' }]"
  73. />
  74. <van-field
  75. v-model="formData.idcard"
  76. name="请输入身份证号"
  77. style="margin-top: 20px"
  78. placeholder="请输入身份证号"
  79. :rules="[{ required: true, message: '请输入身份证号' }]"
  80. />
  81. <van-field
  82. v-model="formData.mobile"
  83. name="请输入手机号"
  84. style="margin-top: 20px"
  85. placeholder="请输入手机号"
  86. :rules="[{ required: true, message: '请填写手机号' }]"
  87. />
  88. <van-field
  89. v-model="formData.code"
  90. center
  91. clearable
  92. label="验证码"
  93. placeholder="图形验证码"
  94. >
  95. <template #button>
  96. <img style="width: 100px" :src="codeUrl" @click="getCode" />
  97. </template>
  98. </van-field>
  99. <van-field
  100. v-model="formData.smsCode"
  101. style="margin-top: 20px"
  102. placeholder="请输入验证码"
  103. :rules="[{ required: true, message: '请填写验证码' }]"
  104. >
  105. <template #button>
  106. <!-- <van-button size="mini" type="info" @click="getRegisterSmsCode" >获取验证码</van-button> -->
  107. <div class="registerSmsBtn" @click="getRegisterSmsCode">{{
  108. computeTime > 0 ? `(${computeTime}s)已发送` : "获取短信码"
  109. }}</div>
  110. </template>
  111. </van-field>
  112. <div style="margin: 50px 16px 16px;">
  113. <van-button block type="info" native-type="submit" @click="registerSubmit">注册</van-button>
  114. </div>
  115. </van-form>
  116. </van-tab>
  117. </van-tabs>
  118. <van-popup v-model="showKeyboard" :style="{ height: '100%',width:'100%' }" >
  119. <van-nav-bar
  120. left-arrow
  121. fixed
  122. placeholder
  123. @click-left="showPopup"
  124. />
  125. <div style="padding: 20px">
  126. <h1>输入短信验证码</h1>
  127. <h3 style="color: #878787">验证码已发送至{{(formData.mobile+"").substr(0,3) + "****" + (formData.mobile+"").substr(7)}},请在下方输入框内输入4位数字验证码</h3>
  128. </div>
  129. <van-password-input
  130. :value="smsCodeValue"
  131. :length="4"
  132. :focused="showKeyboard"
  133. @focus="showKeyboard = true"
  134. />
  135. <van-number-keyboard
  136. v-model="smsCodeValue"
  137. :show="showKeyboard"
  138. theme="custom"
  139. close-button-text="完成"
  140. />
  141. </van-popup>
  142. </div>
  143. </template>
  144. <style scoped>
  145. .app-container{
  146. background: #fff;
  147. height: 100vh;
  148. }
  149. .title{
  150. padding-top: 20%;
  151. width: 88%;
  152. margin: 0 auto;
  153. }
  154. .van-tab--active{
  155. font-size: .6rem;
  156. font-weight: bold;
  157. }
  158. .van-tabs__line{
  159. background:#1D6FE9;
  160. width: 0.15rem;
  161. height: 0.15rem;
  162. border-radius: 0.07rem;
  163. bottom: 0.3rem;
  164. }
  165. .van-tabs__nav{
  166. padding:0
  167. }
  168. .van-tab{
  169. display: inline-block;
  170. flex: inherit;
  171. margin-left: 30px;
  172. line-height: .8rem;
  173. }
  174. .van-tab__text--ellipsis {
  175. overflow: auto;
  176. }
  177. .van-password-input{
  178. width: 50%;
  179. margin: 0 auto;
  180. }
  181. [class*=van-hairline]::after{
  182. border:none;
  183. }
  184. .van-password-input__security li{
  185. margin: 0 10px;
  186. border-bottom: 3px solid black;
  187. }
  188. .registerSmsBtn{
  189. color: rgb(29, 111, 233);
  190. font-size: 0.34rem;
  191. }
  192. </style>
  193. <script>
  194. import { getCodeImg, getSmsCode ,getRegisterSmsCode,registerCheck,registerOn} from "../api/login";
  195. import Cookies from "js-cookie";
  196. import { encrypt, decrypt } from "../utils/jsencrypt";
  197. //引用wx sdk
  198. import wx from "weixin-js-sdk";
  199. export default {
  200. name: "login",
  201. data() {
  202. return {
  203. showMessage:false,
  204. smsCodeValue:"",
  205. showKeyboard:false,
  206. formData: {
  207. username: "", //账号
  208. password: "", //密码
  209. code: null, //图片验证码
  210. uuid: null, //识别uuid
  211. mobile: null, //手机号
  212. smsCode: null, //短信验证码
  213. memberName:null, //身份信息
  214. idcard:null, //身份号码
  215. rememberMe:false
  216. },
  217. loading: false,
  218. codeUrl: "", //验证码
  219. isSmsLogin: false, //是否手机验证码
  220. computeTime: 0,
  221. active:1
  222. };
  223. },
  224. created() {
  225. this.getCode();
  226. this.getCookie();
  227. this.reset();
  228. },
  229. methods: {
  230. reset(){
  231. },
  232. showPopup(){
  233. this.showKeyboard = !this.showKeyboard
  234. },
  235. showMessagePop(){
  236. this.showMessage = !this.showMessage
  237. },
  238. getCode() {
  239. getCodeImg().then((res) => {
  240. this.formData.uuid = res.uuid;
  241. this.codeUrl = "data:image/gif;base64," + res.img;
  242. });
  243. },
  244. getCookie() {
  245. const username = Cookies.get("username");
  246. const password = Cookies.get("password");
  247. const rememberMe = Cookies.get("rememberMe");
  248. this.formData = {
  249. username: username === undefined ? this.formData.username : username,
  250. password:
  251. password === undefined ? this.formData.password : decrypt(password),
  252. rememberMe: rememberMe === undefined ? false : Boolean(rememberMe),
  253. };
  254. },
  255. getSmsCode() {
  256. if (this.formData.code == "") {
  257. this.$dialog.alert({
  258. message: '图片验证码不能为空',
  259. });
  260. return false;
  261. }
  262. if (!this.computeTime) {
  263. let myreg = /^[1][3,4,5,7,8,9][0-9]{9}$/;
  264. if (!myreg.test(this.formData.mobile)) {
  265. this.$dialog.alert({
  266. message: '手机号格式不正确',
  267. });
  268. return false;
  269. }
  270. /* getSmsCode(this.formData.mobile).then((res) => {
  271. if (res.code === 200) {
  272. this.$dialog.alert({
  273. message: '验证码已发送',
  274. });
  275. this.showKeyboard = !this.showKeyboard;
  276. this.loginForm.uuid = res.uuid;
  277. this.computeTime = 60;
  278. this.timer = setInterval(() => {
  279. this.computeTime--;
  280. if (this.computeTime <= 0) {
  281. clearInterval(this.timer);
  282. }
  283. }, 1000);
  284. }
  285. });*/
  286. }
  287. },
  288. handleLogin(values) {
  289. if (this.isSmsLogin) {
  290. //短信登录
  291. let myreg = /^[1][3,4,5,7,8,9][0-9]{9}$/;
  292. if (!myreg.test(this.formData.mobile)) {
  293. this.$dialog.alert({
  294. message: '手机号格式不正确',
  295. });
  296. return false;
  297. } else if (this.formData.smsCode == "") {
  298. this.$dialog.alert({
  299. message: '短信验证码不能为空',
  300. });
  301. return false;
  302. }
  303. this.loading = true;
  304. this.$store
  305. .dispatch("SmsLogin", this.formData)
  306. .then(() => {
  307. this.$router.push({ path: "/onlineHomeIndex" }).catch(() => {});
  308. })
  309. .catch((error) => {
  310. this.loading = false;
  311. });
  312. } else {
  313. if (this.formData.rememberMe) {
  314. Cookies.set("username", this.formData.username, { expires: 30 });
  315. Cookies.set("password", encrypt(this.formData.password), { expires: 30 });
  316. Cookies.set("rememberMe", this.formData.rememberMe, { expires: 30 });
  317. } else {
  318. Cookies.remove("username");
  319. Cookies.remove("password");
  320. Cookies.remove("rememberMe");
  321. }
  322. //账号密码登录
  323. if (this.formData.username == "") {
  324. this.$dialog.alert({
  325. message: '账号不能为空',
  326. });
  327. return false;
  328. } else if (this.formData.password == "") {
  329. this.$dialog.alert({
  330. message: '密码不能为空',
  331. });
  332. return false;
  333. } else if (!this.formData.code) {
  334. this.$dialog.alert({
  335. message: '图片验证码不能为空',
  336. });
  337. return false;
  338. }
  339. this.$store
  340. .dispatch("Login", this.formData)
  341. .then((resp) => {
  342. console.log(resp);
  343. this.$router.push({ path: "/onlineHome/workbench" }).catch(() => {});
  344. })
  345. .catch((error) => {
  346. console.log(error)
  347. this.loading = false;
  348. this.getCode();
  349. });
  350. }
  351. },
  352. getRegisterSmsCode(){
  353. if (!this.computeTime) {
  354. let myreg = /^[1][3,4,5,7,8,9][0-9]{9}$/;
  355. if (!myreg.test(this.formData.mobile)) {
  356. this.$dialog.alert({
  357. message: '手机号格式不正确',
  358. });
  359. return false;
  360. }else if (this.formData.code == "") {
  361. this.$dialog.alert({
  362. message: '图片验证码不能为空',
  363. });
  364. return false;
  365. }
  366. if (this.active==2) {
  367. let formObj = {
  368. code :this.formData.code,
  369. mobile:this.formData.mobile,
  370. uuid:this.formData.uuid
  371. }
  372. getRegisterSmsCode(formObj).then((res) => {
  373. console.log(res)
  374. console.log(res.code == 200)
  375. if(res.code == 200) {
  376. this.$dialog.alert({
  377. message: '验证码已发送',
  378. });
  379. this.formData.uuid = res.uuid;
  380. this.computeTime = 60;
  381. this.timer = setInterval(() => {
  382. this.computeTime--;
  383. if (this.computeTime <= 0) {
  384. clearInterval(this.timer);
  385. }
  386. }, 1000);
  387. }
  388. }).catch((res)=>{
  389. if(res=='Error: 验证码已失效'){
  390. this.getCode()
  391. }
  392. });
  393. }
  394. }
  395. },
  396. registerSubmit(){
  397. //注册
  398. if (this.formData.memberName == "") {
  399. this.$dialog.alert({
  400. message: '姓名不能为空',
  401. });
  402. return false;
  403. } else if (this.formData.idcard == "") {
  404. this.$dialog.alert({
  405. message: '身份证号不能为空',
  406. });
  407. return false;
  408. } else if (this.formData.mobile == "") {
  409. this.$dialog.alert({
  410. message: '手机号码不能为空',
  411. });
  412. return false;
  413. }else if (this.formData.smsCode == "") {
  414. this.$dialog.alert({
  415. message: '短信验证码不能为空',
  416. });
  417. return false;
  418. }
  419. //registerCheck,registerOn
  420. console.log(this.formData)
  421. registerCheck(this.formData).then((res)=>{
  422. if(res.code == 200){
  423. registerOn(this.formData).then((res)=>{
  424. if(res.code == 200){
  425. //
  426. this.$dialog.alert({
  427. message: '您的初始密码:'+res.password,
  428. }).then(() => {
  429. this.$router.push({ path: "/onlineHome/workbench" }).catch(() => {});
  430. });
  431. }
  432. })
  433. }
  434. })
  435. }
  436. },
  437. };
  438. </script>