Login.vue 20 KB

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