login.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. <template>
  2. <div class="login-container">
  3. <div class="login-box">
  4. <div class="login-left">
  5. <img class="login-left-img" src="/assets/img/banner.png" alt="login" />
  6. </div>
  7. <div class="login-form">
  8. <div class="login-logo">
  9. <img class="login-icon" src="{$logo}" alt="" />
  10. <h2 class="logo-text">{$sitename}</h2>
  11. </div>
  12. <el-form ref="loginForm" :model="loginForm" label-width="0px" :rules="rules">
  13. {:token_field()}
  14. <el-row>
  15. <el-col :span="thirdLogin?15:24">
  16. <el-form-item label="" prop="username">
  17. <el-input size="large" v-model="loginForm.username" placeholder="用户名">
  18. <template #prepend>
  19. <i class="fa fa-user"></i>
  20. </template>
  21. </el-input>
  22. </el-form-item>
  23. <el-form-item label="" prop="password">
  24. <el-input size="large" type="password" v-model="loginForm.password" placeholder="密码">
  25. <template #prepend>
  26. <i class="fa fa-lock"></i>
  27. </template>
  28. </el-input>
  29. </el-form-item>
  30. {if $login_captcha}
  31. <el-form-item label="" prop="captcha" style="margin-bottom:10px;">
  32. <el-row>
  33. <el-col :span="12" :xs="14">
  34. <el-input size="large" v-model="loginForm.captcha" placeholder="验证码">
  35. <template #prepend>
  36. <i class="fa fa-ellipsis-h"></i>
  37. </template>
  38. </el-input>
  39. </el-col>
  40. <el-col :span="12" :xs="10">
  41. <div class="captcha-img">
  42. <img :src="captchaUrl" @click="refreshCaptcha"/>
  43. </div>
  44. </el-col>
  45. </el-row>
  46. </el-form-item>
  47. {/if}
  48. </el-col>
  49. <el-col :span="9" v-if="thirdLogin && qrcode" class="hide-800">
  50. <div class="login-right">
  51. <img class="login-right-img" :src="qrcode" alt="login" />
  52. <span>微信扫码</span>
  53. </div>
  54. </el-col>
  55. </el-row>
  56. <el-form-item label="" prop="savepassword" style="margin-bottom:10px;">
  57. <el-checkbox-group v-model="loginForm.savepassword">
  58. <el-checkbox :label="1">{:__('记住密码')}</el-checkbox>
  59. </el-checkbox-group>
  60. </el-form-item>
  61. <el-form-item>
  62. <el-button type="primary" size="large" style="width: 100%" @click="login">登陆</el-button>
  63. </el-form-item>
  64. </el-form>
  65. </div>
  66. </div>
  67. </div>
  68. <el-dialog
  69. v-model="dialogVisible"
  70. title="选择登录账号"
  71. width="600"
  72. >
  73. <div class="login-admin">
  74. <el-radio-group v-model="checked">
  75. <el-radio v-for="item in adminlist" :label="item.id" size="large" border>{{item.nickname}}</el-radio>
  76. </el-radio-group>
  77. <span style="margin-top: 20px">您当前微信绑定了多个账户,请任选择一个登录</span>
  78. </div>
  79. <template #footer>
  80. <div class="dialog-footer">
  81. <el-button @click="cancelDialog">取消</el-button>
  82. <el-button type="primary" @click="confirmDialog">
  83. 确认
  84. </el-button>
  85. </div>
  86. </template>
  87. </el-dialog>
  88. </template>
  89. <script>
  90. export default{
  91. data(){
  92. return {
  93. thirdLogin:false,
  94. qrcode:'',
  95. captchaUrl:'',
  96. loginForm:{
  97. __token__:'',
  98. username: '',
  99. password: '',
  100. captcha: '',
  101. savepassword:[1],
  102. },
  103. rules:{
  104. username:[{required:true,message:'用户名不能为空!',}],
  105. password:[{required:true,message:'密码不能为空!',}],
  106. },
  107. dialogVisible:false,
  108. adminlist:[],
  109. checked:''
  110. }
  111. },
  112. onLoad:function (){
  113. this.refreshCaptcha();
  114. let width=document.body.clientWidth;
  115. this.thirdLogin=Yunqi.data.thirdLogin && width>800;
  116. window.addEventListener('resize',()=>{
  117. let width=document.body.clientWidth;
  118. this.thirdLogin=Yunqi.data.thirdLogin && width>800;
  119. });
  120. this.qrcode=Yunqi.data.qrcode;
  121. },
  122. onShow:function (){
  123. this.loginForm.__token__=document.getElementsByTagName('input')[0].value;
  124. this.loginForm.username= localStorage.getItem('username') || '';
  125. this.loginForm.password= localStorage.getItem('password') || '';
  126. this.loginForm.savepassword= localStorage.getItem('savepassword')? [1] : [];
  127. this.checklogin();
  128. },
  129. methods:{
  130. refreshCaptcha:function (){
  131. this.captchaUrl=Yunqi.config.baseUrl+"captcha?"+Math.random();
  132. },
  133. checklogin:function (){
  134. if(!this.thirdLogin){
  135. return;
  136. }
  137. let token=document.querySelector('input[name="__token__"]').value;
  138. Yunqi.ajax.get('qrcodeLogin', {token:token},false,false).then(res=>{
  139. Yunqi.message.success('登录成功');
  140. setTimeout(()=>{
  141. this.redirect();
  142. },1000);
  143. }).catch(err=>{
  144. if(err.data.length>0){
  145. this.adminlist=err.data;
  146. this.dialogVisible=true;
  147. return;
  148. }
  149. setTimeout(()=>{
  150. this.checklogin();
  151. },2000);
  152. });
  153. },
  154. cancelDialog:function (){
  155. location.reload();
  156. },
  157. confirmDialog:function (){
  158. let token=document.querySelector('input[name="__token__"]').value;
  159. Yunqi.ajax.get('qrcodeLogin',{token:token,admin_id:this.checked},true,false).then(res=>{
  160. this.dialogVisible=false;
  161. Yunqi.message.success('登录成功');
  162. setTimeout(()=>{
  163. this.redirect();
  164. },1000);
  165. });
  166. },
  167. redirect:function (){
  168. location.href=Yunqi.config.baseUrl+'index';
  169. },
  170. login:function (){
  171. this.$refs.loginForm.validate((valid)=>{
  172. if(valid){
  173. Yunqi.ajax.post('login',this.loginForm,true).then(res=>{
  174. let savepassword=this.loginForm.savepassword.length>0?1:0;
  175. if(savepassword){
  176. localStorage.setItem('username',this.loginForm.username);
  177. localStorage.setItem('password',this.loginForm.password);
  178. localStorage.setItem('savepassword',savepassword);
  179. }else{
  180. localStorage.removeItem('username');
  181. localStorage.removeItem('password');
  182. localStorage.removeItem('savepassword');
  183. }
  184. this.redirect();
  185. }).catch(err=>{
  186. if(err.data){
  187. this.refreshCaptcha();
  188. }
  189. });
  190. }
  191. });
  192. }
  193. }
  194. }
  195. </script>
  196. <style>
  197. body {
  198. color: #999;
  199. }
  200. .login-container {
  201. height: 100%;
  202. min-height: 550px;
  203. display: flex;
  204. align-items: center;
  205. justify-content: center;
  206. position: fixed;
  207. left: 0;
  208. right: 0;
  209. bottom: 0;
  210. top: 0;
  211. background-color: #eeeeee;
  212. background-image: url("/assets/img/bg.svg");
  213. background-size: 100% 100%;
  214. background-size: cover;
  215. }
  216. .login-container .login-box {
  217. position: relative;
  218. box-sizing: border-box;
  219. display: flex;
  220. align-items: center;
  221. justify-content: space-around;
  222. width: 96.5%;
  223. height: 94%;
  224. padding: 0 50px;
  225. background-color: rgba(255, 255, 255, 0.8);
  226. border-radius: 10px;
  227. }
  228. .login-container .login-box .under {
  229. position: absolute;
  230. top: 13px;
  231. left: 18px;
  232. }
  233. .login-container .login-box .under a{
  234. text-decoration:none;
  235. font-size: 16px;
  236. color: #4c4c4c;
  237. }
  238. .login-container .login-box .under span{
  239. font-size: 16px;
  240. color: #4c4c4c;
  241. margin-left: 20px;
  242. cursor: pointer;
  243. }
  244. .login-container .login-box .login-left {
  245. width: 800px;
  246. margin-right: 10px;
  247. text-align: center;
  248. }
  249. .login-container .login-box .login-left .login-left-img {
  250. width: 80%;
  251. }
  252. .login-container .login-box .login-form {
  253. width: 420px;
  254. padding: 50px 40px 0px;
  255. background-color: var(--el-bg-color);
  256. border-radius: 10px;
  257. box-shadow: rgba(0, 0, 0, 0.1) 0 2px 10px 2px;
  258. }
  259. .login-container .login-box .login-form .login-logo {
  260. display: flex;
  261. align-items: center;
  262. justify-content: center;
  263. margin-bottom: 45px;
  264. }
  265. .login-container .login-box .login-form .login-logo .login-icon {
  266. width: 80px;
  267. }
  268. .login-container .login-box .login-form .login-logo .logo-text {
  269. padding: 0 0 0 25px;
  270. margin: 0;
  271. font-size: 42px;
  272. font-weight: bold;
  273. color: #34495e;
  274. white-space: nowrap;
  275. }
  276. .login-container .login-box .login-form .el-form-item {
  277. margin-bottom: 10px;
  278. }
  279. .login-container .login-box .login-form .login-btn {
  280. display: flex;
  281. justify-content: space-between;
  282. width: 100%;
  283. margin-top: 40px;
  284. white-space: nowrap;
  285. }
  286. .login-container .login-box .login-form .login-btn .el-button {
  287. width: 185px;
  288. }
  289. .captcha-img img{
  290. width: 125px;
  291. }
  292. .login-right{
  293. display: flex;
  294. flex-direction: column;
  295. margin-left: 10px;
  296. align-items: center;
  297. justify-content: center;
  298. }
  299. .login-right-img{
  300. width: 125px;
  301. }
  302. @media screen and (max-width: 1250px) {
  303. .login-left {
  304. display: none;
  305. }
  306. }
  307. @media screen and (max-width: 600px) {
  308. .login-box{
  309. padding: 0 20px!important;
  310. }
  311. .login-form {
  312. width: 100% !important;
  313. padding: 10px !important;
  314. }
  315. .captcha-img img{
  316. width: 120px;
  317. }
  318. .login-icon {
  319. width: 20%!important;
  320. }
  321. .login-logo{
  322. margin: 20px 0!important;
  323. }
  324. .logo-text {
  325. font-size: 32px!important;
  326. }
  327. }
  328. .login-admin{
  329. display: flex;
  330. flex-direction: column;
  331. }
  332. </style>