Login.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. <template>
  2. <div class="fle bgColor" v-if="!isSSo || false">
  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. // 注意事项:个人微信需要关注微工作台,否则会导致没有userId(userId为openID)登录失败
  30. import { decode } from "js-base64";
  31. import LoadIng from "./../views/loading.vue";
  32. export default {
  33. data() {
  34. return {
  35. zhanghao: "",
  36. mima: "",
  37. requesterLgoinType: "",
  38. isSSo: true // 是否单点登录
  39. };
  40. },
  41. components: {
  42. LoadIng
  43. },
  44. methods: {
  45. // 登陆
  46. login() {
  47. var that = this;
  48. that.$http.post("service/auth/wechatAuth", {}).then(res => {
  49. if (res.data.url) {
  50. window.location.href = res.data.url;
  51. } else {
  52. console.log(res.data);
  53. if (res.data.user) {
  54. localStorage.setItem(
  55. "loginUser",
  56. JSON.stringify(res.data.user.user)
  57. );
  58. localStorage.setItem("menu", JSON.stringify(res.data.user.menu));
  59. localStorage.setItem(
  60. "login_requester",
  61. JSON.stringify(res.data.user.requester)
  62. );
  63. that.getConfig(res.data.user.user,res.data.user.requester);
  64. }
  65. }
  66. });
  67. },
  68. // 获取code
  69. getCode() {
  70. var that = this;
  71. var url = window.location.href.split("?");
  72. if (!url[1]) {
  73. that.login();
  74. } else {
  75. var code = {
  76. code: url[1]
  77. // name: "微信处理人"
  78. };
  79. // alert("2--传code参数:");
  80. // alert(JSON.stringify(code));
  81. that.$http.post("service/auth/wechatLoginEncrypt", code).then(res => {
  82. if (res.data.state == 200) {
  83. console.log(res.data);
  84. // alert(3);
  85. // alert(JSON.stringify(res.data));
  86. if (res.data.user) {
  87. localStorage.setItem(
  88. "loginUser",
  89. JSON.stringify(res.data.user.user)
  90. );
  91. localStorage.setItem("menu", JSON.stringify(res.data.user.menu));
  92. localStorage.setItem(
  93. "login_requester",
  94. JSON.stringify(res.data.user.requester)
  95. );
  96. that.getConfig(res.data.user.user,res.data.user.requester);
  97. }
  98. } else if (res.data.state == 501) {
  99. that
  100. .$createDialog({
  101. type: "alert",
  102. title: "您的账号被删除,请联系管理员",
  103. icon: "cubeic-alert"
  104. })
  105. .show();
  106. } else {
  107. that
  108. .$createDialog({
  109. type: "alert",
  110. title: res.data.remarks,
  111. icon: "cubeic-alert"
  112. })
  113. .show();
  114. }
  115. });
  116. }
  117. },
  118. // 获取版本配置(报修主题:报修人/报修科室)
  119. // 获取配置
  120. getConfig(user,requester) {
  121. this.$http
  122. .post("service/sysinfo/data/fetchDataList/systemConfiguration", {
  123. idx: 0,
  124. sum: 1000
  125. })
  126. .then(res => {
  127. let list = res.data.list;
  128. list.forEach(v => {
  129. switch (v.keyconfig) {
  130. case "repairMain": //报修主体
  131. localStorage.setItem(
  132. "valConfig",
  133. JSON.stringify(v.valueconfig)
  134. );
  135. break;
  136. case "incidentWithConsumable": //是否绑定耗材
  137. localStorage.setItem("incidentWithConsumable", v.valueconfig);
  138. break;
  139. case "wxIncidentWithCmdb": //是否绑定资产
  140. localStorage.setItem("wxIncidentWithCmdb", v.valueconfig);
  141. break;
  142. case "ifWorking": //是否开通上下班
  143. localStorage.setItem("ifWorking", v.valueconfig);
  144. break;
  145. // case "wxBxQuestions": //微信报修常见问题链接
  146. // localStorage.setItem("wxBxQuestions", v.valueconfig);
  147. // break;
  148. // case "wxGuide": //微信报修服务指南链接
  149. // localStorage.setItem("wxGuide", v.valueconfig);
  150. // break;
  151. case "wxClQuestions": //微信处理常见问题链接
  152. localStorage.setItem("wxClQuestions", v.valueconfig);
  153. break;
  154. case "ifRoom": //是否增加房间号选择
  155. localStorage.setItem("ifRoom", v.valueconfig);
  156. break;
  157. case "integralMechanism": //积分机制
  158. localStorage.setItem("integralMechanism", v.valueconfig);
  159. break;
  160. case "integralRole": //积分控制角色
  161. sessionStorage.setItem("integralRole", v.valueconfig);
  162. break;
  163. }
  164. });
  165. this.roleHandler(user,requester);
  166. });
  167. },
  168. // 判断角色
  169. roleHandler(user,requester){
  170. let userRoles = user.role.map(v=>({id:v.id,rolecode:v.rolecode}));
  171. let isUser = false;
  172. if(userRoles.length){
  173. // this.isService = userRoles.some(v=>(v.rolecode === 'call center' || v.rolecode === 'call center admin'))
  174. isUser = userRoles.some(v=>(v.rolecode === 'first-line support' || v.rolecode === 'second-line support' || v.rolecode === 'incident manager' || v.rolecode === 'inspectman' || v.rolecode === 'incident-category-manager'))
  175. }else{
  176. // this.isService = false;
  177. isUser = false;
  178. }
  179. // this.isReq = requester ? true : false;
  180. if(isUser){
  181. this.$router.push({ path: "/main" });
  182. }else{
  183. this.$createDialog({
  184. type: "alert",
  185. title: "提示",
  186. content: "没有权限,无法进入!",
  187. icon: "cubeic-wrong",
  188. color: "red"
  189. }).show();
  190. }
  191. },
  192. // 获取报修人登录方式
  193. getLoginType() {
  194. this.$http.post("service/wechat/getLoginType", {}).then(result => {
  195. if (result.data.status == 200) {
  196. this.requesterLgoinType = result.data.data;
  197. window.localStorage.setItem(
  198. "requesterLgoinType",
  199. this.requesterLgoinType
  200. );
  201. if (this.requesterLgoinType == "wechat") {
  202. this.getCode();
  203. } else if (this.requesterLgoinType == "web") {
  204. // this.$router.push({ path: "/login" });
  205. }
  206. }
  207. });
  208. },
  209. // 账号密码登录
  210. zlogin() {
  211. console.log(this);
  212. var that = this;
  213. var ssoStr = "";
  214. var ssoJson;
  215. if (this.isSSo) {
  216. ssoStr = location.search
  217. .replace("?", "")
  218. .split("&")[0]
  219. .split("=")[1];
  220. ssoStr = decode(decodeURIComponent(ssoStr));
  221. ssoJson = JSON.parse(ssoStr);
  222. }
  223. var postData = this.isSSo
  224. ? { username: ssoJson.a, password: ssoJson.u, t: false }
  225. : { username: this.zhanghao, password: this.mima };
  226. this.$http.post("service/auth/loginEncrypt", postData).then(res => {
  227. that.loading = false;
  228. if (res.data && res.data.state == 200) {
  229. localStorage.setItem("loginUser", JSON.stringify(res.data.data.user));
  230. localStorage.setItem("menu", JSON.stringify(res.data.data.menu));
  231. localStorage.setItem(
  232. "login_requester",
  233. JSON.stringify(res.data.data.requester)
  234. );
  235. this.getConfig(res.data.data.user,res.data.data.requester);
  236. } else {
  237. that
  238. .$createDialog({
  239. type: "alert",
  240. title: "系统错误",
  241. content: "请稍后再试",
  242. icon: "cubeic-wrong",
  243. color: "red"
  244. })
  245. .show();
  246. }
  247. });
  248. },
  249. // 获取查询参数
  250. getQueryString(name) {
  251. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
  252. var r = window.location.search.substr(1).match(reg);
  253. if (r != null) {
  254. return unescape(r[2]);
  255. }
  256. return null;
  257. }
  258. },
  259. created() {
  260. if (location.search.length > 0) {
  261. this.isSSo = Boolean(this.getQueryString("t"));
  262. } else {
  263. this.isSSo = false;
  264. }
  265. if (this.isSSo) {
  266. this.zlogin();
  267. }
  268. this.getLoginType();
  269. }
  270. };
  271. </script>
  272. <style scoped>
  273. .color {
  274. color: red;
  275. font-size: 1rem;
  276. }
  277. .fle {
  278. display: flex;
  279. height: 100vh;
  280. justify-content: center;
  281. align-items: center;
  282. flex-direction: column;
  283. background: url(./../../static/images/weChartBackImage.jpg);
  284. background-size: cover;
  285. }
  286. /* .bgColor{
  287. background-color: white
  288. } */
  289. input {
  290. border: 0.02rem #999999 solid;
  291. width: 60%;
  292. height: 0.8rem;
  293. margin-top: 0.4rem;
  294. border-radius: 10px;
  295. padding-left: 0.24rem;
  296. }
  297. input:nth-child(1) {
  298. margin-top: 0;
  299. }
  300. input:focus {
  301. outline: none;
  302. }
  303. .sub {
  304. width: 40%;
  305. background-color: rgb(60, 162, 254);
  306. height: 0.7rem;
  307. color: white;
  308. font-size: 0.36rem;
  309. text-align: center;
  310. line-height: 0.7rem;
  311. margin-top: 0.3rem;
  312. border-radius: 10px;
  313. }
  314. </style>