Login.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <script>
  2. import { post, get } from '../../utils/request'
  3. import crypto from '@/crypto/crypto'
  4. import Eyecolse from '@/components/icon/eye_colse.vue'
  5. import Eyeopen from '@/components/icon/eye_open.vue'
  6. import Error from '@/components/icon/error.vue'
  7. import { userStore } from '@/store/userInfo'
  8. export default {
  9. components: { Eyecolse, Eyeopen, Error },
  10. data() {
  11. return {
  12. passwordError: false,
  13. emailError: false,
  14. empty: true,
  15. teamIds: '',
  16. passwordType: false,
  17. remenber: false,
  18. ruleForm: {
  19. email: '',
  20. password: ''
  21. },
  22. rules: {
  23. email: [
  24. {
  25. required: true,
  26. message: 'Email Address is required',
  27. trigger: ['']
  28. },
  29. {
  30. type: 'email',
  31. message: 'Please enter a valid Email Address',
  32. trigger: ['']
  33. }
  34. ],
  35. password: [
  36. { required: true, message: 'Password is required', trigger: [''] }
  37. ]
  38. }
  39. }
  40. },
  41. mounted() {
  42. const isRemenber = localStorage.getItem('isRemenber')
  43. if (isRemenber) {
  44. this.ruleForm.email = localStorage.getItem('username') || ''
  45. this.ruleForm.password =
  46. crypto.get(localStorage.getItem('password')) || ''
  47. this.remenber = true
  48. }
  49. this.isdisable()
  50. },
  51. methods: {
  52. submit() {
  53. this.passwordError = false
  54. this.emailError = false
  55. this.$refs['ruleForm'].validate((valid) => {
  56. if (valid) {
  57. var formdata = new FormData()
  58. formdata.append('username', this.ruleForm.email)
  59. formdata.append('password', this.ruleForm.password)
  60. post('/pdf-tech/login', formdata).then(
  61. (res) => {
  62. if (res.data.code === 200 && res.data.msg === '获取授权码成功') {
  63. this.$message({
  64. type: 'success',
  65. duration: 5000,
  66. message: 'Sign in Success'
  67. })
  68. get(
  69. '/pdf-tech/auth/getToken?code=' +
  70. res.data.result
  71. ).then((res) => {
  72. this.$cookies.remove('accessToken')
  73. this.$cookies.set('accessToken', res.data.result.accessToken)
  74. setTimeout(() => {
  75. if (this.$route.query.teamIds) {
  76. this.teamIds = this.$route.query.teamIds.split(',')
  77. var urlencoded = new URLSearchParams()
  78. urlencoded.append('memberId', this.$route.query.memberId)
  79. urlencoded.append('teamIds', this.teamIds)
  80. urlencoded.append('action', this.$route.query.action)
  81. urlencoded.append('code', this.$route.query.code)
  82. post(
  83. '/pdf-tech/vppTeam/enterTeam',
  84. urlencoded
  85. ).then((res) => {
  86. this.getMemberInfo()
  87. })
  88. } else {
  89. this.getMemberInfo()
  90. }
  91. })
  92. })
  93. localStorage.setItem('username', this.ruleForm.email)
  94. const SECRET_PWD = crypto.set(this.ruleForm.password) // 加密
  95. localStorage.setItem('password', SECRET_PWD)
  96. if (this.remenber) {
  97. localStorage.setItem('isRemenber', 'true')
  98. } else {
  99. localStorage.removeItem('isRemenber')
  100. }
  101. } else if (
  102. res.data.code === 306 &&
  103. res.data.msg === '账号或者密码错误'
  104. ) {
  105. this.passwordError = true
  106. this.ruleForm.password = ''
  107. this.$message.error({
  108. duration: 5000,
  109. message: 'Incorrect email or password'
  110. })
  111. } else if (
  112. res.data.code === 302 &&
  113. res.data.msg === 'Please Create your Account first'
  114. ) {
  115. this.emailError = true
  116. this.passwordError = true
  117. this.ruleForm.password = ''
  118. this.ruleForm.email = ''
  119. this.$message({
  120. type: 'error',
  121. duration: 5000,
  122. message: 'Please Create your Account first'
  123. })
  124. }
  125. }
  126. )
  127. } else {
  128. return false
  129. }
  130. })
  131. },
  132. isdisable() {
  133. if (
  134. this.ruleForm.email.trim() !== '' ||
  135. this.ruleForm.password.trim() !== ''
  136. ) {
  137. this.empty = false
  138. } else {
  139. this.empty = true
  140. }
  141. if (this.ruleForm.email.trim() !== '') {
  142. this.emailError = false
  143. }
  144. if (this.ruleForm.password.trim() !== '') {
  145. this.passwordError = false
  146. }
  147. },
  148. getMemberInfo () {
  149. get('/pdf-tech/vppMember/getMemberInfo').then((res) => {
  150. if (res.data.code === 200 && res.data.msg == 'success') {
  151. userStore().setUserInfo(res.data.result)
  152. get(
  153. '/pdf-tech/vppLicenseCode/checkCompanyLicense?companyId='+res.data.result.companyId
  154. ).then((res)=>{
  155. if(!res.data.result){
  156. this.$router.push('/non-admin-user')
  157. return
  158. }
  159. })
  160. }
  161. if (
  162. res.data.result.role?.indexOf("2") !== -1 || res.data.result.role?.indexOf("1") !== -1
  163. ) {
  164. this.$router.push('/dashboard')
  165. } else {
  166. this.$router.push('/non-admin-user')
  167. }
  168. })
  169. }
  170. }
  171. }
  172. </script>
  173. <template>
  174. <div class="bg w-full h-100vh flex justify-center items-center m-auto">
  175. <div class="w-404px h-auto rounded-8px p-24px bg-[#fff] loginBox">
  176. <h1 class="text-24px font-bold mb-24px">Sign in</h1>
  177. <el-form
  178. :model="ruleForm"
  179. ref="ruleForm"
  180. :rules="rules"
  181. label-position="top"
  182. label-width="100px"
  183. inline-message
  184. >
  185. <el-form-item prop="email">
  186. <div class="flex items-center">
  187. <el-input
  188. v-model="ruleForm.email"
  189. @input="isdisable()"
  190. placeholder="Email address"
  191. />
  192. <Error
  193. class="w-14px h-14px block"
  194. :class="emailError ? 'block' : 'hidden'"
  195. />
  196. </div>
  197. </el-form-item>
  198. <el-form-item prop="password">
  199. <div class="flex items-center">
  200. <el-input
  201. v-model="ruleForm.password"
  202. placeholder="Password"
  203. @input="isdisable()"
  204. @keyup.enter.native="submit()"
  205. :type="passwordType ? '' : 'password'"
  206. >
  207. </el-input>
  208. <span
  209. v-show="ruleForm.password !== ''"
  210. class="show-password"
  211. :class="passwordType ? 'eye-open' : 'eye-close'"
  212. @click="passwordType = !passwordType"
  213. >
  214. <Eyeopen v-show="passwordType" />
  215. <Eyecolse v-show="!passwordType" />
  216. </span>
  217. <Error
  218. class="w-14px h-14px block"
  219. :class="passwordError ? 'block' : 'hidden'"
  220. />
  221. </div>
  222. </el-form-item>
  223. <el-form-item>
  224. <div class="flex justify-between items-center !text-12px">
  225. <el-checkbox
  226. label="Keep me logged in"
  227. name="type"
  228. v-model="remenber"
  229. ></el-checkbox>
  230. <router-link to="/forget-password" class="text-[#1460F3]">
  231. Forgot Password?
  232. </router-link>
  233. </div>
  234. </el-form-item>
  235. <el-form-item>
  236. <button
  237. :disabled="empty"
  238. type="button"
  239. @click="submit()"
  240. :class="empty ? 'opacity-20' : 'hover:opacity-80'"
  241. class="w-full h-48px bg-[#1460F3] text-[#fff] rounded-8px"
  242. >
  243. Sign in
  244. </button>
  245. </el-form-item>
  246. <!-- <div class="flex justify-end">
  247. <router-link to="/sign-up" class="text-12px text-[#1460F3]">
  248. Create account
  249. </router-link>
  250. </div> -->
  251. </el-form>
  252. </div>
  253. </div>
  254. </template>
  255. <style lang="scss" scoped>
  256. .bg {
  257. background: #e7eaee url('@/assets/images/background.png') center center
  258. no-repeat;
  259. }
  260. .loginBox {
  261. box-shadow: 0px 0px 12px rgba(35, 97, 169, 0.05);
  262. }
  263. .el-checkbox ::v-deep .el-checkbox__label {
  264. font-size: 12px;
  265. line-height: 16px;
  266. }
  267. .el-input::v-deep input {
  268. border: 0px !important;
  269. padding-right: 30px;
  270. border-bottom: 1px solid #d9d9d9 !important;
  271. border-radius: 0 !important;
  272. }
  273. .show-password {
  274. display: inline-block;
  275. position: absolute;
  276. right: 13px;
  277. top: 13px;
  278. width: 14px;
  279. height: 14px;
  280. cursor: pointer;
  281. }
  282. </style>