Login.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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" @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. export default {
  46. data() {
  47. return {
  48. dialogVisible: false,
  49. logining: false,
  50. // 登录信息
  51. ruleForm: {
  52. username: '',
  53. password: ''
  54. },
  55. rules: {
  56. username: [{ required: true, message: '请输入账号', trigger: 'blur' },],
  57. password: [{ required: true, message: '请输入密码', trigger: 'blur' },]
  58. }
  59. };
  60. },
  61. created() {
  62. if (localStorage.userInfo != null) {
  63. var user = JSON.parse(localStorage.userInfo);
  64. if (user.role == 3) {
  65. //公司高层
  66. this.$router.push({ path: '/cost' });
  67. } else if (user.role == 4) {
  68. //人事管理员
  69. this.$router.push({ path: '/team' });
  70. } else {
  71. this.$router.push({ path: '/daily' });
  72. }
  73. }
  74. },
  75. mounted() {
  76. if (localStorage.userInfo != null) {
  77. var user = JSON.parse(localStorage.userInfo);
  78. if (user.role == 3) {
  79. //公司高层
  80. this.$router.push({ path: '/cost' });
  81. } else if (user.role == 4) {
  82. //人事管理员
  83. this.$router.push({ path: '/team' });
  84. } else {
  85. this.$router.push({ path: '/daily' });
  86. }
  87. } else {
  88. //检查环境,如果是钉钉有$CORPID$
  89. var key = '?corpid=';
  90. var url = location.href;
  91. var that = this;
  92. if (url.indexOf(key) > 0) {
  93. var corpId = url.substring(url.indexOf(key)+key.length,url.indexOf('#'));
  94. dd.ready(function() {
  95. dd.runtime.permission.requestAuthCode({
  96. corpId: corpId, // 企业id
  97. onSuccess: function (info) {
  98. var code = info.code // 通过该免登授权码可以获取用户身份
  99. that.loginByCode(code, corpId);
  100. }});
  101. });
  102. }
  103. }
  104. },
  105. methods: {
  106. loginByCode(code, corpId) {
  107. this.http.post("/dingding/getUserByCode", {code:code, corpid:corpId} , res => {
  108. if (res.code == "ok") {
  109. var user = res.data;
  110. localStorage.user = JSON.stringify(res.data);
  111. sessionStorage.setItem('user', JSON.stringify(res.data));
  112. if (user.role == 3) {
  113. //公司高层
  114. this.$router.push({ path: '/cost' });
  115. } else if (user.role == 4) {
  116. //人事管理员
  117. this.$router.push({ path: '/team' });
  118. } else {
  119. this.$router.push({ path: '/daily' });
  120. }
  121. } else {
  122. this.$message({
  123. message: res.msg,
  124. type: 'error'
  125. });
  126. }
  127. }, error => {
  128. this.$message({
  129. message: error,
  130. type: 'error'
  131. });
  132. })
  133. },
  134. handleReset2() {
  135. this.$refs.ruleForm.resetFields();
  136. },
  137. jumpTo() {
  138. this.$router.push({ path: '/register' });
  139. },
  140. handleSubmit(ev) {
  141. this.$refs.ruleForm.validate((valid) => {
  142. if (valid) {
  143. var _this = this;
  144. this.logining = true;
  145. this.http.post(this.port.manage.login, this.ruleForm , res => {
  146. this.logining = false;
  147. if (res.code == "ok") {
  148. var user = res.data;
  149. sessionStorage.setItem('user', JSON.stringify(res.data));
  150. if (user.role == 3) {
  151. //公司高层
  152. this.$router.push({ path: '/cost' });
  153. } else if (user.role == 4) {
  154. //人事管理员
  155. this.$router.push({ path: '/team' });
  156. } else {
  157. this.$router.push({ path: '/daily' });
  158. }
  159. } else {
  160. this.$message({
  161. message: res.msg,
  162. type: 'error'
  163. });
  164. }
  165. }, error => {
  166. this.logining = false;
  167. this.$message({
  168. message: error,
  169. type: 'error'
  170. });
  171. })
  172. }
  173. });
  174. },
  175. },
  176. }
  177. </script>
  178. <style lang="scss" scoped>
  179. .login {
  180. height: 100%;
  181. .login-par {
  182. width: 100%;
  183. min-height: 100%;
  184. background: #f0f2f5 url('../assets/image/background.png') no-repeat 50%;
  185. background-size: 100%;
  186. padding: 110px 0 144px;
  187. position: relative;
  188. box-sizing: border-box;
  189. .login-logo {
  190. text-align: center;
  191. margin: 0 0 20px 0;
  192. }
  193. .login-container {
  194. -webkit-border-radius: 5px;
  195. border-radius: 5px;
  196. -moz-border-radius: 5px;
  197. background-clip: padding-box;
  198. width: 315px;
  199. height: 380px;
  200. padding: 25px 35px 25px 35px;
  201. background: #fff;
  202. border: 1px solid #eaeaea;
  203. box-shadow: 0 0 5px #cac6c6;
  204. border-top: 10px solid #20a0ff;
  205. margin:auto;
  206. .title {
  207. font-size: 20px;
  208. margin: 0px auto 40px auto;
  209. text-align: center;
  210. color: #505458;
  211. }
  212. .remember {
  213. margin: 0px 0px 35px 0px;
  214. }
  215. .login-input {
  216. margin: 30px 0 0 0;
  217. }
  218. .login-button {
  219. margin: 30px 0 0 0;
  220. }
  221. .login-button .el-button {
  222. padding: 14px;
  223. }
  224. }
  225. }
  226. }
  227. .toRegister {
  228. margin: 15px 0;
  229. text-align: right;
  230. position: relative;
  231. .service {
  232. display: none;
  233. width: 120px;
  234. position: absolute;
  235. background: #fff;
  236. text-align: center;
  237. padding: 10px;
  238. left: -30px;
  239. top: -210px;
  240. border-radius: 5px;
  241. box-shadow: 3px 3px 10px #dfdfdf;
  242. img {
  243. width: 80px;
  244. }
  245. }
  246. }
  247. .btn:hover .service {
  248. display: block;
  249. }
  250. </style>