Login.vue 21 KB

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