login.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <template>
  2. <div class="bg">
  3. <el-form :rules="rules" ref="loginForm" :model="loginForm" class="loginContainer">
  4. <h3 class="loginTitle">
  5. Emdoor可视化平台
  6. </h3>
  7. <el-form-item prop="sob">
  8. <el-select v-model="loginForm.sob" placeholder="请选择账套" style="width:100%">
  9. <el-option
  10. v-for="item in options"
  11. :key="item.value"
  12. :label="item.label"
  13. :value="item.value">
  14. </el-option>
  15. </el-select>
  16. </el-form-item>
  17. <el-form-item prop="workshop">
  18. <el-select v-model="loginForm.type" placeholder="请选择看板类型" style="width:100%">
  19. <el-option
  20. v-for="item in typeoptions"
  21. :key="item.value"
  22. :label="item.label"
  23. :value="item.value">
  24. </el-option>
  25. </el-select>
  26. </el-form-item>
  27. <el-form-item prop="factory">
  28. <el-select v-model="loginForm.factory" placeholder="请选择厂区" style="width:100%">
  29. <el-option
  30. v-for="item in factoryoptions"
  31. :key="item.value"
  32. :label="item.label"
  33. :value="item.value">
  34. </el-option>
  35. </el-select>
  36. </el-form-item>
  37. <el-form-item prop="username">
  38. <el-input type="text" v-model="loginForm.username" placeholder="请输入用户名" >
  39. </el-input>
  40. </el-form-item>
  41. <el-form-item prop="password">
  42. <el-input type="password" v-model="loginForm.password" placeholder="请输入密码" >
  43. </el-input>
  44. </el-form-item>
  45. <el-checkbox v-model="checked" class="loginRemember">记住我</el-checkbox>
  46. <el-button type="primary" style="width:100%" @click="submitLogin">登录</el-button>
  47. </el-form>
  48. </div>
  49. </template>
  50. <script>
  51. import CryptoJS from "crypto-js";
  52. export default {
  53. name: "Login",
  54. data(){
  55. return{
  56. captchaUrl: "",
  57. loginForm:{
  58. sob:"",
  59. username:"",
  60. password:"",
  61. type:"产线看板",
  62. factory:""
  63. },
  64. checked: true,
  65. rules:{
  66. sob :[{required:true,message:"请选择账套",trigger:"blur"}],
  67. username:[{required:true,message:"请输入用户名",trigger:"blur"}/*,{ min: 5, max: 14, message: '长度在 5 到 14 个字符', trigger: 'blur' }*/],
  68. password:[{required:true,message:"请输入密码",trigger:"blur"} /*,{ min: 6, message: '密码长度要大于6', trigger: 'blur' }*/],
  69. type:[{required:true,message:"请选择看板类型",trigger:"blur"}]
  70. },
  71. options: [],
  72. typeoptions:[
  73. //车间看板、产线看板、品质看板、设备看板
  74. {label: '车间看板', value: '车间看板'},
  75. {label: '产线看板', value: '产线看板'},
  76. {label: '品质看板', value: '品质看板'},
  77. {label: '仓库看板', value: '仓库看板'},
  78. /* {label: '设备看板', value: '设备看板'}*/
  79. ],
  80. factoryoptions:[], //产区
  81. }
  82. },
  83. created() {
  84. //默认数据
  85. this.getCookies();
  86. //获取账套信息
  87. this.getMasters();
  88. //获取厂区信息
  89. this.getFactory();
  90. },
  91. mounted() {
  92. //监听enter键
  93. this.$refs.loginForm.$el.addEventListener('keydown',this.handleEnter);
  94. },
  95. beforeDestroy(){
  96. this.$refs.loginForm.$el.removeEventListener('keydown',this.handleEnter);
  97. },
  98. methods:{
  99. //获取账套
  100. getMasters(){
  101. this.$http.get("kanban/getAllMasters.action").then(
  102. (result)=>{
  103. var res = JSON.parse(JSON.stringify(result.data.masters));
  104. for (let i = 0; i < res.length; i++) {
  105. this.options.push({label: res[i].ma_function, value: res[i].ma_user});
  106. }
  107. //设置默认值
  108. if("" == this.loginForm.sob || !result.data.masters.some(item => item.ma_function === this.loginForm.sob) ){
  109. this.loginForm.sob = res[0].ma_user;
  110. }
  111. },(result)=>{
  112. console.error(result)
  113. });
  114. },
  115. getFactory(){
  116. this.$http.get("kanban/getFactory.action").then(
  117. (result)=>{
  118. var res = JSON.parse(JSON.stringify(result.data.factories));
  119. for (let i = 0; i < res.length; i++) {
  120. this.factoryoptions.push({label: res[i].FA_NAME, value: res[i].FA_NAME});
  121. }
  122. //设置默认值
  123. if("" == this.loginForm.factory || !result.data.factories.some(item => item.FA_NAME === this.loginForm.factory) ){
  124. this.loginForm.factory = res[0].FA_NAME;
  125. }
  126. },(result)=>{
  127. console.error(result)
  128. });
  129. },
  130. //登录操作
  131. submitLogin(){
  132. this.$refs.loginForm.validate((valid) => {
  133. if (valid) {
  134. // console.log('登录',this.loginForm);
  135. //?username=zhongyl&password=asd&sob=N_MES_TEST
  136. this.$http.get("kanban/login.action",{
  137. params:{
  138. username:this.loginForm.username,
  139. password:CryptoJS.AES.encrypt(this.loginForm.password, "123456"), //密码加密传递
  140. sob:this.loginForm.sob,
  141. type:this.loginForm.type,
  142. factory:this.loginForm.factory
  143. }}).then(
  144. (result)=>{
  145. var res = result.data;
  146. if(res.success || "检测到您已登录本系统,请不要重复登录、打开空白页!" == res.reason) {
  147. this.setStoreSession(res);
  148. this.setCookieData();
  149. if(this.loginForm.type =='产线看板'){
  150. this.$router.push({path: this.redirect || '/prodline'});
  151. }else if(this.loginForm.type =='车间看板'){
  152. this.$router.push({path: this.redirect || '/shop'});
  153. }else if(this.loginForm.type =='品质看板'){
  154. this.$router.push({path: this.redirect || '/quality'});
  155. }else if(this.loginForm.type =='仓库看板'){
  156. this.$router.push({path: this.redirect || '/warehouse'});
  157. }
  158. }else{
  159. this.$message.error(res.reason);
  160. }
  161. },(result)=>{
  162. console.error(result)
  163. });
  164. /*this.$store.dispatch('kanban/login.action',this.form).then(() => {
  165. this.$router.push({ path: this.redirect || '/' })
  166. }).catch(() => {
  167. this.loading = false;
  168. })*/
  169. } else {
  170. this.$message.error('登录出错请重新输入');
  171. return false;
  172. }
  173. });
  174. },
  175. handleEnter(event){
  176. if(event.key === 'Enter'){
  177. //处理回车键按下时间
  178. this.submitLogin();
  179. }
  180. },
  181. setStoreSession(res){
  182. //登录成功返回session
  183. sessionStorage.setItem('x-access-token', res.token);
  184. sessionStorage.setItem('username',this.loginForm.username);
  185. sessionStorage.setItem('password',CryptoJS.AES.encrypt(this.loginForm.password, "123456"));
  186. sessionStorage.setItem('sob',this.loginForm.sob);
  187. this.$store.commit('setUser',this.loginForm);
  188. this.$store.commit('setFactoryOptions',this.factoryoptions);
  189. this.$store.commit('setFactory',this.loginForm.factory);
  190. },
  191. setCookieData(){
  192. if (this.checked) {
  193. this.$cookie.set(
  194. "password",
  195. CryptoJS.AES.encrypt(this.loginForm.password, "123456"),
  196. {
  197. expires: 30
  198. }
  199. );
  200. } else {
  201. this.$cookie.remove("password");
  202. }
  203. this.$cookie.set("username", this.loginForm.username, {
  204. expires: 30,
  205. });
  206. this.$cookie.set("sob", this.loginForm.sob, {
  207. expires: 30,
  208. });
  209. this.$cookie.set("type", this.loginForm.type, {
  210. expires: 30,
  211. });
  212. this.$cookie.set("checked", this.checked, {
  213. expires: 30,
  214. });
  215. this.$cookie.set("factory", this.loginForm.factory, {
  216. expires: 30,
  217. });
  218. },
  219. getCookies(){
  220. if(this.$cookie.get("sob")) {
  221. this.loginForm.sob = this.$cookie.get("sob");
  222. }
  223. this.loginForm.username = this.$cookie.get("username");
  224. if (this.$cookie.get("password")) {
  225. this.loginForm.password = CryptoJS.AES.decrypt(
  226. this.$cookie.get("password"),
  227. "123456"
  228. ).toString(CryptoJS.enc.Utf8);
  229. }
  230. if(this.$cookie.get("type")) {
  231. this.loginForm.type = this.$cookie.get("type");
  232. }
  233. if(this.$cookie.get("checked")) {
  234. if(this.$cookie.get("checked") == 'false') {
  235. this.checked = false;
  236. }
  237. }
  238. if(this.$cookie.get("factory")) {
  239. this.loginForm.factory = this.$cookie.get("factory");
  240. }
  241. }
  242. },
  243. };
  244. </script>
  245. <style lang="less" scoped>
  246. .loginContainer{
  247. border-radius: 15px;
  248. background-clip: padding-box;
  249. margin: 120px auto;
  250. width: 350px;
  251. padding: 15px 35px 15px 35px;
  252. background: aliceblue;
  253. border:1px solid blueviolet;
  254. box-shadow: 0 0 25px #f885ff;
  255. }
  256. .loginTitle{
  257. margin: 0px auto 35px auto;
  258. text-align: center;
  259. font-size: 24px;
  260. }
  261. .loginRemember{
  262. text-align: left;
  263. margin: 0px 0px 15px 0px;
  264. }
  265. .bg {
  266. width: 100%;
  267. height: 100%;
  268. background-image: url("../assets/pageBg.png");
  269. background-size: cover;
  270. background-position: center center;
  271. }
  272. /*body{
  273. background-image: url("../assets/pageBg.png");
  274. background-size:100%;
  275. }*/
  276. </style>