index.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. <template>
  2. <div class="go-login-box">
  3. <div class="go-login-box-bg">
  4. <aside class="bg-slot"></aside>
  5. <aside class="bg-img-box">
  6. <transition-group name="list-complete">
  7. <template v-for="item in bgList" :key="item">
  8. <div class="bg-img-box-li list-complete-item">
  9. <n-collapse-transition :appear="true" :show="show">
  10. <img :src="getImageUrl(item, 'chart')" alt="chart" />
  11. </n-collapse-transition>
  12. </div>
  13. </template>
  14. </transition-group>
  15. </aside>
  16. </div>
  17. <n-divider class="go-login-box-header" />
  18. <div class="go-login">
  19. <div class="go-login-carousel">
  20. <n-carousel autoplay :interval="Number(carouselInterval)">
  21. <img
  22. v-for="(item, i) in carouselImgList"
  23. :key="i"
  24. class="go-login-carousel-img"
  25. :src="getImageUrl(item, 'login')"
  26. alt="展示图片"
  27. />
  28. </n-carousel>
  29. </div>
  30. <div class="login-account">
  31. <div class="login-account-container">
  32. <n-collapse-transition :appear="true" :show="show">
  33. <n-card class="login-account-card" title="登录 GoView">
  34. <div class="login-account-top">
  35. <img
  36. class="login-account-top-logo"
  37. src="~@/assets/images/logo.png"
  38. alt="logo"
  39. />
  40. </div>
  41. <n-form
  42. ref="formRef"
  43. label-placement="left"
  44. size="large"
  45. :model="formInline"
  46. :rules="rules"
  47. >
  48. <n-form-item path="username">
  49. <n-input
  50. v-model:value="formInline.username"
  51. placeholder="请输入用户名"
  52. >
  53. <template #prefix>
  54. <n-icon size="18">
  55. <PersonOutline />
  56. </n-icon>
  57. </template>
  58. </n-input>
  59. </n-form-item>
  60. <n-form-item path="password">
  61. <n-input
  62. v-model:value="formInline.password"
  63. type="password"
  64. show-password-toggle
  65. placeholder="请输入密码"
  66. >
  67. <template #prefix>
  68. <n-icon size="18">
  69. <LockClosedOutline />
  70. </n-icon>
  71. </template>
  72. </n-input>
  73. </n-form-item>
  74. <n-form-item>
  75. <div class="flex justify-between">
  76. <div class="flex-initial">
  77. <n-checkbox v-model:checked="autoLogin">
  78. 自动登录
  79. </n-checkbox>
  80. </div>
  81. </div>
  82. </n-form-item>
  83. <n-form-item>
  84. <n-button
  85. type="primary"
  86. @click="handleSubmit"
  87. size="large"
  88. :loading="loading"
  89. block
  90. >
  91. 登录
  92. </n-button>
  93. </n-form-item>
  94. </n-form>
  95. </n-card>
  96. </n-collapse-transition>
  97. </div>
  98. </div>
  99. </div>
  100. <div class="go-login-box-footer">
  101. <n-a>文档地址: </n-a>
  102. <n-a italic href="http://www.mtruning.club/">
  103. http://www.mtruning.club/
  104. </n-a>
  105. </div>
  106. </div>
  107. </template>
  108. <script lang="ts" setup>
  109. import { reactive, ref, onMounted } from 'vue'
  110. import { useRouter } from 'vue-router'
  111. import { useMessage } from 'naive-ui'
  112. import { PersonOutline, LockClosedOutline } from '@vicons/ionicons5'
  113. import { requireUrl } from '@/utils/index'
  114. import { shuffle } from 'lodash'
  115. import { carouselInterval } from '@/settings/designSetting'
  116. interface FormState {
  117. username: string
  118. password: string
  119. }
  120. const router = useRouter()
  121. const formRef = ref()
  122. const message = useMessage()
  123. const loading = ref(false)
  124. const autoLogin = ref(true)
  125. const show = ref(false)
  126. onMounted(() => {
  127. setTimeout(() => {
  128. show.value = true
  129. }, 100)
  130. })
  131. const formInline = reactive({
  132. username: 'admin',
  133. password: '123456'
  134. })
  135. const rules = {
  136. username: { required: true, message: '请输入用户名', trigger: 'blur' },
  137. password: { required: true, message: '请输入密码', trigger: 'blur' }
  138. }
  139. // 定时器
  140. const shuffleTimiing = ref()
  141. // 轮播图
  142. const carouselImgList = ['one', 'two', 'three']
  143. // 背景图
  144. const bgList = ref([
  145. 'bar_y',
  146. 'bar_x',
  147. 'line_gradient',
  148. 'line',
  149. 'funnel',
  150. 'heatmap',
  151. 'map',
  152. 'pie',
  153. 'radar',
  154. ])
  155. // 处理url获取
  156. const getImageUrl = (name: string, folder: string) => {
  157. return requireUrl(`../assets/images/${folder}`, `${name}.png`)
  158. }
  159. // 打乱
  160. const shuffleHandle = () => {
  161. shuffleTimiing.value = setInterval(() => {
  162. bgList.value = shuffle(bgList.value)
  163. }, carouselInterval)
  164. }
  165. // 点击事件
  166. const handleSubmit = (e: Event) => {
  167. e.preventDefault()
  168. formRef.value.validate(async (errors: any) => {
  169. if (!errors) {
  170. const { username, password } = formInline
  171. loading.value = true
  172. message.success('登录成功!')
  173. router.replace('/')
  174. } else {
  175. message.error('请填写完整信息,并且进行验证码校验')
  176. }
  177. })
  178. }
  179. onMounted(() => {
  180. shuffleHandle()
  181. })
  182. </script>
  183. <style lang="scss" scoped>
  184. $width: 450px;
  185. $go-login-height: 100vh;
  186. $account-img-height: 270px;
  187. $footer-height: 50px;
  188. $carousel-width: 30%;
  189. $carousel-image-height: 60vh;
  190. $--filter-color-base-login: rgba(89, 95, 103, 0.45);
  191. * {
  192. box-sizing: border-box;
  193. }
  194. @include go(login-box) {
  195. height: $go-login-height;
  196. overflow: hidden;
  197. background-image: linear-gradient(
  198. 120deg,
  199. $--color-bg-1 0%,
  200. $--color-bg-2 100%
  201. );
  202. &-header {
  203. margin: 0px;
  204. padding-top: $--header-height;
  205. }
  206. @include go(login) {
  207. z-index: 2;
  208. display: flex;
  209. justify-content: space-around;
  210. align-items: center;
  211. margin-top: -$--header-height;
  212. height: $go-login-height;
  213. max-width: $--max-width;
  214. &-carousel {
  215. width: $carousel-width;
  216. margin-top: 100px;
  217. min-width: 500px;
  218. &-img {
  219. display: block;
  220. margin: 0 auto;
  221. height: $carousel-image-height;
  222. }
  223. }
  224. .login-account {
  225. display: flex;
  226. flex-direction: column;
  227. margin: 0 160px;
  228. &-container {
  229. width: $width;
  230. }
  231. &-card {
  232. @extend .go-background-filter;
  233. background-color: $--filter-color-base-login;
  234. box-shadow: 0 0 105px 50px #202020;
  235. }
  236. &-top {
  237. padding-top: 10px;
  238. text-align: center;
  239. height: $account-img-height;
  240. margin-bottom: 20px;
  241. }
  242. }
  243. }
  244. &-footer {
  245. z-index: 2;
  246. position: fixed;
  247. bottom: 0;
  248. width: 100%;
  249. height: $footer-height;
  250. text-align: center;
  251. line-height: $footer-height;
  252. color: $--color-text-2;
  253. }
  254. &-bg {
  255. z-index: 0;
  256. position: fixed;
  257. display: flex;
  258. justify-content: space-around;
  259. align-items: center;
  260. width: $--max-width;
  261. height: 100vh;
  262. background: url('@/assets/images/login/login-bg.png') no-repeat 0 -120px;
  263. .bg-slot{
  264. width: $carousel-width;
  265. }
  266. .bg-img-box {
  267. position: relative;
  268. display: flex;
  269. flex-wrap: wrap;
  270. width: 770px;
  271. margin-right: -20px;
  272. &-li {
  273. img {
  274. margin-right: 20px;
  275. margin-top: 20px;
  276. height: 230px;
  277. border-radius: 2 * $--border-radius-base;
  278. opacity: 0.9;
  279. }
  280. }
  281. }
  282. }
  283. }
  284. @media only screen and (max-width: 1200px) {
  285. .bg-img-box,
  286. .bg-slot,
  287. .go-login-carousel {
  288. display: none !important;
  289. }
  290. .go-login-box-footer {
  291. position: relative;
  292. }
  293. }
  294. </style>