Login.vue 17 KB

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