login.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. <template>
  2. <div class="login">
  3. <a-row type="flex" justify="center" align="middle">
  4. <a-col>
  5. <div class="login-background">
  6. <div id="img">
  7. <!-- <img src="./logo.png"
  8. alt="" />-->
  9. </div>
  10. </div>
  11. <div class="login-content">
  12. <p>账号登录</p>
  13. <a-form ref="formDom" :model="form" :rules="rules">
  14. <a-form-item name="account">
  15. <a-input placeholder="用户名/账号/手机号" v-model:value="form.account">
  16. <template #prefix>
  17. <img src="@/assets/images/user.png" alt />
  18. </template>
  19. </a-input>
  20. </a-form-item>
  21. <a-form-item name="password" class="mb20">
  22. <a-input
  23. @keyup.enter="loginAction"
  24. placeholder="请输入您的登录密码"
  25. type="password"
  26. v-model:value="form.password"
  27. >
  28. <template #prefix>
  29. <img src="@/assets/images/password.png" alt />
  30. </template>
  31. </a-input>
  32. </a-form-item>
  33. <a-form-item>
  34. <div class="login-remember-password">
  35. <a-checkbox v-model:checked="form.isRemember">记住账号</a-checkbox>
  36. <!-- <router-link to="/resetPassword">忘记密码?</router-link> -->
  37. </div>
  38. </a-form-item>
  39. <!-- <a-form-item>
  40. <div style="text-align:left">
  41. <a-checkbox v-model:checked="form.isRead">
  42. 我已阅读并同意
  43. </a-checkbox>
  44. <router-link to="/resetPassword">《用户协议》</router-link>
  45. </div>
  46. </a-form-item>-->
  47. <a-form-item class="mt20">
  48. <a-button
  49. @click="loginAction"
  50. :loading="loading"
  51. :disabled="goHomeloading"
  52. >登录</a-button>
  53. </a-form-item>
  54. </a-form>
  55. </div>
  56. </a-col>
  57. </a-row>
  58. </div>
  59. </template>
  60. <script lang="ts">
  61. import { defineComponent, reactive, ref, toRaw, onMounted } from 'vue';
  62. import { globalDataRefresh } from '@/services/bus/index';
  63. import { login } from '@/services/bus/login';
  64. import { useRouter } from 'vue-router';
  65. import { message } from 'ant-design-vue';
  66. import { localStorageUtil } from '@/utils/storage/index';
  67. import { initData, setLoadComplete } from '@/common/methods';
  68. import eventBus from '@/utils/eventBus/index';
  69. import { QWebChannel } from '@/utils/qt/qwebchannel.js';
  70. import { qtAction } from './qt';
  71. import { serviceURL } from '@/services/request/serviceURL';
  72. interface Form {
  73. account: string;
  74. password: string;
  75. isRemember: boolean;
  76. isRead: boolean;
  77. }
  78. const initForm: Form = {
  79. account: '',
  80. password: '',
  81. isRemember: false,
  82. isRead: false,
  83. };
  84. function setRememberAccount(): void {
  85. const account: string = localStorageUtil.getItem('loginAccount');
  86. if (account) {
  87. Object.assign(initForm, { account, isRemember: true });
  88. }
  89. }
  90. // declare global {
  91. // interface Window {
  92. // qt: {
  93. // webChannelTransport: {
  94. // send: (payload: any) => void;
  95. // onmessage: (payload: any) => void;
  96. // };
  97. // };
  98. // }
  99. // }
  100. // function qtAction() {
  101. // // 获取 与qt交互实例
  102. // let qtWebChannel: any = null;
  103. // const webChannelTransport = window.qt?.webChannelTransport;
  104. // if (webChannelTransport) {
  105. // new QWebChannel(webChannelTransport, (channel: any) => {
  106. // // all published objects are available in channel.objects under
  107. // // the identifier set in their attached WebChannel.id property
  108. // qtWebChannel = channel.objects.bridge;
  109. // console.log('qtWebChannel', qtWebChannel);
  110. // });
  111. // }
  112. // function getQtInfo(): Promise<Uint8Array[]> {
  113. // if (qtWebChannel) {
  114. // return qtWebChannel.getSystemInfo().then((res: any) => {
  115. // return base64ToUint8Array(res);
  116. // });
  117. // } else {
  118. // console.warn('qtWebChannel is null');
  119. // return Promise.resolve([]);
  120. // }
  121. // }
  122. // return { getQtInfo };
  123. // }
  124. // function base64ToUint8Array(base64String: string) {
  125. // let padding = '='.repeat((4 - (base64String.length % 4)) % 4);
  126. // let base64 = (base64String + padding).replace(/\-/g, '+').replace(/_/g, '/');
  127. // let rawData = window.atob(base64);
  128. // let outputArray = new Uint8Array(rawData.length);
  129. // for (var i = 0; i < rawData.length; ++i) {
  130. // outputArray[i] = rawData.charCodeAt(i);
  131. // }
  132. // return outputArray;
  133. // }
  134. export default defineComponent({
  135. name: 'login',
  136. components: {},
  137. setup() {
  138. function setLogo() {
  139. const img = document.querySelector('#logo_img') || document.createElement('img');
  140. const obj = {
  141. id: 'logo_img',
  142. src: './wrLogo.png',
  143. };
  144. Object.assign(img, obj);
  145. document.querySelector('#img')?.appendChild(img);
  146. }
  147. onMounted(() => {
  148. setLogo();
  149. });
  150. const loading = ref<boolean>(false);
  151. const form = reactive(initForm);
  152. const rules = {
  153. account: [{ required: true, message: '请输入手机号!', trigger: 'change', type: 'string' }],
  154. password: [{ required: true, message: '请输入密码!', trigger: 'change', type: 'string' }],
  155. };
  156. const formDom: any = ref(null);
  157. const router = useRouter();
  158. form.password = '';
  159. // setRememberAccount();
  160. // qt
  161. const { getQtInfo } = qtAction();
  162. function loginAction() {
  163. formDom.value.validate().then(() => {
  164. loading.value = true;
  165. const { account, password } = toRaw(form);
  166. setLoadComplete(false);
  167. getQtInfo().then((arr) => {
  168. login(account, password, arr)
  169. .then((value: any) => {
  170. setLoadComplete(true);
  171. const { account, isRemember } = toRaw(form);
  172. if (isRemember) {
  173. localStorageUtil.setItem('loginAccount', account); // 缓存登录账号
  174. }
  175. eventBus.$emit('loginSuccess', true);
  176. router.push({ name: 'home' });
  177. loading.value = false;
  178. })
  179. .catch((err: any) => {
  180. loading.value = false;
  181. err && message.error(err);
  182. });
  183. });
  184. });
  185. }
  186. // 直接前往首页
  187. const goHomeloading = ref<boolean>(false);
  188. const goHome = () => {
  189. goHomeloading.value = true;
  190. setLoadComplete(false);
  191. globalDataRefresh()
  192. .then((res) => {
  193. setLoadComplete(true);
  194. goHomeloading.value = false;
  195. router.push({ name: 'home' });
  196. })
  197. .catch((err) => {
  198. console.error(err);
  199. goHomeloading.value = false;
  200. });
  201. };
  202. return { form, loginAction, rules, formDom, loading, goHomeloading, goHome };
  203. },
  204. });
  205. </script>
  206. <style lang="less" scoped>
  207. .login {
  208. width: 100%;
  209. height: 100%;
  210. background: url(../../assets/images/loginBackground.png) no-repeat scroll 0 0;
  211. background-size: 100% 100%;
  212. }
  213. .ant-row {
  214. height: 100%;
  215. }
  216. .ant-col {
  217. width: 690px;
  218. height: 450px;
  219. background: @m-white0;
  220. border-radius: 5px;
  221. box-shadow: 0px 5px 10px 0px rgba(18, 22, 24, 0.18);
  222. .flex();
  223. }
  224. .login-background {
  225. width: 275px;
  226. background: url('../../assets/images/logoBackground.png') no-repeat scroll 0 0;
  227. background-size: cover;
  228. div {
  229. margin-top: 120px;
  230. // margin-left: 69.5px; // 企业风管logo
  231. margin-left: 33px; // 云融
  232. width: 136px;
  233. height: 136px;
  234. min-width: 136px;
  235. min-height: 136px;
  236. position: relative;
  237. img {
  238. max-width: 100%;
  239. max-height: 100%;
  240. .position(absolute, 0%, auto, auto, 50%);
  241. z-index: 10;
  242. transform: translate(-50%, -50%);
  243. }
  244. }
  245. // .ant-btn {
  246. // background: @cyan-color2;
  247. // border-color: @cyan-color2;
  248. // border-radius: 10px;
  249. // font-size: 14px;
  250. // color: @white;
  251. // margin-top: 90px;
  252. // margin-left: -60px;
  253. // }
  254. }
  255. .login-content {
  256. flex: 1;
  257. padding-left: 53px;
  258. padding-right: 53px;
  259. min-width: 405px;
  260. ::v-deep(.ant-form) {
  261. margin-top: 20px;
  262. .ant-form-item-control-wrapper {
  263. width: 100%;
  264. }
  265. .ant-form-item-control.has-error {
  266. .ant-form-item-children {
  267. .ant-input-affix-wrapper {
  268. .ant-input {
  269. background: transparent !important;
  270. }
  271. }
  272. }
  273. .ant-form-explain {
  274. text-align: left;
  275. padding-left: 24px;
  276. }
  277. }
  278. .ant-input {
  279. border: 0;
  280. border-radius: 0;
  281. width: 154px;
  282. height: 40px;
  283. font-size: 16px;
  284. font-family: Adobe Heiti Std;
  285. }
  286. .ant-input-affix-wrapper {
  287. box-shadow: none;
  288. border: none;
  289. border-radius: 0;
  290. border-bottom: 1px solid @m-grey3;
  291. padding: 0;
  292. }
  293. .ant-input-affix-wrapper:hover {
  294. border-bottom: 1px solid @m-blue1;
  295. }
  296. }
  297. .mt20 {
  298. margin-top: 20px;
  299. }
  300. .mb20 {
  301. margin-bottom: 20px;
  302. }
  303. .ant-form-item,
  304. .ant-form label {
  305. font-size: 16px;
  306. }
  307. .ant-form-item {
  308. margin-bottom: 10px;
  309. }
  310. p {
  311. font-size: 26px;
  312. text-align: left;
  313. font-family: Adobe Heiti Std;
  314. font-weight: normal;
  315. color: @m-grey4;
  316. margin-top: 40px;
  317. margin-bottom: 10px;
  318. }
  319. img {
  320. width: 19px;
  321. height: 21px;
  322. }
  323. .login-remember-password {
  324. .flex();
  325. justify-content: space-between;
  326. a {
  327. color: @m-grey4;
  328. }
  329. }
  330. .ant-btn {
  331. width: 100%;
  332. font-size: 16px;
  333. background: @m-blue1;
  334. border-radius: 3px;
  335. color: @m-white0;
  336. height: 50px;
  337. font-weight: 500;
  338. line-height: 43px;
  339. }
  340. }
  341. </style>