Login.vue 21 KB

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