Login.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <template>
  2. <div class="login-view">
  3. <div class="login-content">
  4. <div class="login-intro">
  5. <div>
  6. <h3>盒子IM 3.0版本已上线(2024-08-04):</h3>
  7. <ul>
  8. <li>后台管理端上线,后台管理代码仓库地址:https://gitee.com/bluexsx/box-im-admin</li>
  9. <li>框架和组件版本全面升级: jdk17、springboot3.3、node18等</li>
  10. <li>部分界面,功能、性能优化</li>
  11. <li>语雀详细文档:
  12. <a href="https://www.yuque.com/u1475064/mufu2a" target="_blank">盒子IM详细介绍文档</a>
  13. </li>
  14. </ul>
  15. </div>
  16. <div>
  17. <h3>温馨提示:</h3>
  18. <ul>
  19. <li>在管理后台可以看到所有人的消息,请小伙伴们在测试时不要发送任何涉及自身隐私或机密信息,以避免信息泄露!</li>
  20. <li>音视频通话部分源码未开源,可付费获取:
  21. <a href="https://www.yuque.com/u1475064/mufu2a/vi7engzluty594s2" target="_blank">音视频源码购买说明</a>
  22. </li>
  23. </ul>
  24. </div>
  25. <div>
  26. <h3>如果本项目对您有帮助,请在Gitee上帮忙点亮star</h3>
  27. </div>
  28. <div class="login-icons">
  29. <a class="login-icon">
  30. <img src="https://img.shields.io/badge/license-MIT-red" />
  31. </a>
  32. <a class="login-icon" href="https://gitee.com/bluexsx/box-im" target="_blank">
  33. <img src="https://gitee.com/bluexsx/box-im/badge/star.svg" />
  34. </a>
  35. <a class="login-icon" href="https://github.com/bluexsx/box-im" target="_blank">
  36. <img src="https://img.shields.io/github/stars/bluexsx/box-im.svg?style=flat&logo=GitHub" />
  37. </a>
  38. </div>
  39. </div>
  40. <el-form class="login-form" :model="loginForm" status-icon :rules="rules" ref="loginForm" label-width="60px"
  41. @keyup.enter.native="submitForm('loginForm')">
  42. <div class="login-brand">登陆盒子IM</div>
  43. <el-form-item label="终端" prop="userName" v-show="false">
  44. <el-input type="terminal" v-model="loginForm.terminal" autocomplete="off"></el-input>
  45. </el-form-item>
  46. <el-form-item label="用户名" prop="userName">
  47. <el-input type="userName" v-model="loginForm.userName" autocomplete="off"
  48. placeholder="用户名"></el-input>
  49. </el-form-item>
  50. <el-form-item label="密码" prop="password">
  51. <el-input type="password" v-model="loginForm.password" autocomplete="off"
  52. placeholder="密码"></el-input>
  53. </el-form-item>
  54. <el-form-item>
  55. <el-button type="primary" @click="submitForm('loginForm')">登陆</el-button>
  56. <el-button @click="resetForm('loginForm')">清空</el-button>
  57. </el-form-item>
  58. <div class="register">
  59. <router-link to="/register">没有账号,前往注册</router-link>
  60. </div>
  61. </el-form>
  62. </div>
  63. <icp></icp>
  64. </div>
  65. </template>
  66. <script>
  67. import Icp from '../components/common/Icp.vue'
  68. export default {
  69. name: "login",
  70. components: {
  71. Icp
  72. },
  73. data() {
  74. var checkUsername = (rule, value, callback) => {
  75. if (!value) {
  76. return callback(new Error('请输入用户名'));
  77. }
  78. callback();
  79. };
  80. var checkPassword = (rule, value, callback) => {
  81. if (value === '') {
  82. callback(new Error('请输入密码'));
  83. }
  84. callback();
  85. };
  86. return {
  87. loginForm: {
  88. terminal: this.$enums.TERMINAL_TYPE.WEB,
  89. userName: '',
  90. password: ''
  91. },
  92. rules: {
  93. userName: [{
  94. validator: checkUsername,
  95. trigger: 'blur'
  96. }],
  97. password: [{
  98. validator: checkPassword,
  99. trigger: 'blur'
  100. }]
  101. }
  102. };
  103. },
  104. methods: {
  105. submitForm(formName) {
  106. this.$refs[formName].validate((valid) => {
  107. if (valid) {
  108. this.$http({
  109. url: "/login",
  110. method: 'post',
  111. data: this.loginForm
  112. })
  113. .then((data) => {
  114. // 保存密码到cookie(不安全)
  115. this.setCookie('username', this.loginForm.userName);
  116. this.setCookie('password', this.loginForm.password);
  117. // 保存token
  118. sessionStorage.setItem("accessToken", data.accessToken);
  119. sessionStorage.setItem("refreshToken", data.refreshToken);
  120. this.$message.success("登陆成功");
  121. this.$router.push("/home/chat");
  122. })
  123. }
  124. });
  125. },
  126. resetForm(formName) {
  127. this.$refs[formName].resetFields();
  128. },
  129. // 获取cookie、
  130. getCookie(name) {
  131. let reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
  132. let arr = document.cookie.match(reg)
  133. if (arr) {
  134. return unescape(arr[2]);
  135. }
  136. return '';
  137. },
  138. // 设置cookie,增加到vue实例方便全局调用
  139. setCookie(name, value, expiredays) {
  140. var exdate = new Date();
  141. exdate.setDate(exdate.getDate() + expiredays);
  142. document.cookie = name + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate
  143. .toGMTString());
  144. },
  145. // 删除cookie
  146. delCookie(name) {
  147. var exp = new Date();
  148. exp.setTime(exp.getTime() - 1);
  149. var cval = this.getCookie(name);
  150. if (cval != null) {
  151. document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
  152. }
  153. }
  154. },
  155. mounted() {
  156. this.loginForm.userName = this.getCookie("username");
  157. // cookie存密码并不安全,暂时是为了方便
  158. this.loginForm.password = this.getCookie("password");
  159. }
  160. }
  161. </script>
  162. <style scoped lang="scss">
  163. .login-view {
  164. width: 100%;
  165. height: 100%;
  166. background: #E8F2FF;
  167. background-size: cover;
  168. box-sizing: border-box;
  169. .login-content {
  170. position: relative;
  171. display: flex;
  172. justify-content: space-around;
  173. align-items: center;
  174. padding: 10%;
  175. .login-intro {
  176. flex: 1;
  177. padding: 40px;
  178. max-width: 600px;
  179. .login-title {
  180. text-align: center;
  181. font-weight: 600;
  182. font-size: 30px;
  183. }
  184. .login-icons {
  185. display: flex;
  186. align-items: center;
  187. .login-icon {
  188. padding-left: 5px;
  189. }
  190. }
  191. }
  192. .login-form {
  193. height: 340px;
  194. width: 400px;
  195. padding: 30px;
  196. background: white;
  197. opacity: 0.9;
  198. box-shadow: 0px 0px 1px #ccc;
  199. border-radius: 3%;
  200. overflow: hidden;
  201. border: 1px solid #ccc;
  202. .login-brand {
  203. line-height: 50px;
  204. margin: 30px 0 40px 0;
  205. font-size: 22px;
  206. font-weight: 600;
  207. letter-spacing: 2px;
  208. text-transform: uppercase;
  209. text-align: center;
  210. }
  211. .register {
  212. display: flex;
  213. flex-direction: row-reverse;
  214. line-height: 40px;
  215. text-align: left;
  216. padding-left: 20px;
  217. }
  218. }
  219. }
  220. }
  221. </style>