login.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. <template>
  2. <div class="login_content">
  3. <div class="login_box" v-show="islogin">
  4. <div style="padding: 0px 20px">
  5. <div class="login_title">
  6. <span>广东省案例征集</span>
  7. </div>
  8. <el-form
  9. label-position="right"
  10. label-width="80px"
  11. style="margin-top: 30px"
  12. >
  13. <el-form-item label="账号">
  14. <el-input
  15. v-model="phoneNum"
  16. auto-complete="off"
  17. placeholder="请输入账号"
  18. style="width: 100%"
  19. @keyup.enter.native="findPhone"
  20. ></el-input>
  21. </el-form-item>
  22. <el-form-item label="密码">
  23. <el-input
  24. v-model="password"
  25. auto-complete="off"
  26. placeholder="请输入密码"
  27. type="password"
  28. style="width: 100%"
  29. @keyup.enter.native="findPhone"
  30. ></el-input>
  31. </el-form-item>
  32. </el-form>
  33. <div style="display: flex; justify-content: flex-end">
  34. <el-button type="text" @click="noRegister">立即注册</el-button>
  35. <!-- @click="goTo('/register')" -->
  36. </div>
  37. <div class="login_button">
  38. <button @click="findPhone()">登录</button>
  39. </div>
  40. </div>
  41. </div>
  42. <div class="login_box" v-show="!islogin">
  43. <div style="padding: 0px 20px">
  44. <div class="login_title">
  45. <span>PBL项目平台注册</span>
  46. </div>
  47. <!-- <div class="userLogin">
  48. <img src="../assets/username.png" />
  49. <el-input v-model="phoneNum" placeholder="手机号码"></el-input>
  50. </div>
  51. <div class="userLogin">
  52. <img src="../assets/password.png" />
  53. <el-input v-model="password" placeholder="密码" type="password"></el-input>
  54. </div> -->
  55. <el-form
  56. label-position="right"
  57. label-width="80px"
  58. style="margin-top: 30px"
  59. :rules="rules2"
  60. ref="ruleForm2"
  61. :model="registerForm"
  62. >
  63. <el-form-item label="手机号码" prop="phone">
  64. <el-input
  65. v-model="registerForm.rphoneNum"
  66. auto-complete="off"
  67. placeholder="请输入手机号码"
  68. style="width: 100%"
  69. ></el-input>
  70. </el-form-item>
  71. <el-form-item label="密码" prop="pass">
  72. <el-input
  73. v-model="registerForm.rpassword"
  74. auto-complete="off"
  75. placeholder="请输入密码"
  76. type="password"
  77. style="width: 100%"
  78. ></el-input>
  79. </el-form-item>
  80. <el-form-item label="确认密码" prop="checkPass">
  81. <el-input
  82. v-model="registerForm.repassword"
  83. auto-complete="off"
  84. placeholder="请再输入一遍密码"
  85. type="password"
  86. style="width: 100%"
  87. ></el-input>
  88. </el-form-item>
  89. <el-form-item label="学校" prop="school">
  90. <el-select v-model="registerForm.school" placeholder="请选择学校">
  91. <el-option
  92. v-for="(item, index) in schoolArray"
  93. :key="index"
  94. :label="item.name"
  95. :value="item.id"
  96. >
  97. </el-option>
  98. </el-select>
  99. </el-form-item>
  100. </el-form>
  101. <div style="display: flex; justify-content: flex-end">
  102. <el-button type="text" @click="islogin = true">返回登录</el-button>
  103. </div>
  104. <div class="login_button">
  105. <button @click="register()">注册</button>
  106. </div>
  107. </div>
  108. </div>
  109. </div>
  110. </template>
  111. <script>
  112. export default {
  113. data() {
  114. var validatePass = (rule, value, callback) => {
  115. var _this = this;
  116. if (_this.registerForm.rpassword === "") {
  117. callback(new Error("请输入密码"));
  118. } else {
  119. if (_this.registerForm.rpassword.length < 6) {
  120. callback(new Error("输入的密码需不少于6位"));
  121. } else if (_this.registerForm.repassword !== "") {
  122. _this.$refs.ruleForm2.validateField("checkPass");
  123. }
  124. callback();
  125. }
  126. };
  127. var validatePass2 = (rule, value, callback) => {
  128. var _this = this;
  129. if (_this.registerForm.repassword === "") {
  130. callback(new Error("请再次输入密码"));
  131. } else if (
  132. _this.registerForm.repassword !== _this.registerForm.rpassword
  133. ) {
  134. callback(new Error("两次输入密码不一致!"));
  135. } else {
  136. callback();
  137. }
  138. };
  139. // 验证手机
  140. var checkPhone = (rule, value, callback) => {
  141. var _this = this;
  142. let reg = /^1\d{10}$/;
  143. if (_this.registerForm.rphoneNum === "") {
  144. callback(new Error("请输入手机号码"));
  145. } else {
  146. if (!reg.test(_this.registerForm.rphoneNum)) {
  147. callback(new Error("请输入11位手机号"));
  148. } else {
  149. let params = { un: _this.registerForm.rphoneNum };
  150. this.ajax
  151. .get(this.$store.state.api + "findPhone", params)
  152. .then((res) => {
  153. if (res.data[0].length > 0) {
  154. callback(new Error("此手机号已注册"));
  155. } else {
  156. callback();
  157. }
  158. console.log(res.data[0]);
  159. })
  160. .catch((err) => {
  161. callback();
  162. console.error(err);
  163. });
  164. }
  165. }
  166. };
  167. return {
  168. islogin: true,
  169. phoneNum: "",
  170. password: "",
  171. sqlPassword: "",
  172. registerForm: {
  173. rphoneNum: "",
  174. rpassword: "",
  175. repassword: "",
  176. school: "",
  177. },
  178. schoolArray: [],
  179. now: "",
  180. rules2: {
  181. phone: [
  182. {
  183. required: true,
  184. type: "number",
  185. validator: checkPhone,
  186. trigger: ["blur", "change"],
  187. },
  188. ],
  189. pass: [{ required: true, validator: validatePass, trigger: "blur" }],
  190. checkPass: [
  191. { required: true, validator: validatePass2, trigger: "blur" },
  192. ],
  193. school: [
  194. { required: true, message: "请选择活动区域", trigger: "blur" },
  195. ],
  196. },
  197. userInfo: [],
  198. };
  199. },
  200. created() {
  201. // this.getOrg();
  202. this.getSchool();
  203. },
  204. methods: {
  205. time() {
  206. if (!this.now) {
  207. this.now = new Date().getTime();
  208. return true;
  209. } else {
  210. let time = new Date().getTime();
  211. if (time - this.now > 3000) {
  212. this.now = time;
  213. return true;
  214. } else {
  215. return false;
  216. }
  217. }
  218. },
  219. register() {
  220. this.$refs.ruleForm2.validate((valid) => {
  221. if (valid) {
  222. if (this.time()) {
  223. let params = [
  224. {
  225. username: this.registerForm.rphoneNum,
  226. userpassword: this.registerForm.repassword,
  227. oid: this.registerForm.school,
  228. },
  229. ];
  230. this.ajax
  231. .post(this.$store.state.api + "register", params)
  232. .then((res) => {
  233. this.$message({
  234. message: "注册成功",
  235. type: "success",
  236. });
  237. this.registerForm = {
  238. rphoneNum: "",
  239. rpassword: "",
  240. repassword: "",
  241. school: "",
  242. };
  243. this.islogin = true;
  244. })
  245. .catch((err) => {
  246. this.$message.error("注册失败");
  247. console.error(err);
  248. });
  249. }
  250. } else {
  251. return false;
  252. }
  253. });
  254. },
  255. goTo(path) {
  256. this.$router.push(path);
  257. },
  258. findPhone() {
  259. let params = { un: this.phoneNum };
  260. this.ajax
  261. .get(this.$store.state.api + "findUsername", params)
  262. .then((res) => {
  263. if (res.data[0].length > 0) {
  264. // if (res.data[0][0].type == 0) {
  265. // this.$message.error("此账号已被屏蔽登录,请咨询管理员");
  266. // return;
  267. // }
  268. this.isU = res.data[0][0].type;
  269. this.login();
  270. } else {
  271. this.$message.error("此账号不存在");
  272. return;
  273. this.isU = false;
  274. }
  275. console.log(res.data[0][0]);
  276. })
  277. .catch((err) => {
  278. console.error(err);
  279. });
  280. },
  281. login() {
  282. if (this.time()) {
  283. var _this = this;
  284. let isU = _this.isU;
  285. let params = [
  286. {
  287. uname: this.phoneNum,
  288. password: this.password,
  289. // sqlpassword: this.sqlPassword,
  290. },
  291. ];
  292. _this.ajax
  293. .post(_this.$store.state.api + "loginRace", params)
  294. .then((res) => {
  295. if (res.data.status == "1") {
  296. _this.$message({
  297. message: "登录成功",
  298. type: "success",
  299. });
  300. _this.userInfo = res.data[0][0];
  301. _this.$cookies.set("tlogin", "1", -1);
  302. _this.$cookies.set("tuserid", _this.userInfo.userid, -1);
  303. _this.$cookies.set("teacherInfo", _this.userInfo, -1);
  304. // window.sessionStorage.setItem("login", true);
  305. // window.sessionStorage.setItem("userInfo", JSON.stringify(this.userInfo));
  306. _this.$store.commit("update", ["isLogin", true]);
  307. _this.$store.commit("update", ["userInfo", _this.userInfo]);
  308. if (isU == 1) {
  309. this.$router.push("/eventCenter?steps=" + "1");
  310. } else if (isU == 2 || isU == 4) {
  311. //市级账号 munAdmin
  312. this.$router.push("/anliList");
  313. } else if (isU == 5 || isU == 6) {
  314. //区县账号 disAdmin
  315. this.$router.push("/anliList1");
  316. } else if (isU == 3) {
  317. //省级账号 proAdmin
  318. this.$router.push("/anliList2");
  319. } else if (isU == 0) {
  320. //admin账号
  321. this.$router.push("/eventCenter?steps=" + "1");
  322. }
  323. // console.log(_this.$store.state);
  324. } else {
  325. this.$message.error("密码错误");
  326. }
  327. console.log(res.data);
  328. })
  329. .catch((err) => {
  330. this.$message.error("登录失败");
  331. console.error(err);
  332. });
  333. }
  334. // sessionStorage.removeItem("key");
  335. },
  336. //查询学校
  337. // getOrg() {
  338. // this.ajax
  339. // .get(this.$store.state.api + "getAllOrg", "")
  340. // .then((res) => {
  341. // this.schoolArray = res.data[0];
  342. // console.log(res.data[0]);
  343. // })
  344. // .catch((err) => {
  345. // console.error(err);
  346. // });
  347. // },
  348. getSchool() {
  349. this.ajax
  350. .get(this.$store.state.api + "selectOrg", "")
  351. .then((res) => {
  352. this.schoolArray = res.data[0];
  353. })
  354. .catch((err) => {
  355. console.error(err);
  356. });
  357. },
  358. noRegister() {
  359. this.$message({
  360. message: "暂未开放注册,提交资料请与各地区负责人联系。",
  361. type: "warning",
  362. });
  363. },
  364. },
  365. };
  366. </script>
  367. <style scoped>
  368. .login_content {
  369. display: flex;
  370. align-items: center;
  371. justify-content: center;
  372. height: 100%;
  373. /* position: absolute; */
  374. width: 100%;
  375. }
  376. .login_box {
  377. width: 23%;
  378. min-width: 400px;
  379. margin: 0 auto;
  380. background: #fff;
  381. padding: 20px;
  382. box-shadow: 0 0 20px #eee;
  383. }
  384. /* .userLogin img {
  385. width: 50%;
  386. display: inline-block;
  387. width: 18px;
  388. padding-right: 5px;
  389. border-right: 1px solid #2a97ff;
  390. position: absolute;
  391. top: 8px;
  392. left: 10px;
  393. z-index: 999;
  394. } */
  395. /* .el-input >>> input {
  396. width: 100%;
  397. padding: 15px 0 15px 40px;
  398. outline: none;
  399. border: 1px solid #ccc;
  400. font-size: 14px;
  401. } */
  402. /* .userLogin {
  403. margin-top: 25px;
  404. position: relative;
  405. } */
  406. .login_button {
  407. margin-top: 10px;
  408. }
  409. .login_button button {
  410. width: 100%;
  411. color: #fff;
  412. background: #2a97ff;
  413. padding: 10px;
  414. border-radius: 10px;
  415. border: none;
  416. font-size: 18px;
  417. text-align: center;
  418. outline: none;
  419. cursor: pointer;
  420. }
  421. .login_title {
  422. text-align: center;
  423. font-size: 26px;
  424. font-weight: 600;
  425. }
  426. </style>