mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-19 00:09:16 +08:00
fix: 修复 mysql utf8 数据库创建失败的问题
This commit is contained in:
parent
16080cfc11
commit
981223d9bc
@ -2,6 +2,7 @@ package v1
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
|
||||
"github.com/1Panel-dev/1Panel/backend/app/dto"
|
||||
@ -87,7 +88,7 @@ func (b *BaseApi) HandlePasswordExpired(c *gin.Context) {
|
||||
func (b *BaseApi) SyncTime(c *gin.Context) {
|
||||
ntime, err := ntp.Getremotetime()
|
||||
if err != nil {
|
||||
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
||||
helper.SuccessWithData(c, time.Now().Format("2006-01-02 15:04:05 MST -0700"))
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@ type MysqlDBInfo struct {
|
||||
|
||||
type MysqlDBCreate struct {
|
||||
Name string `json:"name" validate:"required"`
|
||||
Format string `json:"format" validate:"required,oneof=utf8mb4 utf-8 gbk big5"`
|
||||
Format string `json:"format" validate:"required,oneof=utf8mb4 utf8 gbk big5"`
|
||||
Username string `json:"username" validate:"required"`
|
||||
Password string `json:"password" validate:"required"`
|
||||
Permission string `json:"permission" validate:"required"`
|
||||
|
@ -154,6 +154,13 @@ func (u *MysqlService) ListDBName() ([]string, error) {
|
||||
return dbNames, err
|
||||
}
|
||||
|
||||
var formatMap = map[string]string{
|
||||
"utf8": "utf8_general_ci",
|
||||
"utf8mb4": "utf8mb4_general_ci",
|
||||
"gbk": "gbk_chinese_ci",
|
||||
"big5": "big5_chinese_ci",
|
||||
}
|
||||
|
||||
func (u *MysqlService) Create(ctx context.Context, req dto.MysqlDBCreate) (*model.DatabaseMysql, error) {
|
||||
if req.Username == "root" {
|
||||
return nil, errors.New("Cannot set root as user name")
|
||||
@ -170,7 +177,8 @@ func (u *MysqlService) Create(ctx context.Context, req dto.MysqlDBCreate) (*mode
|
||||
return nil, errors.WithMessage(constant.ErrStructTransform, err.Error())
|
||||
}
|
||||
|
||||
if err := excuteSql(app.ContainerName, app.Password, fmt.Sprintf("create database if not exists `%s` character set=%s", req.Name, req.Format)); err != nil {
|
||||
createSql := fmt.Sprintf("create database if not exists `%s` default character set %s collate %s", req.Name, req.Format, formatMap[req.Format])
|
||||
if err := excuteSql(app.ContainerName, app.Password, createSql); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
tmpPermission := req.Permission
|
||||
|
@ -4,7 +4,7 @@
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" href="/favicon.ico" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>-</title>
|
||||
<title>loading...</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app">
|
||||
@ -94,4 +94,4 @@
|
||||
</div>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
@ -3,7 +3,7 @@
|
||||
<slot></slot>
|
||||
</div>
|
||||
<div class="footer flx-center">
|
||||
<a href="http://www.spicyboy.cn/" target="_blank">2022 © 1Panel By 飞致云.</a>
|
||||
<a href="http://www.spicyboy.cn/" target="_blank">2023 © 1Panel By 飞致云.</a>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
<template #append>
|
||||
<el-select v-model="form.format" style="width: 125px">
|
||||
<el-option label="utf8mb4" value="utf8mb4" />
|
||||
<el-option label="utf-8" value="utf-8" />
|
||||
<el-option label="utf-8" value="utf8" />
|
||||
<el-option label="gbk" value="gbk" />
|
||||
<el-option label="big5" value="big5" />
|
||||
</el-select>
|
||||
|
@ -76,7 +76,10 @@
|
||||
<el-card class="el-card">
|
||||
<el-form ref="hostInfoRef" label-width="100px" :model="hostInfo" :rules="rules">
|
||||
<el-form-item :label="$t('terminal.ip')" prop="addr">
|
||||
<el-input clearable v-model="hostInfo.addr" />
|
||||
<span v-if="hostInfo.addr === '127.0.0.1' && hostOperation === 'edit'">
|
||||
{{ hostInfo.addr }}
|
||||
</span>
|
||||
<el-input v-else clearable v-model="hostInfo.addr" />
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('terminal.user')" prop="user">
|
||||
<el-input clearable v-model="hostInfo.user" />
|
||||
|
@ -307,6 +307,14 @@ const onReconnect = async (item: any) => {
|
||||
|
||||
const onConnTerminal = async (title: string, wsID: number, isLocal?: boolean) => {
|
||||
const res = await testByID(wsID);
|
||||
if (isLocal) {
|
||||
for (const tab of terminalTabs.value) {
|
||||
if (tab.title.indexOf('@127.0.0.1:') !== -1 || tab.title === i18n.global.t('terminal.localhost')) {
|
||||
onReconnect(tab);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
terminalTabs.value.push({
|
||||
index: tabIndex,
|
||||
title: title,
|
||||
@ -322,7 +330,7 @@ const onConnTerminal = async (title: string, wsID: number, isLocal?: boolean) =>
|
||||
ctx.refs[`t-${terminalValue.value}`][0].acceptParams({
|
||||
wsID: wsID,
|
||||
terminalID: terminalValue.value,
|
||||
error: res.data ? '' : 'Failed to set up the connection. Please check the host information !',
|
||||
error: res.data ? '' : 'Authentication failed. Please check the host information !',
|
||||
});
|
||||
});
|
||||
tabIndex++;
|
||||
|
@ -38,32 +38,11 @@
|
||||
<script setup lang="ts" name="login">
|
||||
import LoginForm from './components/login-form.vue';
|
||||
import { ref, onMounted } from 'vue';
|
||||
// import { loginStatus, entrance } from '@/api/modules/auth';
|
||||
|
||||
// interface Props {
|
||||
// code: string;
|
||||
// }
|
||||
// const mySafetyCode = withDefaults(defineProps<Props>(), {
|
||||
// code: '',
|
||||
// });
|
||||
|
||||
const statusCode = ref<number>(0);
|
||||
|
||||
const getStatus = async () => {
|
||||
statusCode.value = 1;
|
||||
// const res = await loginStatus();
|
||||
// if (res.code === 402) {
|
||||
// statusCode.value = -1;
|
||||
// } else {
|
||||
// statusCode.value = 1;
|
||||
// return;
|
||||
// }
|
||||
// if (mySafetyCode.code) {
|
||||
// const res = await entrance(mySafetyCode.code);
|
||||
// if (res.code === 200) {
|
||||
// statusCode.value = 1;
|
||||
// }
|
||||
// }
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
|
@ -105,9 +105,10 @@
|
||||
<el-form-item :label="$t('setting.syncTime')">
|
||||
<el-input disabled v-model="form.localTime">
|
||||
<template #append>
|
||||
<el-button @click="onSyncTime" icon="Refresh">
|
||||
<el-button v-show="!show" @click="onSyncTime" icon="Refresh">
|
||||
{{ $t('commons.button.sync') }}
|
||||
</el-button>
|
||||
<span v-show="show">{{ count }} S</span>
|
||||
</template>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
@ -210,6 +211,11 @@ const form = reactive({
|
||||
complexityVerification: '',
|
||||
});
|
||||
|
||||
const timer = ref();
|
||||
const TIME_COUNT = ref(10);
|
||||
const count = ref();
|
||||
const show = ref();
|
||||
|
||||
const search = async () => {
|
||||
const res = await getSettingInfo();
|
||||
form.userName = res.data.userName;
|
||||
@ -271,6 +277,21 @@ const onSave = async (formEl: FormInstance | undefined, key: string, val: any) =
|
||||
loading.value = false;
|
||||
});
|
||||
};
|
||||
|
||||
function countdown() {
|
||||
count.value = TIME_COUNT.value;
|
||||
show.value = true;
|
||||
timer.value = setInterval(() => {
|
||||
if (count.value > 0 && count.value <= TIME_COUNT.value) {
|
||||
count.value--;
|
||||
} else {
|
||||
show.value = false;
|
||||
clearInterval(timer.value);
|
||||
timer.value = null;
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
function callback(error: any) {
|
||||
if (error) {
|
||||
return error.message;
|
||||
@ -326,6 +347,7 @@ const onSyncTime = async () => {
|
||||
.then((res) => {
|
||||
loading.value = false;
|
||||
form.localTime = res.data;
|
||||
countdown();
|
||||
ElMessage.success(i18n.t('commons.msg.operationSuccess'));
|
||||
})
|
||||
.catch(() => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user