Login.vue 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. <template>
  2. <div>
  3. <div class="login" v-if="!isCorpWX">
  4. <div class="login-par">
  5. <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-position="left" label-width="0px" class="demo-ruleForm login-container">
  6. <div class="login-logo">
  7. <img src="../assets/image/login_logo.png" style="width:80px;height:80px;"/>
  8. </div>
  9. <h3 class="title">{{ $t('workingHoursHousekeeper') }}</h3>
  10. <el-form-item class="login-input" prop="username">
  11. <el-input type="text" v-model="ruleForm.username" autocomplete="off" :placeholder="$t('zhang-hao-shou-ji-hao')" clearable prefix-icon="el-icon-user-solid"></el-input>
  12. </el-form-item>
  13. <el-form-item class="login-input" prop="password">
  14. <el-input type="password" v-model="ruleForm.password" @keyup.enter.native="handleSubmit" autocomplete="off" :placeholder="$t('mi-ma')" show-password prefix-icon="el-icon-lock"></el-input>
  15. </el-form-item>
  16. <el-form-item class="login-button" style="width:100%;">
  17. <el-button type="primary" style="width:100%;" @click.native.prevent="handleSubmit" :loading="logining">{{ $t('login') }}</el-button>
  18. </el-form-item>
  19. <div class="additional">
  20. <el-divider content-position="center">或</el-divider>
  21. </div>
  22. <div class="externalLanding">
  23. <div class="externalLanding_img" @click="wxworkCli()">
  24. <img src="../assets/image/qiyeweix.png" alt="">
  25. </div>
  26. </div>
  27. <div class="toRegister">
  28. <el-link type="primary" class="btn" style="float:left;" :underline="false">{{ $t('lian-xi-ke-fu') }}
  29. <div class="service">
  30. <p style="color: #333">{{ $t('sao-ma-jia-ke-fu-wei-xin') }}</p>
  31. <img src="../assets/image/code.jpg">
  32. <p><span style="color: #333">QQ:</span><span id="QQ">3052894409</span></p>
  33. </div>
  34. </el-link>
  35. <el-link type="primary" style="margin-right:5px;" @click="dialogVisible=true" :underline="false">
  36. {{ $t('shi-yong-shuo-ming') }} </el-link>
  37. <el-link type="primary" v-if="!isCorpWX" @click="jumpTo" :underline="false">{{ $t('qi-ye-zhu-ce') }}</el-link>
  38. </div>
  39. </el-form>
  40. </div>
  41. <el-dialog :title="$t('shi-yong-shuo-ming')" :visible.sync="dialogVisible" width="500px">
  42. <p><a style="color:#409EFF;text-decoration:none" href="upload/工时管家使用说明_基础版.docx" download="工时管家使用说明_基础版.docx"
  43. target="_blank">工时管家使用说明_基础版.docx</a></p>
  44. <p><a style="color:#409EFF;text-decoration:none" href="upload/工时管家使用说明_项目管理专业版.docx" download="工时管家使用说明_项目管理专业版.docx"
  45. target="_blank">工时管家使用说明_项目管理专业版.docx</a></p>
  46. <p><a style="color:#409EFF;text-decoration:none" href="upload/工时管家使用说明_建筑工程专业版.docx" download="工时管家使用说明_建筑工程专业版.docx"
  47. target="_blank">工时管家使用说明_建筑工程专业版.docx</a></p>
  48. <!-- <p><a style="color:#409EFF;text-decoration:none" href="upload/工时管家使用说明_项目经理.docx" download="工时管家使用说明_项目经理.docx"
  49. target="_blank">工时管家使用说明_项目经理.docx</a></p>
  50. <p><a style="color:#409EFF;text-decoration:none" href="upload/工时管家使用说明_普通员工.docx" download="工时管家使用说明_普通员工.docx"
  51. target="_blank">工时管家使用说明_普通员工.docx</a></p> -->
  52. </el-dialog>
  53. <el-dialog title="企业微信扫码登陆" :visible.sync="wxworkFlg" width="500px">
  54. <div>
  55. <div id="wxcode"></div>
  56. </div>
  57. </el-dialog>
  58. </div>
  59. <!-- 企业微信的话 -->
  60. <div class="qiweix" v-if="isCorpWX">
  61. 正在进入系统...
  62. </div>
  63. </div>
  64. </template>
  65. <script>
  66. import * as dd from 'dingtalk-jsapi';
  67. import "../permissions.js"
  68. import WxLogin from "../assets/js/wwLogin.js"
  69. export default {
  70. inject:['reloads'],
  71. data() {
  72. return {
  73. isCorpWX: false,
  74. dialogVisible: false,
  75. logining: false,
  76. // 登录信息
  77. ruleForm: {
  78. username: '',
  79. password: ''
  80. },
  81. rules: {
  82. username: [{ required: true, message: this.$t('peaseenterthe'), trigger: 'blur' },],
  83. password: [{ required: true, message: this.$t('peaseenterthe'), trigger: 'blur' },]
  84. },
  85. wxworkFlg: false
  86. };
  87. },
  88. watch: {
  89. $route(to) {
  90. if (to.query.code) {
  91. this.getStaffInfo(to.query.code)
  92. }
  93. }
  94. },
  95. created() {
  96. // this.langChange()
  97. if (localStorage.userInfo != null) {
  98. var user = JSON.parse(localStorage.userInfo);
  99. if(user.moduleList.length > 0) {
  100. this.$router.push({ path: user.moduleList[0].path })
  101. }
  102. }
  103. let windowHerf = window.location.href
  104. if(windowHerf.indexOf('?jobNumber') != '-1') {
  105. let jobNumber = windowHerf.split('jobNumber=')[1].split('&token=')[0]
  106. let token = windowHerf.split('&token=')[1]
  107. this.automaticLogin(jobNumber, token)
  108. }
  109. },
  110. mounted() {
  111. // this.wxworkCli()
  112. var ua = navigator.userAgent.toLowerCase();
  113. if (ua.indexOf("wxwork") > 0) {
  114. this.isCorpWX = true;
  115. }
  116. let href = window.location.href;
  117. if (this.isCorpWX) {
  118. //企业微信环境下,尝试自动登录
  119. //判断企业微信,是否存在授权
  120. //尝试自动登录
  121. if (href.indexOf('hasTriedAutoLogin') == -1) {
  122. this.tryAutoLogin();
  123. } else if (href.indexOf("userId") > 0) {
  124. //后台经过验证后,重定向过来带上了userId
  125. var loginUserId = href.substring(href.indexOf("userId=")+"userId=".length);
  126. if (loginUserId.includes('#/')) {
  127. loginUserId = loginUserId.substring(0, loginUserId.indexOf('#/'));
  128. }
  129. var path = null;
  130. if (href.indexOf('path') > 0) {
  131. path = href.split('path=')[1].split('&')[0];
  132. }
  133. this.loginByUserId(loginUserId, path);
  134. } else {
  135. if (localStorage.userInfo != null) {
  136. var user = JSON.parse(localStorage.userInfo);
  137. if (user.company.packageSimple == 1) {
  138. //简易模式,直接进入工时统计表
  139. this.$router.push({ path: '/simple' });
  140. } else {
  141. if(user.moduleList.length > 0) {
  142. this.$router.push({ path: user.moduleList[0].path })
  143. }
  144. }
  145. } else if (href.indexOf('errorMsg=') > 0) {
  146. var errorMsg = href.split('errorMsg=')[1].split('#')[0];
  147. this.$message({
  148. message: errorMsg,
  149. type: 'error'
  150. });
  151. }
  152. }
  153. } else {
  154. //浏览器上使用扫码登录
  155. if (href.indexOf("userId") > 0) {
  156. //后台经过验证后,重定向过来带上了userId
  157. var loginUserId = href.substring(href.indexOf("userId=")+"userId=".length);
  158. if (loginUserId.includes('#/')) {
  159. loginUserId = loginUserId.substring(0, loginUserId.indexOf('#/'));
  160. }
  161. var path = null;
  162. if (href.indexOf('path') > 0) {
  163. path = href.split('path=')[1].split('&')[0];
  164. }
  165. this.loginByUserId(loginUserId, path);
  166. } else if (localStorage.userInfo != null) {
  167. var user = JSON.parse(localStorage.userInfo);
  168. if (user.company.packageSimple == 1) {
  169. //简易模式,直接进入工时统计表
  170. this.$router.push({ path: '/simple' });
  171. } else {
  172. if(user.moduleList.length > 0) {
  173. this.$router.push({ path: user.moduleList[0].path })
  174. }
  175. }
  176. } else {
  177. //检查环境,如果是钉钉有$CORPID$
  178. var key = '?corpid=';
  179. var jumpkey = '&jumpto=';
  180. var url = location.href;
  181. console.log('jumpto',location);
  182. // var url = "https://worktime.ttkuaiban.com/?corpid=$CORPID$&jumpto=/info/21#/index"
  183. var that = this;
  184. if (url.indexOf(key) > 0) {
  185. var corpId = ''
  186. var jumpurl = ''
  187. if(url.indexOf(jumpkey) > 0){
  188. corpId = url.substring(url.indexOf(key)+key.length,url.indexOf(jumpkey));
  189. jumpurl = url.substring(url.indexOf(jumpkey)+jumpkey.length,url.indexOf('#'));
  190. }else{
  191. corpId = url.substring(url.indexOf(key)+key.length,url.indexOf('#'));
  192. }
  193. dd.ready(function() {
  194. that.isDingchg()
  195. dd.runtime.permission.requestAuthCode({
  196. corpId: corpId, // 企业id
  197. onSuccess: function (info) {
  198. var code = info.code // 通过该免登授权码可以获取用户身份
  199. that.loginByCode(code, corpId, jumpurl);
  200. }});
  201. });
  202. }
  203. }
  204. }
  205. let urls = window.location.href
  206. console.log(urls, '连接')
  207. if(urls.indexOf('english=1') != '-1' && localStorage.getItem('lang') != 'en') {
  208. this.setlangChange()
  209. location.reload()
  210. }
  211. if(urls.indexOf('english=1') == '-1' && localStorage.getItem('lang') != 'zh') {
  212. localStorage.setItem("lang", 'zh')
  213. location.reload()
  214. }
  215. },
  216. methods: {
  217. wxworkCli() {
  218. // this.wxworkFlg = true
  219. // this.$nextTick(()=>{
  220. // var obj = new WxLogin({
  221. // id: 'wxcode', // 登录页面显示二维码的容器id
  222. // appid: 'wwf11426cf618e1703', // 企业微信的CorpID,在企业微信管理端查看
  223. // redirect_uri: encodeURIComponent('http://localhost:10086/#/login'), // 重定向的地址,需要进行encode
  224. // usertype: 'member'
  225. // })
  226. // })
  227. var appId = "wwf11426cf618e1703";//企业微信第三方的SUIT ID
  228. var url = "https://worktime.ttkuaiban.com/api/corpWXScanningAuth";//授权回调页面
  229. var weixinUrl=`https://open.work.weixin.qq.com/wwopen/sso/3rd_qrConnect?appid=${appId}&redirect_uri=${url}&state=0&usertype=member`;
  230. window.location.href = weixinUrl;
  231. },
  232. getStaffInfo() {
  233. console.log('执行了没')
  234. },
  235. setlangChange() {
  236. localStorage.setItem("lang", 'en')
  237. },
  238. langChange() {
  239. let jsSrc =(navigator.language || navigator.browserLanguage).toLowerCase();
  240. let str = localStorage.getItem("lang")
  241. if(jsSrc.indexOf('zh')!=-1){
  242. // 浏览器语言是中文
  243. localStorage.setItem("lang", 'zh')
  244. // localStorage.setItem("lang", 'en')
  245. } else {
  246. // 浏览器语言是英文
  247. localStorage.setItem("lang", 'en')
  248. // localStorage.setItem("lang", 'zh')
  249. }
  250. if(str != localStorage.getItem("lang")) {
  251. // this.reloads()
  252. location.reload()
  253. }
  254. console.log(str, localStorage.getItem("lang"))
  255. },
  256. isDingchg() {
  257. this.$store.commit('isDingFun')
  258. },
  259. bindIfNessary() {
  260. let href = window.location.href;
  261. if (this.isCorpWX) {
  262. // localStorage.openId = 'o1L3L5lOrOl3_UEJjONaoT2Rne1I';
  263. //会自动跳转到首页
  264. // let href = 'http://hq.tangusoft.com/?code=011Ptjgc2rx1eI09Irgc2Rvsgc2PtjgF&state=1#/index';
  265. if (href.includes("com/?code")) { //url包括 com/?code 证明为从微信跳转回来的
  266. var url = href; //vue自动在末尾加了 #/ 符号,截取去掉
  267. var jingPosit = url.indexOf("com/") + 4; //获取域名结束的位置
  268. // var urlLeft = url.substring(0, jingPosit);//url左侧部分
  269. var urlRight = url.substring(jingPosit, url.length); //url右侧部分
  270. console.log('urlRight=' + urlRight);
  271. urlRight = urlRight.substring(0, urlRight.indexOf('#/'));
  272. // window.location = urlLeft + "#/home" + urlRight;//拼接跳转
  273. //获取code
  274. var code = urlRight.substring('?code='.length,urlRight.indexOf('&state='));
  275. var passUserId = urlRight.substring(urlRight.indexOf('&state=')+'&state='.length);
  276. if (passUserId == '1') {
  277. //自动登录的回调
  278. this.$axios.get('/wxcorp/corpWeiXinLogin', {params:{code:code}})
  279. .then(res => {
  280. if (res == null) {
  281. } else if(res.errcode != null) {
  282. //报错了
  283. console.log(res.errmsg);
  284. } else {
  285. //获取openId
  286. if (res.data != null && ((this.isWX && res.data.wxOpenid != undefined)
  287. || (this.isCorpWX && res.data.corpwxUserid != undefined))) {
  288. localStorage.userInfo = JSON.stringify(res.data);
  289. console.log('登录成功');
  290. this.user = res.data;
  291. this.permissionsList(res.data)
  292. window.location.href = '/#/index';
  293. }
  294. }
  295. }).catch(err=> {
  296. alert('err=' + err);
  297. });
  298. } else {
  299. }
  300. }
  301. }
  302. },
  303. tryAutoLogin() {
  304. var appId = "ww4e237fd6abb635af";//企业微信第三方的SUIT ID
  305. var url = "https://worktime.ttkuaiban.com/api/corpWXAuth";//授权回调页面
  306. 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";
  307. window.location.href = weixinUrl;
  308. },
  309. loginByUserId(userId, path) {
  310. this.http.post("/user/loginByUserId", {userId:userId} , res => {
  311. if (res.code == "ok") {
  312. var user = res.data;
  313. localStorage.user = JSON.stringify(res.data);
  314. sessionStorage.setItem('user', JSON.stringify(res.data));
  315. this.permissionsList(res.data)
  316. if(user.moduleList.length > 0) {
  317. if (path) {
  318. this.$router.push({ path: path })
  319. } else {
  320. this.$router.push({ path: user.moduleList[0].path })
  321. }
  322. if (!path) {
  323. path = user.moduleList[0].path;
  324. }
  325. //去掉链接上存在的参数
  326. if (location.href.indexOf("?")>0) {
  327. var newHref = location.href.split("?")[0] + '#' + (path.indexOf('/')>-1?path:('/'+path));
  328. location.href = newHref;
  329. }
  330. }
  331. } else {
  332. this.$message({
  333. message: res.msg,
  334. type: 'error'
  335. });
  336. }
  337. }, error => {
  338. this.$message({
  339. message: error,
  340. type: 'error'
  341. });
  342. })
  343. },
  344. loginByCode(code, corpId, jumpurl) {
  345. this.http.post("/dingding/getUserByCode", {code:code, corpid:corpId} , res => {
  346. if (res.code == "ok") {
  347. var user = res.data;
  348. localStorage.user = JSON.stringify(res.data);
  349. sessionStorage.setItem('user', JSON.stringify(res.data));
  350. this.permissionsList(res.data)
  351. if(jumpurl){
  352. this.$router.push({ path: jumpurl })
  353. }else if(user.moduleList.length > 0) {
  354. this.$router.push({ path: user.moduleList[0].path })
  355. }
  356. } else {
  357. this.$message({
  358. message: res.msg,
  359. type: 'error'
  360. });
  361. }
  362. }, error => {
  363. this.$message({
  364. message: error,
  365. type: 'error'
  366. });
  367. })
  368. },
  369. handleReset2() {
  370. this.$refs.ruleForm.resetFields();
  371. },
  372. jumpTo() {
  373. this.$router.push({ path: '/register' });
  374. },
  375. handleSubmit(ev) {
  376. this.$refs.ruleForm.validate((valid) => {
  377. if (valid) {
  378. var _this = this;
  379. this.logining = true;
  380. setTimeout(function () {
  381. _this.logining = false;
  382. // console.log('执行')
  383. }, 15000);
  384. this.http.post(this.port.manage.login, this.ruleForm , res => {
  385. this.logining = false;
  386. if (res.code == "ok") {
  387. if(res.data.moduleList.length == 0){
  388. this.$message({
  389. message: this.$t('qing-lian-xi-guan-li-yuan-wei')+'\u3000' + res.data.roleName + '\u3000'+this.$t('assignpermissions'),
  390. type: 'error'
  391. })
  392. return
  393. }
  394. var user = res.data;
  395. sessionStorage.setItem('user', JSON.stringify(res.data));
  396. this.permissionsList(res.data)
  397. if (user.company.packageSimple == 1) {
  398. //简易模式,直接进入工时统计表
  399. this.$router.push({ path: '/simple' });
  400. sessionStorage.setItem('autoRoute','/simple')
  401. } else {
  402. if(user.moduleList.length > 0) {
  403. this.$router.push({ path: user.moduleList[0].path })
  404. sessionStorage.setItem('autoRoute',user.moduleList[0].path)
  405. }
  406. }
  407. } else {
  408. this.logining = false;
  409. // if(res.msg.indexOf('到期') != -1){
  410. // this.$router.push({ path: '/expire', query:{datetext:'2022.11.24',ddd: '111'}})
  411. // console.log('到期skip');
  412. // return
  413. // }
  414. this.$message({
  415. message: res.msg,
  416. type: 'error'
  417. });
  418. }
  419. }, error => {
  420. console.log('执行1')
  421. this.logining = false;
  422. this.$message({
  423. message: error,
  424. type: 'error'
  425. });
  426. })
  427. }
  428. });
  429. },
  430. // 米莱得用工号登录
  431. automaticLogin(jobNumber, token) {
  432. this.http.post('/user/loginAdminByThirdParty', {
  433. jobNumber: jobNumber,
  434. token: token
  435. } , res => {
  436. if (res.code == "ok") {
  437. if(res.data.moduleList.length == 0){
  438. this.$message({
  439. message: this.$t('qing-lian-xi-guan-li-yuan-wei')+'\u3000' + res.data.roleName + '\u3000'+this.$t('assignpermissions'),
  440. type: 'error'
  441. })
  442. return
  443. }
  444. var user = res.data;
  445. sessionStorage.setItem('user', JSON.stringify(res.data));
  446. this.permissionsList(res.data)
  447. if (user.company.packageSimple == 1) {
  448. //简易模式,直接进入工时统计表
  449. this.$router.push({ path: '/simple' });
  450. sessionStorage.setItem('autoRoute','/simple')
  451. } else {
  452. if(user.moduleList.length > 0) {
  453. this.$router.push({ path: user.moduleList[0].path })
  454. sessionStorage.setItem('autoRoute',user.moduleList[0].path)
  455. }
  456. }
  457. } else {
  458. this.$message({
  459. message: res.msg,
  460. type: 'error'
  461. });
  462. }
  463. }, error => {
  464. this.$message({
  465. message: error,
  466. type: 'error'
  467. });
  468. })
  469. },
  470. // 权限控制
  471. permissionsList(item) {
  472. var arr = []
  473. var ss = item.functionList
  474. for(var i in ss) {
  475. arr.push(ss[i].name)
  476. }
  477. var ssAkl = this.StringUtil.permissions(arr)
  478. sessionStorage.setItem('permissions', JSON.stringify(ssAkl));
  479. // console.log(ssAkl, '返回过来的数据原--------')
  480. },
  481. },
  482. }
  483. </script>
  484. <style lang="scss" scoped>
  485. .qiweix {
  486. width: 100%;
  487. display: flex;
  488. justify-content: center;
  489. padding: 50px 0;
  490. font-size: 40px;
  491. color: #505458;
  492. }
  493. .additional {
  494. width: 100%;
  495. text-align: center;
  496. padding: 20px 0;
  497. color: #505458;
  498. }
  499. .externalLanding {
  500. width: 100%;
  501. display: flex;
  502. justify-content: center;
  503. .externalLanding_img {
  504. width: 30px;
  505. height: 30px;
  506. border: 1px solid #409EFF;
  507. border-radius: 50%;
  508. position: relative;
  509. overflow: hidden;
  510. cursor: pointer;
  511. display: flex;
  512. justify-content: center;
  513. align-items: center;
  514. img {
  515. width: 80%;
  516. height: 80%;
  517. }
  518. }
  519. }
  520. .login {
  521. height: 100%;
  522. .login-par {
  523. width: 100%;
  524. min-height: 100%;
  525. background: #f0f2f5 url('../assets/image/background.png') no-repeat 50%;
  526. background-size: 100%;
  527. padding: 110px 0 144px;
  528. position: relative;
  529. box-sizing: border-box;
  530. .login-logo {
  531. text-align: center;
  532. margin: 0 0 20px 0;
  533. }
  534. .login-container {
  535. -webkit-border-radius: 5px;
  536. border-radius: 5px;
  537. -moz-border-radius: 5px;
  538. background-clip: padding-box;
  539. width: 315px;
  540. // height: 380px;
  541. padding: 25px 35px 25px 35px;
  542. background: #fff;
  543. border: 1px solid #eaeaea;
  544. box-shadow: 0 0 5px #cac6c6;
  545. border-top: 10px solid #20a0ff;
  546. margin:auto;
  547. .title {
  548. font-size: 20px;
  549. margin: 0px auto 40px auto;
  550. text-align: center;
  551. color: #505458;
  552. }
  553. .remember {
  554. margin: 0px 0px 35px 0px;
  555. }
  556. .login-input {
  557. margin: 30px 0 0 0;
  558. }
  559. .login-button {
  560. margin: 30px 0 0 0;
  561. }
  562. .login-button .el-button {
  563. padding: 14px;
  564. }
  565. }
  566. }
  567. }
  568. .toRegister {
  569. margin: 15px 0;
  570. text-align: right;
  571. position: relative;
  572. .service {
  573. display: none;
  574. width: 120px;
  575. position: absolute;
  576. background: #fff;
  577. text-align: center;
  578. padding: 10px;
  579. left: -30px;
  580. top: -210px;
  581. border-radius: 5px;
  582. box-shadow: 3px 3px 10px #dfdfdf;
  583. img {
  584. width: 80px;
  585. }
  586. }
  587. }
  588. .btn:hover .service {
  589. display: block;
  590. }
  591. </style>