自动初始化整体调试完成

This commit is contained in:
pixel
2021-03-04 19:38:07 +08:00
parent 4a995a1c56
commit 184b1a903f
14 changed files with 273 additions and 32 deletions
+12 -1
View File
@@ -5,9 +5,20 @@
</template>
<script>
import { checkDB } from "@/api/initdb"
export default {
name: 'app',
components: {}
async created(){
const res = await checkDB()
if(res.code == 0 && res.data.needInit){
this.$message({
type:"info",
message:"您是第一次使用,请初始化"
})
this.$store.commit("user/NeedInit")
this.$router.push({name:"init"})
}
}
}
</script>
+29
View File
@@ -0,0 +1,29 @@
import service from '@/utils/request'
// @Tags InitDB
// @Summary 初始化用户数据库
// @Produce application/json
// @Param data body request.InitDB true "初始化数据库参数"
// @Success 200 {string} string "{"code":0,"data":{},"msg":"自动创建数据库成功"}"
// @Router /init/initdb [post]
export const initDB = (data) => {
return service({
url: "/init/initdb",
method: 'post',
data
})
}
// @Tags CheckDB
// @Summary 初始化用户数据库
// @Produce application/json
// @Success 200 {string} string "{"code":0,"data":{},"msg":"探测完成"}"
// @Router /init/checkdb [post]
export const checkDB = () => {
return service({
url: "/init/checkdb",
method: 'post',
})
}
+1 -1
View File
@@ -4,7 +4,7 @@ import getPageTitle from '@/utils/page'
let asyncRouterFlag = 0
const whiteList = ['login']
const whiteList = ['login','init']
router.beforeEach(async(to, from, next) => {
const token = store.getters['user/token']
// 在白名单中的判断情况
+16 -10
View File
@@ -7,19 +7,25 @@ Vue.use(Router)
const originalPush = Router.prototype.push
//修改原型对象中的push方法
Router.prototype.push = function push(location) {
return originalPush.call(this, location).catch(err => err)
return originalPush.call(this, location).catch(err => err)
}
const baseRouters = [{
path: '/',
redirect: '/login'
},
{
path: '/login',
name: 'login',
component: () =>
import ('@/view/login/login.vue')
}
path: '/',
redirect: '/login'
},
{
path: "/init",
name: 'init',
component: () =>
import('@/view/init/init.vue')
},
{
path: '/login',
name: 'login',
component: () =>
import('@/view/login/login.vue')
}
]
// 需要通过后台数据来生成的组件
+4 -1
View File
@@ -42,7 +42,10 @@ export const router = {
children: []
}]
const asyncRouterRes = await asyncMenu()
const asyncRouter = asyncRouterRes.data.menus
if(asyncRouterRes.code !=0){
return
}
const asyncRouter = asyncRouterRes.data&&asyncRouterRes.data.menus
asyncRouter.push({
path: "404",
name: "404",
+7
View File
@@ -21,6 +21,13 @@ export const user = {
// 这里的 `state` 对象是模块的局部状态
state.token = token
},
NeedInit(state){
state.userInfo = {}
state.token = ""
sessionStorage.clear()
router.push({ name: 'init', replace: true })
},
LoginOut(state) {
state.userInfo = {}
state.token = ""
+106
View File
@@ -0,0 +1,106 @@
<template>
<div class="init">
<p class="in-one a-fadeinT">欢迎使用GIN-VUE-ADMIN</p>
<p class="in-two a-fadeinT">您需要初始化您的数据库并且填充初始数据</p>
<div class="form-card in-three a-fadeinB">
<el-form ref="form" :model="form" label-width="100px">
<el-form-item label="数据库类型">
<el-select disabled v-model="form.sqlType" placeholder="请选择">
<el-option key="mysql" label="mysql(目前只支持mysql)" value="mysql">
</el-option>
</el-select>
</el-form-item>
<el-form-item label="host">
<el-input v-model="form.host" placeholder="请输入数据库链接"></el-input>
</el-form-item>
<el-form-item label="port">
<el-input v-model="form.port" placeholder="请输入数据库端口"></el-input>
</el-form-item>
<el-form-item label="userName">
<el-input v-model="form.userName" placeholder="请输入数据库用户名"></el-input>
</el-form-item>
<el-form-item label="password">
<el-input
v-model="form.password"
placeholder="请输入数据库密码(没有则为空)"
></el-input>
</el-form-item>
<el-form-item label="dbName">
<el-input v-model="form.dbName" placeholder="请输入数据库名称"></el-input>
</el-form-item>
<el-form-item>
<div style="text-align: right">
<el-button type="primary" @click="onSubmit">立即初始化</el-button>
</div>
</el-form-item>
</el-form>
</div>
</div>
</template>
<script>
import { initDB } from "@/api/initdb";
export default {
name: "Init",
data() {
return {
form: {
sqlType: "mysql",
host: "127.0.0.1",
port: "3306",
userName: "root",
password: "",
dbName: "gva",
},
};
},
methods: {
async onSubmit() {
const loading = this.$loading({
lock: true,
text: "正在初始化数据库,请稍候",
spinner: "el-icon-loading",
background: "rgba(0, 0, 0, 0.7)",
});
try {
const res = await initDB(this.form);
if (res.code == 0) {
this.$message({
type: "success",
message: res.msg,
});
this.$router.push({name:"login"})
}
loading.close();
} catch (err) {
loading.close();
}
},
},
};
</script>
<style lang="scss">
.init {
height: 100vh;
flex-direction: column;
display: flex;
align-items: center;
background: #fff;
}
.in-one {
font-size: 26px;
line-height: 98px;
}
.in-two {
font-size: 22px;
}
.form-card {
margin-top: 60px;
box-shadow: 0px 0px 5px 0px rgba(5, 12, 66, 0.15);
width: 60vw;
height: auto;
background: #fff;
padding: 20px;
border-radius: 6px;
}
</style>