Login.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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.role == 3 ) {
  71. // //公司高层
  72. // this.$router.push({ path: '/cost' });
  73. // } else if (user.role == 4) {
  74. // //财务管理员
  75. // this.$router.push({ path: '/team' });
  76. // } else {
  77. // this.$router.push({ path: '/daily' });
  78. // }
  79. if(user.moduleList.length > 0) {
  80. this.$router.push({ path: user.moduleList[0].path })
  81. }
  82. }
  83. },
  84. mounted() {
  85. var ua = navigator.userAgent.toLowerCase();
  86. if (ua.indexOf("wxwork") > 0) {
  87. this.isCorpWX = true;
  88. }
  89. if (localStorage.userInfo != null) {
  90. var user = JSON.parse(localStorage.userInfo);
  91. if (user.company.packageSimple == 1) {
  92. //简易模式,直接进入工时统计表
  93. this.$router.push({ path: '/simple' });
  94. } else {
  95. if(user.moduleList.length > 0) {
  96. this.$router.push({ path: user.moduleList[0].path })
  97. }
  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 jumpkey = '&jumpto=';
  119. var url = location.href;
  120. console.log('jumpto',location);
  121. // var url = "https://worktime.ttkuaiban.com/?corpid=$CORPID$&jumpto=/info/21#/index"
  122. var that = this;
  123. if (url.indexOf(key) > 0) {
  124. var corpId = ''
  125. var jumpurl = ''
  126. if(url.indexOf(jumpkey) > 0){
  127. corpId = url.substring(url.indexOf(key)+key.length,url.indexOf(jumpkey));
  128. if(corpId == 'ding169917db7f1ee5f435c2f4657eb6378f'){
  129. jumpurl = url.substring(url.indexOf(jumpkey)+jumpkey.length,url.indexOf('#'));
  130. }
  131. }else{
  132. corpId = url.substring(url.indexOf(key)+key.length,url.indexOf('#'));
  133. }
  134. dd.ready(function() {
  135. that.isDingchg()
  136. dd.runtime.permission.requestAuthCode({
  137. corpId: corpId, // 企业id
  138. onSuccess: function (info) {
  139. var code = info.code // 通过该免登授权码可以获取用户身份
  140. that.loginByCode(code, corpId, jumpurl);
  141. }});
  142. });
  143. }
  144. }
  145. }
  146. },
  147. methods: {
  148. isDingchg() {
  149. this.$store.commit('isDingFun')
  150. },
  151. bindIfNessary() {
  152. let href = window.location.href;
  153. if (this.isCorpWX) {
  154. // localStorage.openId = 'o1L3L5lOrOl3_UEJjONaoT2Rne1I';
  155. //会自动跳转到首页
  156. // let href = 'http://hq.tangusoft.com/?code=011Ptjgc2rx1eI09Irgc2Rvsgc2PtjgF&state=1#/index';
  157. if (href.includes("com/?code")) { //url包括 com/?code 证明为从微信跳转回来的
  158. var url = href; //vue自动在末尾加了 #/ 符号,截取去掉
  159. var jingPosit = url.indexOf("com/") + 4; //获取域名结束的位置
  160. // var urlLeft = url.substring(0, jingPosit);//url左侧部分
  161. var urlRight = url.substring(jingPosit, url.length); //url右侧部分
  162. console.log('urlRight=' + urlRight);
  163. urlRight = urlRight.substring(0, urlRight.indexOf('#/'));
  164. // window.location = urlLeft + "#/home" + urlRight;//拼接跳转
  165. //获取code
  166. var code = urlRight.substring('?code='.length,urlRight.indexOf('&state='));
  167. var passUserId = urlRight.substring(urlRight.indexOf('&state=')+'&state='.length);
  168. if (passUserId == '1') {
  169. //自动登录的回调
  170. this.$axios.get('/wxcorp/corpWeiXinLogin', {params:{code:code}})
  171. .then(res => {
  172. if (res == null) {
  173. } else if(res.errcode != null) {
  174. //报错了
  175. console.log(res.errmsg);
  176. } else {
  177. //获取openId
  178. if (res.data != null && ((this.isWX && res.data.wxOpenid != undefined)
  179. || (this.isCorpWX && res.data.corpwxUserid != undefined))) {
  180. localStorage.userInfo = JSON.stringify(res.data);
  181. console.log('登录成功');
  182. this.user = res.data;
  183. this.permissionsList(res.data)
  184. window.location.href = '/#/index';
  185. }
  186. }
  187. }).catch(err=> {
  188. alert('err=' + err);
  189. });
  190. } else {
  191. }
  192. }
  193. }
  194. },
  195. tryAutoLogin() {
  196. var appId = "ww4e237fd6abb635af";//企业微信第三方的SUIT ID
  197. var url = "http://mobworktime.ttkuaiban.com/api/corpWXAuth";//授权回调页面
  198. 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";
  199. window.location.href = weixinUrl;
  200. },
  201. loginByUserId(userId) {
  202. this.http.post("/user/loginByUserId", {userId:userId} , res => {
  203. if (res.code == "ok") {
  204. var user = res.data;
  205. localStorage.user = JSON.stringify(res.data);
  206. sessionStorage.setItem('user', JSON.stringify(res.data));
  207. this.permissionsList(res.data)
  208. // if (user.role == 3) {
  209. // //公司高层
  210. // this.$router.push({ path: '/cost' });
  211. // } else if (user.role == 4) {
  212. // //财务管理员
  213. // this.$router.push({ path: '/team' });
  214. // } else {
  215. // this.$router.push({ path: '/daily' });
  216. // }
  217. if(user.moduleList.length > 0) {
  218. this.$router.push({ path: user.moduleList[0].path })
  219. }
  220. } else {
  221. this.$message({
  222. message: res.msg,
  223. type: 'error'
  224. });
  225. }
  226. }, error => {
  227. this.$message({
  228. message: error,
  229. type: 'error'
  230. });
  231. })
  232. },
  233. loginByCode(code, corpId, jumpurl) {
  234. this.http.post("/dingding/getUserByCode", {code:code, corpid:corpId} , res => {
  235. if (res.code == "ok") {
  236. var user = res.data;
  237. localStorage.user = JSON.stringify(res.data);
  238. sessionStorage.setItem('user', JSON.stringify(res.data));
  239. this.permissionsList(res.data)
  240. // if (user.role == 3) {
  241. // //公司高层
  242. // this.$router.push({ path: '/cost' });
  243. // } else if (user.role == 4) {
  244. // //财务管理员
  245. // this.$router.push({ path: '/team' });
  246. // } else {
  247. // this.$router.push({ path: '/daily' });
  248. // }
  249. if(jumpurl){
  250. this.$router.push({ path: jumpurl })
  251. }else if(user.moduleList.length > 0) {
  252. this.$router.push({ path: user.moduleList[0].path })
  253. }
  254. } else {
  255. this.$message({
  256. message: res.msg,
  257. type: 'error'
  258. });
  259. }
  260. }, error => {
  261. this.$message({
  262. message: error,
  263. type: 'error'
  264. });
  265. })
  266. },
  267. handleReset2() {
  268. this.$refs.ruleForm.resetFields();
  269. },
  270. jumpTo() {
  271. this.$router.push({ path: '/register' });
  272. },
  273. handleSubmit(ev) {
  274. this.$refs.ruleForm.validate((valid) => {
  275. if (valid) {
  276. var _this = this;
  277. this.logining = true;
  278. this.http.post(this.port.manage.login, this.ruleForm , res => {
  279. this.logining = false;
  280. if (res.code == "ok") {
  281. if(res.data.functionList.length == 0){
  282. this.$message({
  283. message: '请联系管理员为\u3000' + res.data.roleName + '\u3000分配权限',
  284. type: 'error'
  285. })
  286. return
  287. }
  288. var user = res.data;
  289. sessionStorage.setItem('user', JSON.stringify(res.data));
  290. this.permissionsList(res.data)
  291. if (user.company.packageSimple == 1) {
  292. //简易模式,直接进入工时统计表
  293. this.$router.push({ path: '/simple' });
  294. } else {
  295. if(user.moduleList.length > 0) {
  296. this.$router.push({ path: user.moduleList[0].path })
  297. }
  298. }
  299. } else {
  300. this.$message({
  301. message: res.msg,
  302. type: 'error'
  303. });
  304. }
  305. }, error => {
  306. this.logining = false;
  307. this.$message({
  308. message: error,
  309. type: 'error'
  310. });
  311. })
  312. }
  313. });
  314. },
  315. // 权限控制
  316. permissionsList(item) {
  317. var arr = []
  318. var ss = item.functionList
  319. for(var i in ss) {
  320. arr.push(ss[i].name)
  321. }
  322. var ssAkl = this.StringUtil.permissions(arr)
  323. sessionStorage.setItem('permissions', JSON.stringify(ssAkl));
  324. // console.log(ssAkl, '返回过来的数据原--------')
  325. },
  326. },
  327. }
  328. </script>
  329. <style lang="scss" scoped>
  330. .login {
  331. height: 100%;
  332. .login-par {
  333. width: 100%;
  334. min-height: 100%;
  335. background: #f0f2f5 url('../assets/image/background.png') no-repeat 50%;
  336. background-size: 100%;
  337. padding: 110px 0 144px;
  338. position: relative;
  339. box-sizing: border-box;
  340. .login-logo {
  341. text-align: center;
  342. margin: 0 0 20px 0;
  343. }
  344. .login-container {
  345. -webkit-border-radius: 5px;
  346. border-radius: 5px;
  347. -moz-border-radius: 5px;
  348. background-clip: padding-box;
  349. width: 315px;
  350. height: 380px;
  351. padding: 25px 35px 25px 35px;
  352. background: #fff;
  353. border: 1px solid #eaeaea;
  354. box-shadow: 0 0 5px #cac6c6;
  355. border-top: 10px solid #20a0ff;
  356. margin:auto;
  357. .title {
  358. font-size: 20px;
  359. margin: 0px auto 40px auto;
  360. text-align: center;
  361. color: #505458;
  362. }
  363. .remember {
  364. margin: 0px 0px 35px 0px;
  365. }
  366. .login-input {
  367. margin: 30px 0 0 0;
  368. }
  369. .login-button {
  370. margin: 30px 0 0 0;
  371. }
  372. .login-button .el-button {
  373. padding: 14px;
  374. }
  375. }
  376. }
  377. }
  378. .toRegister {
  379. margin: 15px 0;
  380. text-align: right;
  381. position: relative;
  382. .service {
  383. display: none;
  384. width: 120px;
  385. position: absolute;
  386. background: #fff;
  387. text-align: center;
  388. padding: 10px;
  389. left: -30px;
  390. top: -210px;
  391. border-radius: 5px;
  392. box-shadow: 3px 3px 10px #dfdfdf;
  393. img {
  394. width: 80px;
  395. }
  396. }
  397. }
  398. .btn:hover .service {
  399. display: block;
  400. }
  401. </style>