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

359 строки
11 KiB

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