Login.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. <template>
  2. <div class="login">
  3. <div class="login-par">
  4. <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-position="left" label-width="0px" class="demo-ruleForm login-container">
  5. <div class="login-logo">
  6. <img src="../assets/image/login_logo.png" style="width:80px;height:80px;"/>
  7. </div>
  8. <h3 class="title">工时管家</h3>
  9. <el-form-item class="login-input" prop="username">
  10. <el-input type="text" v-model="ruleForm.username" autocomplete="off" placeholder="账号" clearable prefix-icon="el-icon-user-solid"></el-input>
  11. </el-form-item>
  12. <el-form-item class="login-input" prop="password">
  13. <el-input type="password" v-model="ruleForm.password" @keyup.enter.native="handleSubmit" autocomplete="off" placeholder="密码" show-password prefix-icon="el-icon-lock"></el-input>
  14. </el-form-item>
  15. <el-form-item class="login-button" style="width:100%;">
  16. <el-button type="primary" style="width:100%;" @click.native.prevent="handleSubmit" :loading="logining">登录</el-button>
  17. </el-form-item>
  18. <div class="toRegister">
  19. <el-link type="primary" class="btn" style="float:left;" :underline="false">联系客服
  20. <div class="service">
  21. <p style="color: #333">扫码加客服微信</p>
  22. <img src="../assets/image/code.jpg">
  23. <p><span style="color: #333">QQ:</span><span id="QQ">3052894409</span></p>
  24. </div>
  25. </el-link>
  26. <el-link type="primary" style="margin-right:5px;" @click="dialogVisible=true" :underline="false">
  27. 使用说明
  28. </el-link>
  29. <el-link type="primary" v-if="!isCorpWX" @click="jumpTo" :underline="false">企业注册</el-link>
  30. </div>
  31. </el-form>
  32. </div>
  33. <el-dialog title="使用说明" :visible.sync="dialogVisible" width="500px">
  34. <p><a style="color:#409EFF;text-decoration:none" href="upload/工时管家使用说明.docx" download="工时管家使用说明.docx"
  35. target="_blank">工时管家使用说明.docx</a></p>
  36. <!-- <p><a style="color:#409EFF;text-decoration:none" href="upload/工时管家使用说明_项目经理.docx" download="工时管家使用说明_项目经理.docx"
  37. target="_blank">工时管家使用说明_项目经理.docx</a></p>
  38. <p><a style="color:#409EFF;text-decoration:none" href="upload/工时管家使用说明_普通员工.docx" download="工时管家使用说明_普通员工.docx"
  39. target="_blank">工时管家使用说明_普通员工.docx</a></p> -->
  40. </el-dialog>
  41. </div>
  42. </template>
  43. <script>
  44. import * as dd from 'dingtalk-jsapi';
  45. import "../permissions.js"
  46. export default {
  47. data() {
  48. return {
  49. isCorpWX: false,
  50. dialogVisible: false,
  51. logining: false,
  52. // 登录信息
  53. ruleForm: {
  54. username: '',
  55. password: ''
  56. },
  57. rules: {
  58. username: [{ required: true, message: '请输入账号', trigger: 'blur' },],
  59. password: [{ required: true, message: '请输入密码', trigger: 'blur' },]
  60. }
  61. };
  62. },
  63. created() {
  64. if (localStorage.userInfo != null) {
  65. var user = JSON.parse(localStorage.userInfo);
  66. // if (user.role == 3 ) {
  67. // //公司高层
  68. // this.$router.push({ path: '/cost' });
  69. // } else if (user.role == 4) {
  70. // //财务管理员
  71. // this.$router.push({ path: '/team' });
  72. // } else {
  73. // this.$router.push({ path: '/daily' });
  74. // }
  75. if(user.moduleList.length > 0) {
  76. this.$router.push({ path: user.moduleList[0].path })
  77. }
  78. }
  79. },
  80. mounted() {
  81. var ua = navigator.userAgent.toLowerCase();
  82. if (ua.indexOf("wxwork") > 0) {
  83. this.isCorpWX = true;
  84. }
  85. if (localStorage.userInfo != null) {
  86. var user = JSON.parse(localStorage.userInfo);
  87. // if (user.role == 3) {
  88. // //公司高层
  89. // this.$router.push({ path: '/cost' });
  90. // } else if (user.role == 4) {
  91. // //财务管理员
  92. // this.$router.push({ path: '/team' });
  93. // } else {
  94. // this.$router.push({ path: '/daily' });
  95. // }
  96. if(user.moduleList.length > 0) {
  97. this.$router.push({ path: user.moduleList[0].path })
  98. }
  99. } else {
  100. if (this.isCorpWX) {
  101. //企业微信环境下,尝试自动登录
  102. let href = window.location.href;
  103. //判断企业微信,是否存在授权
  104. //尝试自动登录
  105. if (href.indexOf('hasTriedAutoLogin') == -1) {
  106. this.tryAutoLogin();
  107. } else if (href.indexOf("userId") > 0) {
  108. //后台经过验证后,重定向过来带上了userId
  109. var loginUserId = href.substring(href.indexOf("userId=")+"userId=".length);
  110. if (loginUserId.includes('#/')) {
  111. loginUserId = loginUserId.substring(0, loginUserId.indexOf('#/'));
  112. }
  113. this.loginByUserId(loginUserId);
  114. }
  115. } else {
  116. //检查环境,如果是钉钉有$CORPID$
  117. var key = '?corpid=';
  118. var url = location.href;
  119. var that = this;
  120. if (url.indexOf(key) > 0) {
  121. var corpId = url.substring(url.indexOf(key)+key.length,url.indexOf('#'));
  122. dd.ready(function() {
  123. that.isDingchg()
  124. dd.runtime.permission.requestAuthCode({
  125. corpId: corpId, // 企业id
  126. onSuccess: function (info) {
  127. var code = info.code // 通过该免登授权码可以获取用户身份
  128. that.loginByCode(code, corpId);
  129. }});
  130. });
  131. }
  132. }
  133. }
  134. },
  135. methods: {
  136. isDingchg() {
  137. this.$store.commit('isDingFun')
  138. },
  139. bindIfNessary() {
  140. let href = window.location.href;
  141. if (this.isCorpWX) {
  142. // localStorage.openId = 'o1L3L5lOrOl3_UEJjONaoT2Rne1I';
  143. //会自动跳转到首页
  144. // let href = 'http://hq.tangusoft.com/?code=011Ptjgc2rx1eI09Irgc2Rvsgc2PtjgF&state=1#/index';
  145. if (href.includes("com/?code")) { //url包括 com/?code 证明为从微信跳转回来的
  146. var url = href; //vue自动在末尾加了 #/ 符号,截取去掉
  147. var jingPosit = url.indexOf("com/") + 4; //获取域名结束的位置
  148. // var urlLeft = url.substring(0, jingPosit);//url左侧部分
  149. var urlRight = url.substring(jingPosit, url.length); //url右侧部分
  150. console.log('urlRight=' + urlRight);
  151. urlRight = urlRight.substring(0, urlRight.indexOf('#/'));
  152. // window.location = urlLeft + "#/home" + urlRight;//拼接跳转
  153. //获取code
  154. var code = urlRight.substring('?code='.length,urlRight.indexOf('&state='));
  155. var passUserId = urlRight.substring(urlRight.indexOf('&state=')+'&state='.length);
  156. if (passUserId == '1') {
  157. //自动登录的回调
  158. this.$axios.get('/wxcorp/corpWeiXinLogin', {params:{code:code}})
  159. .then(res => {
  160. if (res == null) {
  161. } else if(res.errcode != null) {
  162. //报错了
  163. console.log(res.errmsg);
  164. } else {
  165. //获取openId
  166. if (res.data != null && ((this.isWX && res.data.wxOpenid != undefined)
  167. || (this.isCorpWX && res.data.corpwxUserid != undefined))) {
  168. localStorage.userInfo = JSON.stringify(res.data);
  169. console.log('登录成功');
  170. this.user = res.data;
  171. window.location.href = '/#/index';
  172. }
  173. }
  174. }).catch(err=> {
  175. alert('err=' + err);
  176. });
  177. } else {
  178. }
  179. }
  180. }
  181. },
  182. tryAutoLogin() {
  183. var appId = "ww4e237fd6abb635af";//企业微信第三方的SUIT ID
  184. var url = "http://mobworktime.ttkuaiban.com/api/corpWXAuth";//授权回调页面
  185. var weixinUrl="https://open.weixin.qq.com/connect/oauth2/authorize?appid="+appId+"&redirect_uri="+encodeURI(url)+"&response_type=code&scope=snsapi_base&state=1#wechat_redirect";
  186. window.location.href = weixinUrl;
  187. },
  188. loginByUserId(userId) {
  189. this.http.post("/user/loginByUserId", {userId:userId} , res => {
  190. if (res.code == "ok") {
  191. var user = res.data;
  192. localStorage.user = JSON.stringify(res.data);
  193. sessionStorage.setItem('user', JSON.stringify(res.data));
  194. // if (user.role == 3) {
  195. // //公司高层
  196. // this.$router.push({ path: '/cost' });
  197. // } else if (user.role == 4) {
  198. // //财务管理员
  199. // this.$router.push({ path: '/team' });
  200. // } else {
  201. // this.$router.push({ path: '/daily' });
  202. // }
  203. if(user.moduleList.length > 0) {
  204. this.$router.push({ path: user.moduleList[0].path })
  205. }
  206. } else {
  207. this.$message({
  208. message: res.msg,
  209. type: 'error'
  210. });
  211. }
  212. }, error => {
  213. this.$message({
  214. message: error,
  215. type: 'error'
  216. });
  217. })
  218. },
  219. loginByCode(code, corpId) {
  220. this.http.post("/dingding/getUserByCode", {code:code, corpid:corpId} , res => {
  221. if (res.code == "ok") {
  222. var user = res.data;
  223. localStorage.user = JSON.stringify(res.data);
  224. sessionStorage.setItem('user', JSON.stringify(res.data));
  225. // if (user.role == 3) {
  226. // //公司高层
  227. // this.$router.push({ path: '/cost' });
  228. // } else if (user.role == 4) {
  229. // //财务管理员
  230. // this.$router.push({ path: '/team' });
  231. // } else {
  232. // this.$router.push({ path: '/daily' });
  233. // }
  234. if(user.moduleList.length > 0) {
  235. this.$router.push({ path: user.moduleList[0].path })
  236. }
  237. } else {
  238. this.$message({
  239. message: res.msg,
  240. type: 'error'
  241. });
  242. }
  243. }, error => {
  244. this.$message({
  245. message: error,
  246. type: 'error'
  247. });
  248. })
  249. },
  250. handleReset2() {
  251. this.$refs.ruleForm.resetFields();
  252. },
  253. jumpTo() {
  254. this.$router.push({ path: '/register' });
  255. },
  256. handleSubmit(ev) {
  257. this.$refs.ruleForm.validate((valid) => {
  258. if (valid) {
  259. var _this = this;
  260. this.logining = true;
  261. console.log("login",this.port.manage.login,this.ruleForm);
  262. this.http.post(this.port.manage.login, this.ruleForm , res => {
  263. this.logining = false;
  264. if (res.code == "ok") {
  265. var user = res.data;
  266. sessionStorage.setItem('user', JSON.stringify(res.data));
  267. this.permissionsList(res.data)
  268. // if (user.company.packageSimple == 1) {
  269. // //简易模式,直接进入工时统计表
  270. // this.$router.push({ path: '/simple' });
  271. // } else if (user.role == 3) {
  272. // //公司高层
  273. // this.$router.push({ path: '/cost' });
  274. // } else if (user.role == 4) {
  275. // //财务管理员
  276. // this.$router.push({ path: '/team' });
  277. // } else {
  278. // this.$router.push({ path: '/daily' });
  279. // }
  280. if(user.moduleList.length > 0) {
  281. this.$router.push({ path: user.moduleList[0].path })
  282. }
  283. } else {
  284. this.$message({
  285. message: res.msg,
  286. type: 'error'
  287. });
  288. }
  289. }, error => {
  290. this.logining = false;
  291. this.$message({
  292. message: error,
  293. type: 'error'
  294. });
  295. })
  296. }
  297. });
  298. },
  299. // 权限控制
  300. permissionsList(item) {
  301. var arr = []
  302. var ss = item.functionList
  303. for(var i in ss) {
  304. arr.push(ss[i].name)
  305. }
  306. var ssAkl = this.StringUtil.permissions(arr)
  307. sessionStorage.setItem('permissions', JSON.stringify(ssAkl));
  308. console.log(ssAkl, '返回过来的数据原--------')
  309. },
  310. },
  311. }
  312. </script>
  313. <style lang="scss" scoped>
  314. .login {
  315. height: 100%;
  316. .login-par {
  317. width: 100%;
  318. min-height: 100%;
  319. background: #f0f2f5 url('../assets/image/background.png') no-repeat 50%;
  320. background-size: 100%;
  321. padding: 110px 0 144px;
  322. position: relative;
  323. box-sizing: border-box;
  324. .login-logo {
  325. text-align: center;
  326. margin: 0 0 20px 0;
  327. }
  328. .login-container {
  329. -webkit-border-radius: 5px;
  330. border-radius: 5px;
  331. -moz-border-radius: 5px;
  332. background-clip: padding-box;
  333. width: 315px;
  334. height: 380px;
  335. padding: 25px 35px 25px 35px;
  336. background: #fff;
  337. border: 1px solid #eaeaea;
  338. box-shadow: 0 0 5px #cac6c6;
  339. border-top: 10px solid #20a0ff;
  340. margin:auto;
  341. .title {
  342. font-size: 20px;
  343. margin: 0px auto 40px auto;
  344. text-align: center;
  345. color: #505458;
  346. }
  347. .remember {
  348. margin: 0px 0px 35px 0px;
  349. }
  350. .login-input {
  351. margin: 30px 0 0 0;
  352. }
  353. .login-button {
  354. margin: 30px 0 0 0;
  355. }
  356. .login-button .el-button {
  357. padding: 14px;
  358. }
  359. }
  360. }
  361. }
  362. .toRegister {
  363. margin: 15px 0;
  364. text-align: right;
  365. position: relative;
  366. .service {
  367. display: none;
  368. width: 120px;
  369. position: absolute;
  370. background: #fff;
  371. text-align: center;
  372. padding: 10px;
  373. left: -30px;
  374. top: -210px;
  375. border-radius: 5px;
  376. box-shadow: 3px 3px 10px #dfdfdf;
  377. img {
  378. width: 80px;
  379. }
  380. }
  381. }
  382. .btn:hover .service {
  383. display: block;
  384. }
  385. </style>