Login.vue 10 KB

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