You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

448 lines
15 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. <template>
  2. <div class="login-container">
  3. <el-form class="login-form" autoComplete="on" :model="loginForm" :rules="loginRules" ref="loginForm">
  4. <div class="title-container">
  5. <div class="logo">
  6. <img src="../../assets/image/logo1.png" alt="" />
  7. <div class="logo-text">
  8. <div class="systemName">{{$t('login.title')}}</div>
  9. </div>
  10. </div>
  11. <lang-select class="set-language"></lang-select>
  12. </div>
  13. <el-form-item prop="authType">
  14. <el-radio-group v-model="loginForm.authType">
  15. <el-radio label="password_display_userid">账户密码登录</el-radio>
  16. <el-radio label="sms">短信验证码快速登录</el-radio>
  17. </el-radio-group>
  18. </el-form-item>
  19. <el-form-item prop="displayUserid" v-show="loginForm.authType=='password_display_userid'">
  20. <el-input name="displayUserid" type="text" v-model="loginForm.displayUserid" autoComplete="on" placeholder="用户编号" >
  21. <template slot="prepend">账号</template>
  22. </el-input>
  23. </el-form-item>
  24. <el-form-item prop="password" v-show="loginForm.authType=='password_display_userid'">
  25. <el-input name="password" :type="passwordType" @keyup.enter.native="handleLogin" v-model="loginForm.password" autoComplete="on" placeholder="password">
  26. <template slot="prepend">密码</template>
  27. <span slot="append" class="show-pwd" @click="showPwd">
  28. <svg-icon icon-class="eye" />
  29. </span>
  30. </el-input>
  31. </el-form-item>
  32. <el-form-item prop="phoneno" v-show="loginForm.authType=='sms'">
  33. <el-input name="phoneno" type="text" v-model="loginForm.phoneno" autoComplete="on" placeholder="手机号码">
  34. <template slot="prepend">手机号码&nbsp;&nbsp;&nbsp;</template>
  35. <el-button slot="append" @click.prevent="sendPhonenoSmsCode">发送验证码</el-button>
  36. </el-input>
  37. </el-form-item>
  38. <el-form-item prop="smsCode" v-show="loginForm.authType=='sms'">
  39. <el-input name="smsCode" type="text" v-model="loginForm.smsCode" autoComplete="on" placeholder="短信验证码">
  40. <template slot="prepend">短信验证码</template>
  41. <template slot="append">六位验证码</template>
  42. </el-input>
  43. </el-form-item>
  44. <el-button type="primary" style="width:100%;margin-bottom:30px;" :loading="loading" @click.native.prevent="handleLogin">{{$t('login.logIn')}}</el-button>
  45. <el-row>
  46. <el-button type="success" plain round @click="showRegisterDialog=true">新用户注册</el-button>
  47. <el-button type="warning" plain round @click="showResetPasswordDialog=true">忘记密码</el-button>
  48. <el-button type="primary" plain round @click="showTpLoginDialog=true">{{$t('login.thirdparty')}}</el-button>
  49. </el-row>
  50. </el-form>
  51. <el-dialog
  52. title="请选择一个部门进行登陆"
  53. :visible.sync="deptSelectVisible"
  54. width="screenWidth<500?'90%':'500px" append-to-body>
  55. <el-row class="app-container">
  56. <el-col :span=20 v-for="(d,index) in myDepts" :key="index">
  57. <el-col :span=20><el-radio v-model="userDeptid" :label="d.deptid">{{d.deptName}}({{d.branchName}}) </el-radio> </el-col>
  58. </el-col>
  59. </el-row >
  60. <el-row class="app-container" style="text-align:right;">
  61. <el-col :span=20 >
  62. <el-button @click="deptSelectVisible = false"> </el-button>
  63. <el-button type="primary" @click="deptChecked"> </el-button>
  64. </el-col>
  65. </el-row >
  66. </el-dialog>
  67. <!-- 第三方登陆窗口 -->
  68. <el-dialog :title="$t('login.thirdparty')" :visible.sync="showTpLoginDialog" append-to-body>
  69. {{$t('login.thirdpartyTips')}}
  70. <br/>
  71. <br/>
  72. <br/>
  73. <social-sign />
  74. </el-dialog>
  75. <!-- 注册窗口 -->
  76. <el-dialog title="新用户注册" :visible.sync="showRegisterDialog" append-to-body>
  77. <register />
  78. </el-dialog>
  79. <!-- 重置密码窗口 -->
  80. <el-dialog title="重置密码" :visible.sync="showResetPasswordDialog" append-to-body>
  81. <reset-password />
  82. </el-dialog>
  83. <!--新增 Branch 管理端机构表机构下面若干部门界面-->
  84. <el-dialog title="新增机构" :visible.sync="addBranchFormVisible" width="50%" :close-on-click-modal="false" append-to-body>
  85. <branch-add :visible="addBranchFormVisible" @cancel="addBranchFormVisible=false" @submit="afterAddBranchSubmit"></branch-add>
  86. </el-dialog>
  87. </div>
  88. </template>
  89. <script>
  90. import { sendSmsCode } from '@/api/sms/sms';
  91. import LangSelect from '@/components/LangSelect';
  92. import SocialSign from './socialsignin';
  93. import Register from './register';
  94. import ResetPassword from './resetPassword';
  95. import BranchAdd from './BranchAdd';
  96. import { mapGetters } from 'vuex';
  97. import md5 from 'js-md5';
  98. export default {
  99. components: { LangSelect, SocialSign, BranchAdd,Register,ResetPassword},
  100. name: 'login',
  101. data() {
  102. const validateDisplayUserid = (rule, value, callback) => {
  103. if (this.loginForm.authType=='password_display_userid') {
  104. if(value.length<=6){
  105. callback(new Error('请输入6位以上用户账号'))
  106. }else{
  107. callback()
  108. }
  109. } else {
  110. callback()
  111. }
  112. }
  113. const validatePassword = (rule, value, callback) => {
  114. if (this.loginForm.authType=='password_display_userid') {
  115. if(value.length<6){
  116. callback(new Error('密码最少为六位'))
  117. }else{
  118. callback()
  119. }
  120. } else {
  121. callback()
  122. }
  123. }
  124. const validatePhoneno = (rule, value, callback) => {
  125. if (this.loginForm.authType=='sms') {
  126. if(value.length !=11 ){
  127. callback(new Error('手机号码必须为11位号码'))
  128. }else{
  129. callback()
  130. }
  131. } else {
  132. callback()
  133. }
  134. }
  135. const validateSmsCode = (rule, value, callback) => {
  136. if (this.loginForm.authType=='sms') {
  137. if(value.length !=6 ){
  138. callback(new Error('请输入6位短信验证码'))
  139. }else{
  140. callback()
  141. }
  142. } else {
  143. callback()
  144. }
  145. }
  146. return {
  147. loginForm: {
  148. displayUserid: '',
  149. password: '',
  150. authType:'password_display_userid',//password/sms/password_display_userid 分别为账户密码、短信验证码快捷登录
  151. phoneno:'',//手机号码
  152. smsCode:'',//短信验证码
  153. },
  154. loginRules: {
  155. displayUserid: [{ required: true, trigger: 'blur', validator: validateDisplayUserid }],
  156. password: [{ required: true, trigger: 'blur', validator: validatePassword }],
  157. phoneno: [{ required: true, trigger: 'blur', validator: validatePhoneno }],
  158. smsCode: [{ required: true, trigger: 'blur', validator: validateSmsCode }],
  159. },
  160. passwordType: 'password',
  161. loading: false,
  162. showResetPasswordDialog:false,//显示忘记密码重置密码窗口
  163. showTpLoginDialog: false, //显示第三方登陆对话框
  164. showRegisterDialog: false,//显示注册窗口
  165. deptSelectVisible:false,//显示选择部门对话框
  166. userDeptid:'',//选中的部门编号
  167. addBranchFormVisible:false, //显示添加机构对话框
  168. }
  169. },
  170. methods: {
  171. showPwd() {
  172. if (this.passwordType === 'password') {
  173. this.passwordType = ''
  174. } else {
  175. this.passwordType = 'password'
  176. }
  177. },
  178. sendPhonenoSmsCode(){
  179. var params={
  180. phoneno:this.loginForm.phoneno,
  181. scene:"login"
  182. }
  183. sendSmsCode(params).then(res=>{
  184. if(res.data.tips.isOk){
  185. this.$message.info(res.data.tips.msg);
  186. }else{
  187. this.$message.error(res.data.tips.msg);
  188. }
  189. })
  190. },
  191. handleLogin() {
  192. this.$refs.loginForm.validate(valid => {
  193. if (valid) {
  194. this.loading = true
  195. let params={
  196. displayUserid:this.loginForm.displayUserid,
  197. password:md5(this.loginForm.password),
  198. deptid:this.userDeptid,
  199. authType:this.loginForm.authType,
  200. phoneno:this.loginForm.phoneno,
  201. smsCode:this.loginForm.smsCode
  202. }
  203. var loginParams={ }
  204. if(params.authType=='password_display_userid'){
  205. loginParams.userloginid=params.displayUserid
  206. loginParams.password=params.password
  207. loginParams.grantType="password"
  208. loginParams.authType='password_display_userid'
  209. loginParams.deptid=params.deptid
  210. }else if(params.authType=='sms'){
  211. loginParams.userloginid=params.phoneno
  212. loginParams.password=params.smsCode
  213. loginParams.grantType="password"
  214. loginParams.authType="sms"
  215. loginParams.deptid=params.deptid
  216. }
  217. this.$store.dispatch("LoginByUserloginid",loginParams).then(res => {
  218. this.loading = false
  219. if(res.data.tips.isOk==true){
  220. console.log(this.$store);
  221. this.loading = true;
  222. this.$store.dispatch('GetUserInfo').then((res2)=>{
  223. //this.userDeptid=res2.data.userInfo.deptid
  224. this.loading = false
  225. if(res2.data.tips.isOk==true){
  226. if(this.$store.state.user.myBranchs==null ||this.$store.state.user.myBranchs.length==0||this.$store.state.user.myDepts==null || this.$store.state.user.myDepts.length<=0){
  227. //if(1==1){
  228. //this.$message.error("亲,您不在任何一个公司或者部门中,需要【先创建公司】\n 或者请【管理员加您进入公司】哦");
  229. this.addBranchFormVisible=true;
  230. }else if(this.$store.state.user.myDepts.length>1 ){
  231. //this.$message.info("亲,您在多个部门中任职,我分不清您要登陆哪个部门,请选择一个部门登陆吧");
  232. if( !this.userDeptid ){
  233. this.userDeptid=res2.data.userInfo.deptid
  234. this.deptSelectVisible=true;
  235. }else{
  236. this.rolesChecked();
  237. }
  238. //this.$router.push({ path: 'mdp/sys/branch/BranchAdd' })
  239. }else if(this.$store.state.user.myDepts.length==1){
  240. //进行角色身份验证
  241. this.userDeptid=res2.data.userInfo.deptid
  242. this.rolesChecked();
  243. }else{
  244. this.rolesChecked();
  245. }
  246. }else{
  247. this.$message.error(res2.data.tips.msg);
  248. }
  249. }).catch(err=>{
  250. console.log(err);
  251. this.loading = false
  252. });
  253. }else{
  254. this.$message.error(res.data.tips.msg);
  255. }
  256. }).catch((e) => {
  257. console.log(e);
  258. this.loading = false
  259. })
  260. } else {
  261. console.log('error submit!!')
  262. return false
  263. }
  264. })
  265. },
  266. deptChecked() {
  267. if( !this.userDeptid){
  268. this.$message.error("请选择登陆的部门")
  269. return
  270. }
  271. let depts=this.myDepts.filter(d=>d.deptid==this.userDeptid)
  272. if(this.$store.state.user.userInfo.deptid!=this.userDeptid){
  273. this.handleLogin();
  274. return;
  275. }else{
  276. this.rolesChecked();
  277. }
  278. },
  279. //角色身份验证
  280. rolesChecked(){
  281. if(this.userInfo.isSuperAdmin){
  282. this.$router.push({ path: '/' });
  283. this.$message.info("欢迎登陆,超级管理员");
  284. }else if(this.userInfo.isPlatformAdmin){
  285. this.$router.push({ path: '/' });
  286. this.$message.info("欢迎登陆,平台管理员");
  287. }else{
  288. this.$router.push({ path: '/' });
  289. this.$message.info("欢迎登陆");
  290. }
  291. },
  292. afterAddBranchSubmit(branch){
  293. this.addBranchFormVisible=false;
  294. this.handleLogin();
  295. },
  296. afterQRScan() {
  297. // const hash = window.location.hash.slice(1)
  298. // const hashObj = getQueryObject(hash)
  299. // const originUrl = window.location.origin
  300. // history.replaceState({}, '', originUrl)
  301. // const codeMap = {
  302. // wechat: 'code',
  303. // tencent: 'code'
  304. // }
  305. // const codeName = hashObj[codeMap[this.auth_type]]
  306. // if (!codeName) {
  307. // alert('第三方登录失败')
  308. // } else {
  309. // this.$store.dispatch('LoginByThirdparty', codeName).then(() => {
  310. // this.$router.push({ path: '/' })
  311. // })
  312. // }
  313. }
  314. },
  315. created() {
  316. // window.addEventListener('hashchange', this.afterQRScan)
  317. },
  318. destroyed() {
  319. // window.removeEventListener('hashchange', this.afterQRScan)
  320. },
  321. computed: {
  322. ...mapGetters([
  323. 'myBranchs','myDepts','userInfo','roles'
  324. ]),
  325. screenWidth:function(){
  326. return screen.width;
  327. },
  328. }
  329. }
  330. </script>
  331. <style rel="stylesheet/scss" lang="scss" scoped>
  332. $bg:#2d3a4b;
  333. $dark_gray:#889aa4;
  334. $light_gray:#ef1010;
  335. .login-container {
  336. position:absolute;
  337. height: 100%;
  338. width: 100%;
  339. background-color: $bg;
  340. background-size: 100%;
  341. background:url(../../assets/image/yxin_login_backgroup_pc.png) center center;
  342. .login-form {
  343. position: absolute;
  344. left: 0;
  345. right: 0;
  346. max-width: 520px;
  347. padding: 35px 35px 15px 35px;
  348. margin: 180px auto;
  349. border-radius: 20px;
  350. background-color:#f5f7faee;
  351. }
  352. .tips {
  353. font-size: 14px;
  354. color: #fff;
  355. margin-bottom: 10px;
  356. span {
  357. &:first-of-type {
  358. margin-right: 16px;
  359. }
  360. }
  361. }
  362. .svg-container {
  363. padding: 6px 5px 6px 15px;
  364. color: $dark_gray;
  365. vertical-align: middle;
  366. width: 30px;
  367. display: inline-block;
  368. &_login {
  369. font-size: 20px;
  370. }
  371. }
  372. .title-container {
  373. position: relative;
  374. .title {
  375. font-size: 26px;
  376. font-weight: 400;
  377. color: $light_gray;
  378. margin: 0px auto 40px auto;
  379. text-align: center;
  380. font-weight: bold;
  381. }
  382. .set-language {
  383. color: rgb(95, 41, 221);
  384. position: absolute;
  385. top: 5px;
  386. right: 0px;
  387. }
  388. }
  389. .show-pwd {
  390. position: absolute;
  391. right: 10px;
  392. top: 7px;
  393. font-size: 16px;
  394. color: $dark_gray;
  395. cursor: pointer;
  396. user-select: none;
  397. }
  398. .thirdparty-button {
  399. position: absolute;
  400. right: 35px;
  401. bottom: 28px;
  402. }
  403. .register-button {
  404. position: absolute;
  405. bottom: 28px;
  406. }
  407. }
  408. .logo {
  409. height: 100px;
  410. width: 100%;
  411. // padding: 0 20px;
  412. display: flex;
  413. align-items: left;
  414. justify-content: center;
  415. img {
  416. height: 100%;
  417. }
  418. .logo-text {
  419. display: flex;
  420. align-items: center;
  421. justify-content: center;
  422. color: $light_gray;
  423. .systemName {
  424. font-size: 35px;
  425. font-weight: 400;
  426. color: $light_gray;
  427. text-align: center;
  428. font-weight: bold;
  429. }
  430. }
  431. }
  432. </style>