Login.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <template>
  2. <div class="bgimg w-full h-full flex bg-black">
  3. <div class=" w-8/12 h-full hidden md:flex justify-center items-center p-10 bg-blue-400 relative bg-map">
  4. <div class="w-full h-full bgimg absolute"></div>
  5. <div class="w-full h-4/5 bottom-0 absolute flex items-center justify-center relative">
  6. <div class="lbx absolute">
  7. <img src="/public/image/big/lbx.png" alt="lbx">
  8. </div>
  9. <div class="jt absolute ">
  10. <img src="/public/image/big/jt.png" alt="背景图片">
  11. </div>
  12. <div class="map absolute ">
  13. <img src="/public/image/big/map.png" alt="地球">
  14. </div>
  15. <div class="rounded-img absolute ">
  16. <img src="/public/image/big/rounded.png" alt="地球">
  17. </div>
  18. <div class="w-auto relative bottom-1/5">
  19. <h1 class="text-7xl text-white">合方圆管理平台</h1>
  20. <h2 class="text-2xl mt-3 text-gray-200">合天地方圆·尽在掌握</h2>
  21. <h2 class="mt-0.5 text-gray-500">HFY·<a href="/hfy">深圳合方圆</a></h2>
  22. </div>
  23. </div>
  24. </div>
  25. <!-- 登陆框逻辑-->
  26. <div class="w-full md:w-3/12 h-full flex justify-center md:justify-start items-center relative">
  27. <div class="blur w-full h-full absolute bg-blue-300 opacity-50 bgimg"></div>
  28. <div class="login-box w-80 h-auto rounded px-0.5 text-gray-200 relative">
  29. <h2 class="pt-2 text-xl">欢迎您,请登陆</h2>
  30. <div class="w-full px-1.5 flex">
  31. <div class="w-4/12 flex items-center u px-1"><p class="w-full text-justify">用户名</p> </div>
  32. <div class="w-8/12">
  33. <a-input placeholder="用户名" v-model="form.owner.val" @focus="form.owner.msg=''" @blur="checkFormItem('owner')"></a-input>
  34. <div class="w-full text-red-600" v-show="form.owner.msg" >
  35. {{form.owner.msg}}
  36. </div>
  37. </div>
  38. </div>
  39. <div class="w-full px-1.5 mt-3.5 flex">
  40. <div class="w-4/12 flex items-center u px-1 "><p class="w-full text-justify">登陆密码</p> </div>
  41. <div class="w-8/12">
  42. <a-input-password placeholder="登陆密码" v-model="form.password.val" @focus="form.password.msg=''" @blur="checkFormItem('password')"></a-input-password>
  43. <div class="w-full text-red-600" v-show="form.password.msg" >
  44. {{form.password.msg}}
  45. </div>
  46. </div>
  47. </div>
  48. <div class="w-full px-1.5 mt-3.5 flex">
  49. <div class="w-4/12 u px-1 pt-1.5"><p class="w-full text-justify">验证码</p> </div>
  50. <div class="w-8/12">
  51. <a-input
  52. class="w-full"
  53. placeholder="验证码,忽略大小写"
  54. @keydown.enter="submitHandle"
  55. v-model="form.captcha.val"
  56. @focus="form.captcha.msg=''"
  57. @blur="checkFormItem('captcha')"
  58. />
  59. <div class="w-full text-red-600" v-show="form.captcha.msg" >
  60. {{form.captcha.msg}}
  61. </div>
  62. <captcha class="w-full h-24 overflow-hidden mt-1.5 rounded" ref="captchaImg" captcha-url="/captcha/"></captcha>
  63. </div>
  64. </div>
  65. <div class="w-full">
  66. <div class="px-2">
  67. <light-button @click.native="submitHandle" >登陆</light-button>
  68. </div>
  69. </div>
  70. <div class="border-t px-2 ">
  71. <span class="mr-4 text-blue-300" >
  72. <a href="/register">立即注册</a>
  73. </span>
  74. <a href="/hfy_login">主站点</a>
  75. </div>
  76. </div>
  77. </div>
  78. <div class="w-1/12 h-full hidden md:flex bg-gray-800 opacity-30"></div>
  79. </div>
  80. </template>
  81. <script>
  82. import Captcha from "@components/user/captcha";
  83. import apis from '@/apis/apis'
  84. import handle from "@/utils/handle";
  85. import business from "@/utils/business";
  86. import LightButton from "@components/public/lightButton";
  87. import fieldIsAllow from "@/utils/fieldIsAllow"
  88. import userData from "@/saves/users";
  89. export default {
  90. name: 'App',
  91. components: {
  92. LightButton,
  93. Captcha
  94. },
  95. beforeCreate() {
  96. // 修改页面title
  97. document.title = '合方圆-登陆';
  98. },
  99. data(){
  100. return {
  101. // 是否为固定
  102. labelCol: { span: 4 },
  103. wrapperCol: { span: 16 },
  104. form: {
  105. owner: {
  106. val:'',
  107. msg: '',
  108. state: 0,
  109. },
  110. password: {
  111. val:'',
  112. msg: '',
  113. state: 0,
  114. },
  115. captcha: {
  116. val:'',
  117. msg: '',
  118. state: 0,
  119. },
  120. },
  121. // 要切换的url地址
  122. jumpUrl: '/',
  123. }
  124. },
  125. computed:{
  126. },
  127. beforeMount(){
  128. },
  129. mounted(){
  130. let url = window.sessionStorage.getItem('lastUrl');
  131. if(url){
  132. this.jumpUrl = url;
  133. }
  134. },
  135. methods:{
  136. resetForm(){
  137. this.form.owner = '';
  138. this.form.password = '';
  139. this.form.captcha = '';
  140. },
  141. checkFormItem(field){
  142. console.log(field);
  143. if (field){
  144. this.form[field].msg = fieldIsAllow({
  145. [field]:this.form[field].val,
  146. })
  147. }else{
  148. let r = true;
  149. for (const fieldKey in this.form) {
  150. this.form[fieldKey].msg = fieldIsAllow({
  151. [fieldKey]:this.form[fieldKey].val,
  152. })
  153. if (this.form[fieldKey].msg){
  154. r = false;
  155. }
  156. }
  157. return r
  158. }
  159. },
  160. async submitHandle(e){
  161. if(!this.checkFormItem()){
  162. return this.$message.warn("请检查登陆参数");
  163. }
  164. let owner = this.form.owner.val;
  165. let passwd = this.form.password.val;
  166. let captcha = this.form.captcha.val;
  167. let [err,response] = await handle(apis.user.login(owner,passwd,captcha));
  168. let rcodeMean = business.checkResponseRcode(response,err);
  169. if(rcodeMean.ok){
  170. let res = rcodeMean.res;
  171. // 登陆成功
  172. this.$message.success(`登陆成功,稍后进行页面跳转`);
  173. console.log(res);
  174. userData.setUser(res.data)
  175. this.countDown();
  176. }else{
  177. // 登陆失败
  178. this.$message[rcodeMean.type](rcodeMean.msg);
  179. // 更新验证码
  180. this.$refs.captchaImg.refreshCaptcha();
  181. this.form.captcha.val = '';
  182. }
  183. },
  184. // 登陆成功
  185. countDown() {
  186. let secondsToGo = 5,that=this;
  187. const modal = this.$success({
  188. title: '登陆成功',
  189. content: `将在${secondsToGo} 秒后自动跳转页面.`,
  190. okText:'立即跳转',
  191. onOk() {
  192. window.location.href=that.jumpUrl;
  193. },
  194. });
  195. const interval = setInterval(() => {
  196. secondsToGo -= 1;
  197. modal.update({
  198. content: `将在${secondsToGo} 秒后自动跳转页面.`,
  199. });
  200. }, 1000);
  201. setTimeout(() => {
  202. window.location.href=that.jumpUrl;
  203. }, 1+(secondsToGo * 1000));
  204. },
  205. }
  206. }
  207. </script>
  208. <style>
  209. body{
  210. margin: 0;
  211. padding: 0;
  212. height: 100vh;
  213. font-family: sans-serif;
  214. }
  215. .bgimg{
  216. background: url("/public/image/big/bg.jpg") center no-repeat;
  217. }
  218. #app {
  219. font-family: Avenir, Helvetica, Arial, sans-serif;
  220. -webkit-font-smoothing: antialiased;
  221. -moz-osx-font-smoothing: grayscale;
  222. text-align: center;
  223. color: #2c3e50;
  224. width: 100%;
  225. height: 100%;
  226. }
  227. .login-box{
  228. transform: translate(-50%, -0%);
  229. background: rgba(0,0,0,.4);
  230. box-sizing: border-box;
  231. box-shadow: 0 15px 25px rgba(0,0,0,.6);
  232. border-radius: 10px;
  233. /*filter: blur(5px);*/
  234. transition: all .7s;
  235. }
  236. .blur{
  237. filter: blur(5px);
  238. box-shadow: 0 15px 25px rgba(0,0,0,.6);
  239. }
  240. .login-box h2 {
  241. margin: 0 0 30px;
  242. padding: 0;
  243. color: #fff;
  244. text-align: center;
  245. }
  246. .u{
  247. text-align: justify;
  248. text-align-last:justify;
  249. }
  250. .lbx{
  251. animation: rounded-anim1 15s linear infinite;
  252. }
  253. .map{
  254. animation: rounded-anim1 60s linear infinite;
  255. }
  256. .jt{
  257. animation: rounded-anim1 15s reverse infinite ;
  258. }
  259. .rounded-img{
  260. animation: rounded-anim1 5s reverse infinite ;
  261. }
  262. @keyframes rounded-anim1 {
  263. 0% {
  264. transform:rotate(0deg);
  265. }
  266. 100% {
  267. transform:rotate(360deg);
  268. }
  269. }
  270. </style>