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.

302 lines
9.7 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 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,
  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. })
  109. .catch((err) => {});
  110. // console.log(res);
  111. // if (res.data.code == 1 && res.code == 1) {
  112. // console.log(res.data.msg);
  113. // postapi()
  114. // let ress = await this.$axios.post(
  115. // mm.apiurl + "/connect/token",
  116. // {
  117. // client_id: "Peis_App",
  118. // grant_type: "password",
  119. // username: this.form.Username,
  120. // password: this.form.Password,
  121. // scope: "Peis offline_access",
  122. // },
  123. // {
  124. // headers: {
  125. // "Content-Type": "application/x-www-form-urlencoded",
  126. // },
  127. // }
  128. // );
  129. // if (ress.status == 200) {
  130. // writetoken(ress.data.expires_in);
  131. // window.localStorage.setItem("token", ress.data.access_token);
  132. // window.localStorage.setItem(
  133. // "refresh_token",
  134. // ress.data.refresh_token
  135. // );
  136. // window.localStorage.setItem("tokentype", ress.data.token_type);
  137. // window.localStorage.setItem("user", this.form.Username);
  138. // this.$message.success(res.data.msg, "登录成功");
  139. // this.$router.push({ path: "home" });
  140. // }
  141. // } else {
  142. // console.log();
  143. // this.$message.warning(res.data.msg);
  144. // }
  145. // } catch (err) {
  146. // console.log(err);
  147. // }
  148. // await getapi("/api/identity/users/login", {
  149. // username: this.form.Username,
  150. // password: this.form.Password,
  151. // }).then((ress) => {
  152. // if (ress.data.code == 1 && ress.code == 1) {
  153. // // console.log(msg);
  154. // postapi(mm.apiurl + "/connect/token", {
  155. // client_id: "Peis_App",
  156. // grant_type: "password",
  157. // username: this.form.Username,
  158. // password: this.form.Password,
  159. // scope: "Peis offline_access",
  160. // }).then((res) => {
  161. // console.log(res);
  162. // writetoken(res.data.expires_in);
  163. // window.localStorage.setItem("token", res.data.access_token);
  164. // window.localStorage.setItem(
  165. // "refresh_token",
  166. // res.data.refresh_token
  167. // );
  168. // window.localStorage.setItem("tokentype", res.data.token_type);
  169. // window.localStorage.setItem("user", this.form.Username);
  170. // this.$message.success("登录成功");
  171. // this.$router.push({ path: "home" });
  172. // this.$store.state.changepassword = this.form.Password;
  173. // });
  174. // } else {
  175. // this.$message.warning(res.data.msg);
  176. // }
  177. // });
  178. // this.$axios
  179. // .post(
  180. // mm.apiurl + "/connect/token",
  181. // {
  182. // client_id: "Peis_App",
  183. // grant_type: "password",
  184. // username: this.form.Username, //admin
  185. // password: this.form.Password, //1q2w3E
  186. // scope: "Peis offline_access",
  187. // },
  188. // {
  189. // headers: {
  190. // "Content-Type": "application/x-www-form-urlencoded",
  191. // },
  192. // }
  193. // )
  194. // .then((res) => {
  195. // console.log(res, "222222");
  196. // if (res.status == 200) {
  197. // //console.log(res.data)
  198. // writetoken(res.data.expires_in);
  199. // window.localStorage.setItem("token", res.data.access_token);
  200. // window.localStorage.setItem(
  201. // "refresh_token",
  202. // res.data.refresh_token
  203. // );
  204. // // window.localStorage.setItem("expires_in", res.data.expires_in);
  205. // window.localStorage.setItem("tokentype", res.data.token_type);
  206. // window.localStorage.setItem("user", this.form.Username);
  207. // this.$message.success("登录成功");
  208. // this.$router.push({ path: "home" });
  209. // // this.$store.dispatch('changepassword',this.form.Password)
  210. // this.$store.state.changepassword = this.form.Password;
  211. // } else {
  212. // this.$message.warning("用户名或密码错误");
  213. // }
  214. // });
  215. }
  216. });
  217. },
  218. tuichui() {
  219. let token = localStorage.getItem("token");
  220. let tokentype = localStorage.getItem("tokentype");
  221. this.$axios
  222. .get("http://192.168.1.108:44394/api/identity/users", {
  223. params: {
  224. SkipCount: 1,
  225. MaxResultCount: 1,
  226. },
  227. headers: {
  228. Authorization: `${tokentype} ${token}`,
  229. },
  230. })
  231. .then((res) => {
  232. console.log(res);
  233. });
  234. },
  235. users() {
  236. this.$axios.put(
  237. "http://192.168.1.108:44394/api/permission-management/permissions",
  238. {
  239. providerName: "R",
  240. providerKey: "sdsaf",
  241. }
  242. );
  243. },
  244. },
  245. created() {
  246. // let date = moment();
  247. // date.add(3600, 's');
  248. // console.log(parseInt(new Date(date).getTime() / 1000) + '')
  249. // // console.log(this.$moment);
  250. // console.log('33');
  251. // console.log(parseInt(new Date().getTime() / 1000) + '');
  252. },
  253. };
  254. </script>
  255. <style lang="scss" scoped>
  256. .bg {
  257. background-color: black;
  258. // background: url("https://img.zcool.cn/community/013c8b5b62d108a801206a35bea1eb.jpg@2o.jpg");1
  259. background: url("https://img1.baidu.com/it/u=1097534320,1746985227&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500");
  260. height: 100%;
  261. width: 100%;
  262. min-height: 100vh;
  263. }
  264. .box {
  265. width: 400px;
  266. height: 300px;
  267. display: flex;
  268. background: #fff;
  269. position: absolute;
  270. left: 50%;
  271. top: 50%;
  272. transform: translate(-50%, -50%);
  273. padding: 10px;
  274. }
  275. .mainbody {
  276. .title {
  277. width: 400px;
  278. text-align: center;
  279. font-weight: 700;
  280. font-size: 20px;
  281. }
  282. }
  283. .userform {
  284. margin-top: 20px;
  285. padding: 20px;
  286. }
  287. .btn {
  288. width: 100%;
  289. }
  290. </style>