You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

305 lines
9.8 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
  1. <template>
  2. <div class="bg">
  3. <div class="box">
  4. <div class="mainbody">
  5. <div class="title">系统登录</div>
  6. <div class="userform">
  7. <el-form
  8. :model="form"
  9. :rules="rules"
  10. ref="form"
  11. class="demo-ruleForm"
  12. >
  13. <el-form-item label="" prop="Username">
  14. <el-input
  15. v-model="form.Username"
  16. placeholder="用户名"
  17. prefix-icon="el-icon-s-custom"
  18. ></el-input>
  19. </el-form-item>
  20. <el-form-item label="" prop="Password">
  21. <el-input
  22. v-model="form.Password"
  23. placeholder="密码"
  24. type="password"
  25. prefix-icon="el-icon-unlock"
  26. ></el-input>
  27. </el-form-item>
  28. <el-button type="primary" class="btn" @click="onSubmit(form)"
  29. >用户登录</el-button
  30. >
  31. </el-form>
  32. </div>
  33. </div>
  34. </div>
  35. </div>
  36. </template>
  37. <script>
  38. import { lognis } from "@/request/ruquset";
  39. import { yzstr } from "@/utlis/validate.js";
  40. import { yztoken, writetoken } from "@/utlis/istoken";
  41. import mm from "@/utlis/mm";
  42. import { getapi, postapi } from "@/api/api";
  43. export default {
  44. data() {
  45. return {
  46. form: {
  47. Username: "",
  48. Password: "",
  49. },
  50. rules: {
  51. Username: [
  52. { required: true, message: "请输入用户名", trigger: "blur" },
  53. { min: 3, max: 5, message: "长度在 3 到 5 个字符", trigger: "blur" },
  54. ],
  55. Password: [
  56. { required: true, message: "请输入密码", trigger: "blur" },
  57. { min: 3, max: 8, message: "长度在 3 到 5 个字符", trigger: "blur" },
  58. ],
  59. },
  60. };
  61. },
  62. methods: {
  63. onSubmit() {
  64. this.$refs.form.validate((valid) => {
  65. if (valid) {
  66. // let res = await getapi("/api/identity/users/login", {
  67. // username: this.form.Username,
  68. // password: this.form.Password,11
  69. // });
  70. var msgs = "";
  71. getapi("/api/identity/users/login", {
  72. username: this.form.Username,
  73. password: this.form.Password,
  74. })
  75. .then((ret) => {
  76. msgs = ret.data.msg;
  77. if (ret.code != -1 && ret.data.code == 1 && ret.code == 1) {
  78. return this.$axios.post(
  79. mm.apiurl + "/connect/token",
  80. {
  81. client_id: "Peis_App",
  82. grant_type: "password",
  83. username: this.form.Username,
  84. password: this.form.Password,
  85. scope: "Peis offline_access",
  86. },
  87. {
  88. headers: {
  89. "Content-Type": "application/x-www-form-urlencoded",
  90. },
  91. }
  92. );
  93. } else {
  94. this.$message.warning(ret.data.msg);
  95. }
  96. })
  97. .then((res) => {
  98. writetoken(res.data.expires_in);
  99. window.localStorage.setItem("token", res.data.access_token);
  100. window.localStorage.setItem(
  101. "refresh_token",
  102. res.data.refresh_token
  103. );
  104. window.localStorage.setItem("tokentype", res.data.token_type);
  105. window.localStorage.setItem("user", this.form.Username);
  106. this.$message.success(msgs,+"登录成功");
  107. this.$router.push({ path: "home" });
  108. this.$store.state.changepassword = this.form.Password;
  109. })
  110. .catch((err) => {});
  111. // console.log(res);
  112. // if (res.data.code == 1 && res.code == 1) {
  113. // console.log(res.data.msg);
  114. // postapi()
  115. // let ress = await this.$axios.post(
  116. // mm.apiurl + "/connect/token",
  117. // {
  118. // client_id: "Peis_App",
  119. // grant_type: "password",
  120. // username: this.form.Username,
  121. // password: this.form.Password,
  122. // scope: "Peis offline_access",
  123. // },
  124. // {
  125. // headers: {
  126. // "Content-Type": "application/x-www-form-urlencoded",
  127. // },
  128. // }
  129. // );
  130. // if (ress.status == 200) {
  131. // writetoken(ress.data.expires_in);
  132. // window.localStorage.setItem("token", ress.data.access_token);
  133. // window.localStorage.setItem(
  134. // "refresh_token",
  135. // ress.data.refresh_token
  136. // );
  137. // window.localStorage.setItem("tokentype", ress.data.token_type);
  138. // window.localStorage.setItem("user", this.form.Username);
  139. // this.$message.success(res.data.msg, "登录成功");
  140. // this.$router.push({ path: "home" });
  141. // }
  142. // } else {
  143. // console.log();
  144. // this.$message.warning(res.data.msg);
  145. // }
  146. // } catch (err) {
  147. // console.log(err);
  148. // }
  149. // await getapi("/api/identity/users/login", {
  150. // username: this.form.Username,
  151. // password: this.form.Password,
  152. // }).then((ress) => {
  153. // if (ress.data.code == 1 && ress.code == 1) {
  154. // // console.log(msg);
  155. // postapi(mm.apiurl + "/connect/token", {
  156. // client_id: "Peis_App",
  157. // grant_type: "password",
  158. // username: this.form.Username,
  159. // password: this.form.Password,
  160. // scope: "Peis offline_access",
  161. // }).then((res) => {
  162. // console.log(res);
  163. // writetoken(res.data.expires_in);
  164. // window.localStorage.setItem("token", res.data.access_token);
  165. // window.localStorage.setItem(
  166. // "refresh_token",
  167. // res.data.refresh_token
  168. // );
  169. // window.localStorage.setItem("tokentype", res.data.token_type);
  170. // window.localStorage.setItem("user", this.form.Username);
  171. // this.$message.success("登录成功");
  172. // this.$router.push({ path: "home" });
  173. // this.$store.state.changepassword = this.form.Password;
  174. // });
  175. // } else {
  176. // this.$message.warning(res.data.msg);
  177. // }
  178. // });
  179. // this.$axios
  180. // .post(
  181. // mm.apiurl + "/connect/token",
  182. // {
  183. // client_id: "Peis_App",
  184. // grant_type: "password",
  185. // username: this.form.Username, //admin
  186. // password: this.form.Password, //1q2w3E
  187. // scope: "Peis offline_access",
  188. // },
  189. // {
  190. // headers: {
  191. // "Content-Type": "application/x-www-form-urlencoded",
  192. // },
  193. // }
  194. // )
  195. // .then((res) => {
  196. // console.log(res, "222222");
  197. // if (res.status == 200) {
  198. // //console.log(res.data)
  199. // writetoken(res.data.expires_in);
  200. // window.localStorage.setItem("token", res.data.access_token);
  201. // window.localStorage.setItem(
  202. // "refresh_token",
  203. // res.data.refresh_token
  204. // );
  205. // // window.localStorage.setItem("expires_in", res.data.expires_in);
  206. // window.localStorage.setItem("tokentype", res.data.token_type);
  207. // window.localStorage.setItem("user", this.form.Username);
  208. // this.$message.success("登录成功");
  209. // this.$router.push({ path: "home" });
  210. // // this.$store.dispatch('changepassword',this.form.Password)
  211. // this.$store.state.changepassword = this.form.Password;
  212. // } else {
  213. // this.$message.warning("用户名或密码错误");
  214. // }
  215. // });
  216. }
  217. });
  218. },
  219. tuichui() {
  220. let token = localStorage.getItem("token");
  221. let tokentype = localStorage.getItem("tokentype");
  222. this.$axios
  223. .get("http://192.168.1.108:44394/api/identity/users", {
  224. params: {
  225. SkipCount: 1,
  226. MaxResultCount: 1,
  227. },
  228. headers: {
  229. Authorization: `${tokentype} ${token}`,
  230. },
  231. })
  232. .then((res) => {
  233. console.log(res);
  234. });
  235. },
  236. users() {
  237. this.$axios.put(
  238. "http://192.168.1.108:44394/api/permission-management/permissions",
  239. {
  240. providerName: "R",
  241. providerKey: "sdsaf",
  242. }
  243. );
  244. },
  245. },
  246. created() {
  247. // let date = moment();
  248. // date.add(3600, 's');
  249. // console.log(parseInt(new Date(date).getTime() / 1000) + '')
  250. // // console.log(this.$moment);
  251. // console.log('33');
  252. // console.log(parseInt(new Date().getTime() / 1000) + '');
  253. },
  254. };
  255. </script>
  256. <style lang="scss" scoped>
  257. .bg {
  258. background-color: black;
  259. // background: url("https://img.zcool.cn/community/013c8b5b62d108a801206a35bea1eb.jpg@2o.jpg");1
  260. background: url("https://img1.baidu.com/it/u=1097534320,1746985227&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500");
  261. height: 100%;
  262. width: 100%;
  263. min-height: 100vh;
  264. }
  265. .box {
  266. width: 400px;
  267. height: 300px;
  268. display: flex;
  269. background: #fff;
  270. position: absolute;
  271. left: 50%;
  272. top: 50%;
  273. transform: translate(-50%, -50%);
  274. padding: 10px;
  275. }
  276. .mainbody {
  277. .title {
  278. width: 400px;
  279. text-align: center;
  280. font-weight: 700;
  281. font-size: 20px;
  282. }
  283. }
  284. .userform {
  285. margin-top: 20px;
  286. padding: 20px;
  287. }
  288. .btn {
  289. width: 100%;
  290. }
  291. </style>