Login.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <template>
  2. <div class="login-view">
  3. <div class="login-content">
  4. <div class="login-intro">
  5. <div>
  6. <h3>盒子IM 2.0版本已上线:</h3>
  7. <ul>
  8. <li>加入uniapp移动版本,支持移动端和web端同时在线,多端消息同步</li>
  9. <li>目前移动端仅兼容h5和微信小程序,后续会继续兼容更多终端类型</li>
  10. <li>聊天窗口支持粘贴截图、@群成员、已读未读显示</li>
  11. <li>页面风格升级:表情包更新、自动生成文字头像等</li>
  12. </ul>
  13. </div>
  14. <div>
  15. <h3>最近更新(2024-01-19):</h3>
  16. <ul>
  17. <li>最近给小伙伴们整理了一份
  18. <a href="https://www.yuque.com/u1475064/mufu2a" target="_blank">盒子IM详细介绍文档</a>,目前限时免费开放中
  19. </li>
  20. </ul>
  21. </div>
  22. <div>
  23. <h3>最近更新(2024-01-28):</h3>
  24. <ul>
  25. <li>支持群聊已读显示(回执消息)</li>
  26. <li>群聊会话窗口增加邀请、退群、移除、解散提示</li>
  27. </ul>
  28. </div>
  29. <div>
  30. <h3>最近更新(2024-02-24):</h3>
  31. <ul>
  32. <li>uniapp端兼容ios和andriod,
  33. <a href="https://www.boxim.online/download/boxim.apk" target="_blank">点击下载安卓客户端</a>
  34. </li>
  35. </ul>
  36. </div>
  37. <div>
  38. <h3>项目依旧完全开源,可内网部署。如果项目对您有帮助,请帮忙点个star:</h3>
  39. </div>
  40. <div class="login-icons">
  41. <a class="login-icon">
  42. <img src="https://img.shields.io/badge/license-MIT-red" />
  43. </a>
  44. <a class="login-icon" href="https://gitee.com/bluexsx/box-im" target="_blank">
  45. <img src="https://gitee.com/bluexsx/box-im/badge/star.svg" />
  46. </a>
  47. <a class="login-icon" href="https://github.com/bluexsx/box-im" target="_blank">
  48. <img src="https://img.shields.io/github/stars/bluexsx/box-im.svg?style=flat&logo=GitHub" />
  49. </a>
  50. </div>
  51. </div>
  52. <el-form class="login-form" :model="loginForm" status-icon :rules="rules" ref="loginForm" label-width="60px"
  53. @keyup.enter.native="submitForm('loginForm')">
  54. <div class="login-brand">登陆盒子IM</div>
  55. <el-form-item label="终端" prop="userName" v-show="false">
  56. <el-input type="terminal" v-model="loginForm.terminal" autocomplete="off"></el-input>
  57. </el-form-item>
  58. <el-form-item label="用户名" prop="userName">
  59. <el-input type="userName" v-model="loginForm.userName" autocomplete="off"
  60. placeholder="用户名"></el-input>
  61. </el-form-item>
  62. <el-form-item label="密码" prop="password">
  63. <el-input type="password" v-model="loginForm.password" autocomplete="off"
  64. placeholder="密码"></el-input>
  65. </el-form-item>
  66. <el-form-item>
  67. <el-button type="primary" @click="submitForm('loginForm')">登陆</el-button>
  68. <el-button @click="resetForm('loginForm')">清空</el-button>
  69. </el-form-item>
  70. <div class="register">
  71. <router-link to="/register">没有账号,前往注册</router-link>
  72. </div>
  73. </el-form>
  74. </div>
  75. <icp></icp>
  76. </div>
  77. </template>
  78. <script>
  79. import Icp from '../components/common/Icp.vue'
  80. export default {
  81. name: "login",
  82. components: {
  83. Icp
  84. },
  85. data() {
  86. var checkUsername = (rule, value, callback) => {
  87. if (!value) {
  88. return callback(new Error('请输入用户名'));
  89. }
  90. callback();
  91. };
  92. var checkPassword = (rule, value, callback) => {
  93. if (value === '') {
  94. callback(new Error('请输入密码'));
  95. }
  96. callback();
  97. };
  98. return {
  99. loginForm: {
  100. terminal: this.$enums.TERMINAL_TYPE.WEB,
  101. userName: '',
  102. password: ''
  103. },
  104. rules: {
  105. userName: [{
  106. validator: checkUsername,
  107. trigger: 'blur'
  108. }],
  109. password: [{
  110. validator: checkPassword,
  111. trigger: 'blur'
  112. }]
  113. }
  114. };
  115. },
  116. methods: {
  117. submitForm(formName) {
  118. this.$refs[formName].validate((valid) => {
  119. if (valid) {
  120. this.$http({
  121. url: "/login",
  122. method: 'post',
  123. data: this.loginForm
  124. })
  125. .then((data) => {
  126. // 保存密码到cookie(不安全)
  127. this.setCookie('username', this.loginForm.userName);
  128. this.setCookie('password', this.loginForm.password);
  129. // 保存token
  130. sessionStorage.setItem("accessToken", data.accessToken);
  131. sessionStorage.setItem("refreshToken", data.refreshToken);
  132. this.$message.success("登陆成功");
  133. this.$router.push("/home/chat");
  134. })
  135. }
  136. });
  137. },
  138. resetForm(formName) {
  139. this.$refs[formName].resetFields();
  140. },
  141. // 获取cookie、
  142. getCookie(name) {
  143. let reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
  144. let arr = document.cookie.match(reg)
  145. if (arr) {
  146. return unescape(arr[2]);
  147. }
  148. return '';
  149. },
  150. // 设置cookie,增加到vue实例方便全局调用
  151. setCookie(name, value, expiredays) {
  152. var exdate = new Date();
  153. exdate.setDate(exdate.getDate() + expiredays);
  154. document.cookie = name + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate
  155. .toGMTString());
  156. },
  157. // 删除cookie
  158. delCookie(name) {
  159. var exp = new Date();
  160. exp.setTime(exp.getTime() - 1);
  161. var cval = this.getCookie(name);
  162. if (cval != null) {
  163. document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
  164. }
  165. }
  166. },
  167. mounted() {
  168. this.loginForm.userName = this.getCookie("username");
  169. // cookie存密码并不安全,暂时是为了方便
  170. this.loginForm.password = this.getCookie("password");
  171. }
  172. }
  173. </script>
  174. <style scoped lang="scss">
  175. .login-view {
  176. width: 100%;
  177. height: 100%;
  178. background: rgb(232, 242, 255);
  179. background-size: cover;
  180. box-sizing: border-box;
  181. .login-content {
  182. position: relative;
  183. display: flex;
  184. justify-content: space-around;
  185. align-items: center;
  186. padding: 10%;
  187. .login-intro {
  188. flex: 1;
  189. padding: 40px;
  190. max-width: 600px;
  191. .login-title {
  192. text-align: center;
  193. font-weight: 600;
  194. font-size: 30px;
  195. }
  196. .login-icons {
  197. display: flex;
  198. align-items: center;
  199. .login-icon {
  200. padding-left: 5px;
  201. }
  202. }
  203. }
  204. .login-form {
  205. height: 340px;
  206. width: 400px;
  207. padding: 30px;
  208. background: white;
  209. opacity: 0.9;
  210. box-shadow: 0px 0px 1px #ccc;
  211. border-radius: 3%;
  212. overflow: hidden;
  213. border: 1px solid #ccc;
  214. .login-brand {
  215. line-height: 50px;
  216. margin: 30px 0 40px 0;
  217. font-size: 22px;
  218. font-weight: 600;
  219. letter-spacing: 2px;
  220. text-transform: uppercase;
  221. text-align: center;
  222. }
  223. .register {
  224. display: flex;
  225. flex-direction: row-reverse;
  226. line-height: 40px;
  227. text-align: left;
  228. padding-left: 20px;
  229. }
  230. }
  231. }
  232. }
  233. </style>