移动端
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

443 строки
14 KiB

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