Login.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. <template>
  2. <div class="fle bgColor" v-if="!isSSo">
  3. <load-ing v-show="requesterLgoinType == 'wechat'"></load-ing>
  4. <h2
  5. v-if="requesterLgoinType == 'web'"
  6. style="font-size: 0.36rem; margin-bottom: 0.36rem; font-weight: 700"
  7. >
  8. 信息化故障报修
  9. </h2>
  10. <div v-if="requesterLgoinType == 'web'" style="width: 5rem">
  11. <cube-input
  12. v-model="zhanghao"
  13. placeholder="您的账号为工号或学号"
  14. ></cube-input>
  15. <br />
  16. <cube-input
  17. v-model="mima"
  18. type="password"
  19. placeholder="您的初始密码为学号或工号后四位"
  20. ></cube-input>
  21. <br />
  22. <cube-button @click="zlogin()" style="background: #005395"
  23. >登录</cube-button
  24. >
  25. </div>
  26. </div>
  27. </template>
  28. <script>
  29. import { decode } from "js-base64";
  30. import LoadIng from "./../views/loading.vue";
  31. export default {
  32. data() {
  33. return {
  34. zhanghao: "",
  35. mima: "",
  36. requesterLgoinType: "",
  37. isSSo: true // 是否单点登录
  38. };
  39. },
  40. components: {
  41. LoadIng
  42. },
  43. methods: {
  44. // 登陆
  45. login() {
  46. var that = this;
  47. that.$http.post("service/auth/wechatAuth", {}).then(res => {
  48. if (res.data.url) {
  49. window.location.href = res.data.url;
  50. } else {
  51. if (res.data.user) {
  52. localStorage.setItem(
  53. "loginUser",
  54. JSON.stringify(res.data.user.requester)
  55. );
  56. this.loginNext();
  57. }
  58. }
  59. });
  60. },
  61. // 获取code
  62. getCode() {
  63. var that = this;
  64. var url = window.location.href.split("?");
  65. if (!url[1]) {
  66. that.login();
  67. } else {
  68. var code = {
  69. code: url[1],
  70. // name: "微信报修"
  71. };
  72. that.$http.post("service/auth/wechatLoginEncrypt", code).then(res => {
  73. if (res.data.state == 200) {
  74. if (res.data.user) {
  75. localStorage.setItem(
  76. "loginUser",
  77. JSON.stringify(res.data.user.requester)
  78. );
  79. this.loginNext();
  80. }
  81. } else if (res.data.state == 501) {
  82. that
  83. .$createDialog({
  84. type: "alert",
  85. title: "您的账号被删除,请联系管理员",
  86. icon: "cubeic-alert"
  87. })
  88. .show();
  89. } else {
  90. that
  91. .$createDialog({
  92. type: "alert",
  93. title: res.data.remarks,
  94. icon: "cubeic-alert"
  95. })
  96. .show();
  97. }
  98. });
  99. }
  100. },
  101. loginNext() {
  102. // seimin
  103. // 获取报修主体
  104. this.$http
  105. .post("service/sysinfo/data/fetchDataList/systemConfiguration", {
  106. idx: 0,
  107. sum: 1000,
  108. systemConfiguration: { keyconfig: "repairMain" }
  109. })
  110. .then(result => {
  111. if (result.data.status == 200) {
  112. var repairMain = result.data.list[0];
  113. window.localStorage.setItem(
  114. "repairMain",
  115. JSON.stringify(repairMain)
  116. );
  117. // 获取是否自动建单
  118. this.$http
  119. .post("service/sysinfo/data/fetchDataList/systemConfiguration", {
  120. idx: 0,
  121. sum: 1000,
  122. systemConfiguration: { keyconfig: "reqHasCategory" }
  123. })
  124. .then(result => {
  125. if (result.data.status == 200) {
  126. var reqHasCategory = result.data.list[0];
  127. window.localStorage.setItem(
  128. "reqHasCategory",
  129. JSON.stringify(reqHasCategory)
  130. );
  131. this.$router.push({ path: "/main" });
  132. }
  133. });
  134. }
  135. });
  136. // seimin
  137. },
  138. // 获取报修人登录方式
  139. getLoginType() {
  140. this.$http.post("service/wechat/getLoginType", {}).then(result => {
  141. if (result.data.status == 200) {
  142. this.requesterLgoinType = result.data.data;
  143. window.localStorage.setItem(
  144. "requesterLgoinType",
  145. this.requesterLgoinType
  146. );
  147. if (this.requesterLgoinType == "wechat") {
  148. this.getCode();
  149. } else if (this.requesterLgoinType == "web") {
  150. // this.$router.push({ path: "/login" });
  151. }
  152. }
  153. });
  154. },
  155. // 账号密码登录
  156. zlogin() {
  157. console.log(this);
  158. var that = this;
  159. var ssoStr = "";
  160. var ssoJson;
  161. if (this.isSSo) {
  162. ssoStr = location.search
  163. .replace("?", "")
  164. .split("&")[0]
  165. .split("=")[1];
  166. ssoStr = decode(decodeURIComponent(ssoStr));
  167. ssoJson = JSON.parse(ssoStr);
  168. }
  169. var postData = this.isSSo
  170. ? { username: ssoJson.a, password: ssoJson.r, t: false }
  171. : { username: this.zhanghao, password: this.mima };
  172. this.$http.post("service/auth/reqlogin", postData).then(res => {
  173. that.loading = false;
  174. if (res.data && res.data.state == 200) {
  175. localStorage.setItem(
  176. "loginUser",
  177. JSON.stringify(res.data.data.requester)
  178. );
  179. localStorage.setItem(
  180. "loginConfig",
  181. JSON.stringify({ username: this.zhanghao, password: this.mima })
  182. );
  183. // 判断是否有区域地点或联系电话,没有则需要补充
  184. var requester = res.data.data.requester;
  185. if (!requester.place || !requester.mphone) {
  186. this.$router.push({ path: "/supplementary" });
  187. } else {
  188. this.loginNext();
  189. }
  190. } else {
  191. that
  192. .$createDialog({
  193. type: "alert",
  194. title: "系统错误",
  195. content: "请稍后再试",
  196. icon: "cubeic-wrong",
  197. color: "red"
  198. })
  199. .show();
  200. }
  201. });
  202. },
  203. // 获取查询参数
  204. getQueryString(name) {
  205.   var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
  206.   var r = window.location.search.substr(1).match(reg);
  207.   if (r != null){
  208. return unescape(r[2]);
  209. }
  210. return null;
  211. },
  212. },
  213. created() {
  214. localStorage.clear();
  215. if(location.search.length > 0){
  216. this.isSSo = Boolean(this.getQueryString('t'));
  217. }else{
  218. this.isSSo = false;
  219. }
  220. if (this.isSSo) {
  221. this.zlogin();
  222. }
  223. this.getLoginType();
  224. }
  225. };
  226. </script>
  227. <style scoped>
  228. .color {
  229. color: red;
  230. font-size: 1rem;
  231. }
  232. .fle {
  233. display: flex;
  234. height: 100vh;
  235. justify-content: center;
  236. align-items: center;
  237. flex-direction: column;
  238. background: url(./../../static/images/weChartBackImage.jpg);
  239. background-size: cover;
  240. }
  241. /* .bgColor{
  242. background-color: white
  243. } */
  244. input {
  245. border: 0.02rem #999999 solid;
  246. width: 60%;
  247. height: 0.8rem;
  248. margin-top: 0.4rem;
  249. border-radius: 10px;
  250. padding-left: 0.24rem;
  251. }
  252. input:nth-child(1) {
  253. margin-top: 0;
  254. }
  255. input:focus {
  256. outline: none;
  257. }
  258. .sub {
  259. width: 40%;
  260. background-color: rgb(60, 162, 254);
  261. height: 0.7rem;
  262. color: white;
  263. font-size: 0.36rem;
  264. text-align: center;
  265. line-height: 0.7rem;
  266. margin-top: 0.3rem;
  267. border-radius: 10px;
  268. }
  269. </style>