/src/components/Install.vue

https://github.com/zhaojun1998/zfile-vue · Vue · 157 lines · 143 code · 14 blank · 0 comment · 5 complexity · 8bf29eb5e12fa04f7392e324f94dfc1e MD5 · raw file

  1. <template>
  2. <div v-loading="fullLoading" class="zfile-install">
  3. <el-form ref="form" :rules="rules" :model="form"
  4. label-width="auto"
  5. :status-icon="true"
  6. v-loading="loading"
  7. class="zfile-install-form"
  8. element-loading-text="保存并初始化中.">
  9. <div class="zfile-install-title box animate__animated animate__fadeIn">
  10. Z-File
  11. <small>Install</small>
  12. </div>
  13. <el-form-item class="box animate__animated animate__fadeInUp" prop="siteName">
  14. <el-input placeholder="站点名称" prefix-icon="el-icon-tickets" v-model="form.siteName"/>
  15. </el-form-item>
  16. <el-form-item class="box animate__animated animate__fadeInUp" prop="username">
  17. <el-input placeholder="管理员账号" prefix-icon="el-icon-user" v-model.trim="form.username"/>
  18. </el-form-item>
  19. <el-form-item class="box animate__animated animate__fadeInUp" prop="password">
  20. <el-input placeholder="管理员密码" prefix-icon="el-icon-key" v-model.trim="form.password"/>
  21. </el-form-item>
  22. <el-form-item class="box animate__animated animate__fadeInUp" prop="domain">
  23. <el-input placeholder="站点地址/域名" prefix-icon="el-icon-link" v-model.trim="form.domain"/>
  24. </el-form-item>
  25. <el-form-item class="zfile-install-enter">
  26. <el-button type="primary" icon="el-icon-check" size="small" @click="submitForm('form')">确认</el-button>
  27. </el-form-item>
  28. </el-form>
  29. </div>
  30. </template>
  31. <script>
  32. import qs from 'qs';
  33. export default {
  34. name: "Install",
  35. data() {
  36. return {
  37. fullLoading: false,
  38. form: {
  39. siteName: '',
  40. username: '',
  41. password: '',
  42. domain: ''
  43. },
  44. loading: false,
  45. rules: {
  46. siteName: [
  47. {required: true, message: '请输入站点名称', trigger: 'change'},
  48. ],
  49. username: [
  50. {required: true, message: '请输入管理员账号', trigger: 'change'},
  51. ],
  52. password: [
  53. {required: true, message: '请输入管理员密码', trigger: 'change'},
  54. ],
  55. domain: [
  56. {required: true, type: 'url', message: '请输入正确的域名,需以 http:// 或 https:// 开头', trigger: 'change'},
  57. ]
  58. }
  59. };
  60. },
  61. mounted() {
  62. this.form.domain = this.$http.defaults.baseURL === "" ? window.location.origin : this.$http.defaults.baseURL;
  63. this.fullLoading = true;
  64. this.$http.get('/is-installed').then((response) => {
  65. if (response.data.code !== 0) {
  66. this.$router.push('/main');
  67. }
  68. this.fullLoading = false;
  69. });
  70. },
  71. methods: {
  72. submitForm(formName) {
  73. this.$refs[formName].validate((valid) => {
  74. if (valid) {
  75. this.loading = true;
  76. let that = this;
  77. this.$http.post('/doInstall', qs.stringify(this.form)).then((response) => {
  78. this.loading = false;
  79. let data = response.data;
  80. if (data.code === 0) {
  81. this.$message({
  82. message: "初始化成功",
  83. type: data.code === 0 ? 'success' : 'error',
  84. duration: 1500,
  85. onClose() {
  86. that.$router.push('/main')
  87. }
  88. });
  89. } else {
  90. this.$message({
  91. message: data.msg,
  92. type: 'error',
  93. duration: 3000,
  94. onClose() {
  95. that.$router.push('/main')
  96. }
  97. });
  98. }
  99. })
  100. } else {
  101. this.loading = false;
  102. return false;
  103. }
  104. });
  105. }
  106. }
  107. }
  108. </script>
  109. <style scoped>
  110. .zfile-install {
  111. display: flex;
  112. flex-direction: column;
  113. align-items: center;
  114. justify-content: center;
  115. width: 100%;
  116. height: 100%;
  117. }
  118. .zfile-install-form {
  119. width: 450px;
  120. padding: 30px 35px 15px;
  121. background: #fff;
  122. border: 1px solid #eaeaea;
  123. box-shadow: 0 0 15px #cac6c6;
  124. }
  125. .zfile-install-title {
  126. text-align: center;
  127. vertical-align: text-bottom;
  128. font-size: 30px;
  129. font-weight: 600;
  130. color: red;
  131. background-image: linear-gradient(-20deg, #6e45e2, #88d3ce);
  132. -webkit-text-fill-color: transparent;
  133. -webkit-background-clip: text;
  134. line-height: 80px;
  135. }
  136. .zfile-install-enter {
  137. text-align: right;
  138. margin-bottom: 0;
  139. }
  140. .zfile-install-title small {
  141. font-size: 20px;
  142. }
  143. </style>