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.

331 lines
11 KiB

4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. <template>
  2. <div>
  3. <el-form autoComplete="on" label-width="120px" :model="loginForm" :rules="loginRules" ref="loginForm">
  4. <div>
  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. </div>
  12. <el-form-item prop="phoneno" label="手机号码">
  13. <el-input name="phoneno" type="text" v-model="loginForm.phoneno" autoComplete="on" placeholder="手机号码">
  14. <el-button slot="append" @click.prevent="sendPhonenoSmsCode">发送验证码</el-button>
  15. </el-input>
  16. <span v-if="phonenoUsers!=null && phonenoUsers.length>0"> 该手机号有{{phonenoUsers.length}}个账户,请选择需要重置密码的账户<font color="blue"></font>
  17. <br>
  18. <el-tag v-if="selectUser && selectUser.userid">已选择:{{selectUser.username}}</el-tag> <el-button type="text" @click="phonenoUsersVisible=true">选择账户</el-button>
  19. </span>
  20. </el-form-item>
  21. <el-form-item prop="smsCode" label="短信验证码">
  22. <el-input name="smsCode" type="text" v-model="loginForm.smsCode" autoComplete="on" placeholder="短信验证码">
  23. <template slot="append">六位验证码</template>
  24. </el-input>
  25. </el-form-item>
  26. <el-form-item prop="password" label="新密码">
  27. <el-input name="password" :type="passwordType" @keyup.enter.native="handleLogin" v-model="loginForm.password" autoComplete="on" placeholder="password">
  28. <span slot="append" class="show-pwd" @click="showPwd">
  29. <svg-icon icon-class="eye" />
  30. </span>
  31. </el-input>
  32. </el-form-item>
  33. <el-button type="primary" style="width:100%;margin-bottom:30px;" :loading="loading" @click.native.prevent="handleResetPasswordByPhoneno">重置密码</el-button>
  34. </el-form>
  35. <el-dialog
  36. title="查看已有账户"
  37. :visible.sync="phonenoUsersVisible"
  38. width="600" append-to-body>
  39. <el-table :data="phonenoUsers">
  40. <el-table-column prop="userid" label="编号">
  41. </el-table-column>
  42. <el-table-column prop="displayUserid" label="登录账号">
  43. </el-table-column>
  44. <el-table-column prop="username" label="姓名">
  45. </el-table-column>
  46. <el-table-column prop="branchName" label="企业">
  47. </el-table-column>
  48. <el-table-column label="操作">
  49. <template slot-scope="scope">
  50. <el-button type="primary" @click="onUserSelect(scope.row)">选中</el-button>
  51. </template>
  52. </el-table-column>
  53. </el-table>
  54. </el-dialog>
  55. <el-dialog
  56. title="请选择一个部门进行登陆"
  57. :visible.sync="deptSelectVisible"
  58. width="screenWidth<500?'90%':'500px" append-to-body>
  59. <el-row class="app-container">
  60. <el-col :span=20 v-for="(d,index) in myDepts" :key="index">
  61. <el-col :span=20><el-radio v-model="userDeptid" :label="d.deptid">{{d.deptName}}({{d.branchName}}) </el-radio> </el-col>
  62. </el-col>
  63. </el-row >
  64. <el-row class="app-container" style="text-align:right;">
  65. <el-col :span=20 >
  66. <el-button @click="deptSelectVisible = false"> </el-button>
  67. <el-button type="primary" @click="deptChecked"> </el-button>
  68. </el-col>
  69. </el-row >
  70. </el-dialog>
  71. <!-- 第三方登陆窗口 -->
  72. <el-dialog :title="$t('login.thirdparty')" :visible.sync="showTpLoginDialog" append-to-body>
  73. {{$t('login.thirdpartyTips')}}
  74. <br/>
  75. <br/>
  76. <br/>
  77. <social-sign />
  78. </el-dialog>
  79. <!--新增 Branch 管理端机构表机构下面若干部门界面-->
  80. <el-dialog title="新增机构" :visible.sync="addBranchFormVisible" width="50%" :close-on-click-modal="false" append-to-body>
  81. <branch-add :visible="addBranchFormVisible" @cancel="addBranchFormVisible=false" @submit="afterAddBranchSubmit"></branch-add>
  82. </el-dialog>
  83. </div>
  84. </template>
  85. <script>
  86. import { sendSmsCode } from '@/api/sms/sms';
  87. import { checkPhoneno,resetPasswordByPhoneno,queryByUserloginid } from '@/api/login';
  88. import LangSelect from '@/components/LangSelect';
  89. import SocialSign from './socialsignin';
  90. import BranchAdd from './BranchAdd';
  91. import { mapGetters } from 'vuex';
  92. import md5 from 'js-md5';
  93. export default {
  94. components: { LangSelect, SocialSign, BranchAdd },
  95. name: 'login',
  96. data() {
  97. const validatePassword = (rule, value, callback) => {
  98. if( !value || value.length<6){
  99. callback(new Error('密码最少为六位'))
  100. }else{
  101. callback()
  102. }
  103. }
  104. const validatePhoneno = (rule, value, callback) => {
  105. if( !value || value.length !=11 ){
  106. callback(new Error('手机号码必须为11位号码'))
  107. }else{
  108. callback()
  109. }
  110. }
  111. const validateSmsCode = (rule, value, callback) => {
  112. if( !value || value.length !=6 ){
  113. callback(new Error('请输入6位短信验证码'))
  114. }else{
  115. callback()
  116. }
  117. }
  118. return {
  119. loginForm: {
  120. password: '',
  121. phoneno:'',//手机号码
  122. smsCode:'',//短信验证码
  123. },
  124. loginRules: {
  125. password: [{ required: true, trigger: 'blur', validator: validatePassword }],
  126. phoneno: [{ required: true, trigger: 'blur', validator: validatePhoneno }],
  127. smsCode: [{ required: true, trigger: 'blur', validator: validateSmsCode }],
  128. },
  129. passwordType: 'password',
  130. loading: false,
  131. showTpLoginDialog: false, //显示第三方登陆对话框
  132. deptSelectVisible:false,//显示选择部门对话框
  133. userDeptid:'',//选中的部门编号
  134. addBranchFormVisible:false, //显示添加机构对话框
  135. phonenoUsersVisible:false,
  136. phonenoUsers:[],
  137. selectUser:null,//选中的账户
  138. }
  139. },
  140. methods: {
  141. showPwd() {
  142. if (this.passwordType === 'password') {
  143. this.passwordType = ''
  144. } else {
  145. this.passwordType = 'password'
  146. }
  147. },
  148. sendPhonenoSmsCode(){
  149. if(!this.loginForm.phoneno){
  150. this.$message.error("手机号码不能为空");
  151. return;
  152. }
  153. if(this.loginForm.phoneno.length !=11 ){
  154. this.$message.error("手机号码必须为11位");
  155. return;
  156. }
  157. var params={
  158. phoneno:this.loginForm.phoneno,
  159. scene:"changePassword"
  160. }
  161. queryByUserloginid({userloginid:this.loginForm.phoneno,idType:"phoneno"}).then(res0=>{
  162. if(res0.data.tips.isOk){
  163. this.phonenoUsers=res0.data.data;
  164. sendSmsCode(params).then(res=>{
  165. if(res.data.tips.isOk){
  166. this.$message.success(res.data.tips.msg);
  167. }else{
  168. this.$message.error(res.data.tips.msg);
  169. }
  170. })
  171. }
  172. })
  173. },
  174. handleResetPasswordByPhoneno() {
  175. this.$refs.loginForm.validate(valid => {
  176. if (valid) {
  177. let params={
  178. newPassword:md5(this.loginForm.password),
  179. phoneno:this.loginForm.phoneno,
  180. smsCode:this.loginForm.smsCode
  181. }
  182. if(this.phonenoUsers && this.phonenoUsers.length>0){
  183. if(!this.selectUser || !this.selectUser.userid){
  184. if(this.phonenoUsers.length==1){
  185. this.selectUser=this.phonenoUsers[0]
  186. }else{
  187. this.$notify({position:'bottom-left',showClose:true,message:'请选一个账户进行重置密码',type:'warning'})
  188. return;
  189. }
  190. }
  191. }
  192. if(this.selectUser && this.selectUser.userid){
  193. params.userid=this.selectUser.userid
  194. }
  195. this.loading = true
  196. resetPasswordByPhoneno(params).then(res=>{
  197. this.loading = false
  198. if(res.data.tips.isOk){
  199. this.$message.success(res.data.tips.msg);
  200. }else{
  201. this.$message.error(res.data.tips.msg);
  202. }
  203. })
  204. } else {
  205. this.loading = false
  206. return false
  207. }
  208. })
  209. },
  210. deptChecked() {
  211. if( !this.userDeptid){
  212. this.$message.error("请选择登陆的部门")
  213. return
  214. }
  215. let depts=this.myDepts.filter(d=>d.deptid==this.userDeptid)
  216. if(this.$store.state.user.userInfo.deptid!=this.userDeptid){
  217. this.handleLogin();
  218. return;
  219. }else{
  220. this.rolesChecked();
  221. }
  222. },
  223. //角色身份验证
  224. rolesChecked(){
  225. if(this.userInfo.isSuperAdmin){
  226. this.$router.push({ path: '/' });
  227. this.$message.info("欢迎登陆,超级管理员");
  228. }else if(this.userInfo.isPlatformAdmin){
  229. this.$router.push({ path: '/' });
  230. this.$message.info("欢迎登陆,平台管理员");
  231. }else{
  232. this.$router.push({ path: '/' });
  233. this.$message.info("欢迎登陆");
  234. }
  235. },
  236. afterAddBranchSubmit(branch){
  237. this.addBranchFormVisible=false;
  238. this.loading=true
  239. this.$store.dispatch('GetUserInfo').then((res)=>{
  240. this.userDeptid=res.data.userInfo.deptid
  241. this.loading = false;
  242. //角色身份验证
  243. this.rolesChecked();
  244. });
  245. },
  246. afterQRScan() {
  247. // const hash = window.location.hash.slice(1)
  248. // const hashObj = getQueryObject(hash)
  249. // const originUrl = window.location.origin
  250. // history.replaceState({}, '', originUrl)
  251. // const codeMap = {
  252. // wechat: 'code',
  253. // tencent: 'code'
  254. // }
  255. // const codeName = hashObj[codeMap[this.auth_type]]
  256. // if (!codeName) {
  257. // alert('第三方登录失败')
  258. // } else {
  259. // this.$store.dispatch('LoginByThirdparty', codeName).then(() => {
  260. // this.$router.push({ path: '/' })
  261. // })
  262. // }
  263. },
  264. onUserSelect(user){
  265. this.selectUser=user
  266. this.phonenoUsersVisible=false;
  267. }
  268. },
  269. created() {
  270. // window.addEventListener('hashchange', this.afterQRScan)
  271. },
  272. destroyed() {
  273. // window.removeEventListener('hashchange', this.afterQRScan)
  274. },
  275. computed: {
  276. ...mapGetters([
  277. 'myBranchs','myDepts','userInfo','roles'
  278. ]),
  279. screenWidth:function(){
  280. return screen.width;
  281. },
  282. }
  283. }
  284. </script>
  285. <style rel="stylesheet/scss" lang="scss" scoped>
  286. $bg:#2d3a4b;
  287. $dark_gray:#889aa4;
  288. $light_gray:#ef1010;
  289. .logo {
  290. height: 100px;
  291. width: 100%;
  292. // padding: 0 20px;
  293. display: flex;
  294. align-items: left;
  295. justify-content: center;
  296. img {
  297. height: 100%;
  298. }
  299. .logo-text {
  300. display: flex;
  301. align-items: center;
  302. justify-content: center;
  303. color: $light_gray;
  304. .systemName {
  305. font-size: 35px;
  306. font-weight: 400;
  307. color: $light_gray;
  308. text-align: center;
  309. font-weight: bold;
  310. }
  311. }
  312. }
  313. </style>