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.

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