1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-19 08:19:15 +08:00

fix: 初始化安装时,增加默认版本

This commit is contained in:
ssongliu 2023-03-14 17:14:57 +08:00 committed by ssongliu
parent bdcca7f380
commit 0fe1fd3c7b
5 changed files with 27 additions and 178 deletions

View File

@ -13,5 +13,6 @@ type System struct {
BaseDir string `mapstructure:"base_dir"` BaseDir string `mapstructure:"base_dir"`
Mode string `mapstructure:"mode"` Mode string `mapstructure:"mode"`
RepoUrl string `mapstructure:"repo_url"` RepoUrl string `mapstructure:"repo_url"`
Version string `mapstructure:"version"`
IsDemo bool `mapstructure:"is_demo"` IsDemo bool `mapstructure:"is_demo"`
} }

View File

@ -136,7 +136,7 @@ var AddTableSetting = &gormigrate.Migration{
if err := tx.Create(&model.Setting{Key: "DingVars", Value: ""}).Error; err != nil { if err := tx.Create(&model.Setting{Key: "DingVars", Value: ""}).Error; err != nil {
return err return err
} }
if err := tx.Create(&model.Setting{Key: "SystemVersion", Value: "v1.0.0"}).Error; err != nil { if err := tx.Create(&model.Setting{Key: "SystemVersion", Value: global.CONF.System.Version}).Error; err != nil {
return err return err
} }
if err := tx.Create(&model.Setting{Key: "SystemStatus", Value: "Free"}).Error; err != nil { if err := tx.Create(&model.Setting{Key: "SystemStatus", Value: "Free"}).Error; err != nil {

View File

@ -20,6 +20,7 @@ func Init() {
baseDir := "/opt" baseDir := "/opt"
port := "9999" port := "9999"
mode := "" mode := ""
version := ""
fileOp := files.NewFileOp() fileOp := files.NewFileOp()
v := viper.NewWithOptions() v := viper.NewWithOptions()
v.SetConfigType("yaml") v.SetConfigType("yaml")
@ -38,23 +39,9 @@ func Init() {
panic(fmt.Errorf("Fatal error config file: %s \n", err)) panic(fmt.Errorf("Fatal error config file: %s \n", err))
} }
} else { } else {
stdout, err := cmd.Exec("grep '^BASE_DIR=' /usr/bin/1pctl | cut -d'=' -f2") baseDir = loadParams("BASE_DIR")
if err != nil { port = loadParams("PANEL_PORT")
panic(err) version = loadParams("ORIGINAL_INSTALLED_VERSION")
}
baseDir = strings.ReplaceAll(stdout, "\n", "")
if len(baseDir) == 0 {
panic("error `BASE_DIR` find in /usr/bin/1pctl")
}
stdoutPort, err := cmd.Exec("grep '^PANEL_PORT=' /usr/bin/1pctl | cut -d'=' -f2")
if err != nil {
panic(err)
}
port = strings.ReplaceAll(stdoutPort, "\n", "")
if len(port) == 0 {
panic("error `PANEL_PORT` find in /usr/bin/1pctl")
}
if strings.HasSuffix(baseDir, "/") { if strings.HasSuffix(baseDir, "/") {
baseDir = baseDir[:strings.LastIndex(baseDir, "/")] baseDir = baseDir[:strings.LastIndex(baseDir, "/")]
@ -79,6 +66,9 @@ func Init() {
if mode == "dev" && fileOp.Stat("/opt/1panel/conf/app.yaml") && serverConfig.System.Port != "" { if mode == "dev" && fileOp.Stat("/opt/1panel/conf/app.yaml") && serverConfig.System.Port != "" {
port = serverConfig.System.Port port = serverConfig.System.Port
} }
if mode == "dev" && fileOp.Stat("/opt/1panel/conf/app.yaml") && serverConfig.System.Version != "" {
version = serverConfig.System.Version
}
global.CONF = serverConfig global.CONF = serverConfig
global.CONF.BaseDir = baseDir global.CONF.BaseDir = baseDir
@ -90,5 +80,18 @@ func Init() {
global.CONF.System.LogPath = global.CONF.System.DataDir + "/log" global.CONF.System.LogPath = global.CONF.System.DataDir + "/log"
global.CONF.System.TmpDir = global.CONF.System.DataDir + "/tmp" global.CONF.System.TmpDir = global.CONF.System.DataDir + "/tmp"
global.CONF.System.Port = port global.CONF.System.Port = port
global.CONF.System.Version = version
global.Viper = v global.Viper = v
} }
func loadParams(param string) string {
stdout, err := cmd.Execf("grep '^%s=' /usr/bin/1pctl | cut -d'=' -f2", param)
if err != nil {
panic(err)
}
baseDir := strings.ReplaceAll(stdout, "\n", "")
if len(baseDir) == 0 {
panic(fmt.Sprintf("error `%s` find in /usr/bin/1pctl", param))
}
return baseDir
}

View File

@ -61,11 +61,10 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { ref } from 'vue'; import { onBeforeUnmount, ref } from 'vue';
import { ContainerStats } from '@/api/modules/container'; import { ContainerStats } from '@/api/modules/container';
import { dateFormatForSecond } from '@/utils/util'; import { dateFormatForSecond } from '@/utils/util';
import VCharts from '@/components/v-charts/index.vue'; import VCharts from '@/components/v-charts/index.vue';
// import * as echarts from 'echarts';
import i18n from '@/lang'; import i18n from '@/lang';
import DrawerHeader from '@/components/drawer-header/index.vue'; import DrawerHeader from '@/components/drawer-header/index.vue';
@ -223,6 +222,10 @@ const handleClose = async () => {
chartsOption.value = { cpuChart: null, memoryChart: null, ioChart: null, networkChart: null }; chartsOption.value = { cpuChart: null, memoryChart: null, ioChart: null, networkChart: null };
}; };
onBeforeUnmount(() => {
handleClose;
});
defineExpose({ defineExpose({
acceptParams, acceptParams,
}); });

View File

@ -199,7 +199,6 @@
<script lang="ts" setup> <script lang="ts" setup>
import { onMounted, onBeforeUnmount, ref, reactive } from 'vue'; import { onMounted, onBeforeUnmount, ref, reactive } from 'vue';
// import * as echarts from 'echarts';
import Status from '@/views/home/status/index.vue'; import Status from '@/views/home/status/index.vue';
import App from '@/views/home/app/index.vue'; import App from '@/views/home/app/index.vue';
import VCharts from '@/components/v-charts/index.vue'; import VCharts from '@/components/v-charts/index.vue';
@ -211,8 +210,6 @@ import { useRouter } from 'vue-router';
import RouterButton from '@/components/router-button/index.vue'; import RouterButton from '@/components/router-button/index.vue';
import { loadBaseInfo, loadCurrentInfo } from '@/api/modules/dashboard'; import { loadBaseInfo, loadCurrentInfo } from '@/api/modules/dashboard';
import { getIOOptions, getNetworkOptions } from '@/api/modules/monitor'; import { getIOOptions, getNetworkOptions } from '@/api/modules/monitor';
// import { GlobalStore } from '@/store';
// const globalStore = GlobalStore();
const router = useRouter(); const router = useRouter();
const statuRef = ref(); const statuRef = ref();
@ -451,7 +448,6 @@ function loadUpTime(uptime: number) {
const loadData = async () => { const loadData = async () => {
if (chartOption.value === 'io') { if (chartOption.value === 'io') {
chartsOption.value['ioChart'] = { chartsOption.value['ioChart'] = {
// title: i18n.global.t('home.io'),
xDatas: timeIODatas.value, xDatas: timeIODatas.value,
yDatas: [ yDatas: [
{ {
@ -465,54 +461,8 @@ const loadData = async () => {
], ],
formatStr: 'MB', formatStr: 'MB',
}; };
// let ioReadYDatas = {
// name: i18n.global.t('monitor.read'),
// type: 'line',
// areaStyle: {
// color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
// {
// offset: 0,
// color: 'rgba(27, 143, 60, 1)',
// },
// {
// offset: 1,
// color: 'rgba(27, 143, 60, 0)',
// },
// ]),
// },
// data: ioReadBytes.value,
// showSymbol: false,
// };
// let ioWriteYDatas = {
// name: i18n.global.t('monitor.write'),
// type: 'line',
// areaStyle: {
// color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
// {
// offset: 0,
// color: 'rgba(0, 94, 235, 1)',
// },
// {
// offset: 1,
// color: 'rgba(0, 94, 235, 0)',
// },
// ]),
// },
// data: ioWriteBytes.value,
// showSymbol: false,
// };
// freshChart(
// 'ioChart',
// [i18n.global.t('monitor.read'), i18n.global.t('monitor.write')],
// timeIODatas.value,
// [ioReadYDatas, ioWriteYDatas],
// i18n.global.t('home.io'),
// 'MB',
// );
} else { } else {
chartsOption.value['networkChart'] = { chartsOption.value['networkChart'] = {
// title: i18n.global.t('home.network'),
xDatas: timeNetDatas.value, xDatas: timeNetDatas.value,
yDatas: [ yDatas: [
{ {
@ -526,116 +476,9 @@ const loadData = async () => {
], ],
formatStr: 'KB/s', formatStr: 'KB/s',
}; };
// let netTxYDatas = {
// name: i18n.global.t('monitor.up'),
// type: 'line',
// areaStyle: {
// color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
// {
// offset: 0,
// color: 'rgba(0, 94, 235, .5)',
// },
// {
// offset: 1,
// color: 'rgba(0, 94, 235, 0)',
// },
// ]),
// },
// data: netBytesRecvs.value,
// showSymbol: false,
// };
// let netRxYDatas = {
// name: i18n.global.t('monitor.down'),
// type: 'line',
// areaStyle: {
// color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
// {
// offset: 0,
// color: 'rgba(27, 143, 60, .5)',
// },
// {
// offset: 1,
// color: 'rgba(27, 143, 60, 0)',
// },
// ]),
// },
// data: netBytesSents.value,
// showSymbol: false,
// };
// freshChart(
// 'networkChart',
// [i18n.global.t('monitor.up'), i18n.global.t('monitor.down')],
// timeNetDatas.value,
// [netTxYDatas, netRxYDatas],
// i18n.global.t('home.network'),
// 'KB/s',
// );
} }
}; };
// function freshChart(chartName: string, legendDatas: any, xDatas: any, yDatas: any, yTitle: string, formatStr: string) {
// if (isInit.value) {
// echarts.init(document.getElementById(chartName) as HTMLElement);
// isInit.value = false;
// }
// let itemChart = echarts.getInstanceByDom(document.getElementById(chartName) as HTMLElement);
// const theme = globalStore.$state.themeConfig.theme || 'light';
// const option = {
// title: [
// {
// left: 'center',
// text: yTitle,
// show: false,
// },
// ],
// zlevel: 1,
// z: 1,
// tooltip: {
// trigger: 'axis',
// formatter: function (datas: any) {
// let res = datas[0].name + '<br/>';
// for (const item of datas) {
// res += item.marker + ' ' + item.seriesName + '' + item.data + formatStr + '<br/>';
// }
// return res;
// },
// },
// grid: { left: '7%', right: '7%', bottom: '20%' },
// legend: {
// data: legendDatas,
// right: 10,
// itemWidth: 8,
// textStyle: {
// color: '#646A73',
// },
// icon: 'circle',
// },
// xAxis: { data: xDatas, boundaryGap: false },
// yAxis: {
// name: '( ' + formatStr + ' )',
// splitLine: {
// //线
// lineStyle: {
// type: 'dashed', //线 线0
// opacity: theme === 'dark' ? 0.1 : 1, //
// },
// },
// },
// series: yDatas,
// dataZoom: [{ startValue: xDatas[0] }],
// };
// itemChart?.setOption(option, true);
// }
// function changeChartSize() {
// if (document.getElementById('ioChart') != null) {
// echarts.getInstanceByDom(document.getElementById('ioChart') as HTMLElement)?.resize();
// }
// if (document.getElementById('networkChart') != null) {
// echarts.getInstanceByDom(document.getElementById('networkChart') as HTMLElement)?.resize();
// }
// }
onMounted(() => { onMounted(() => {
onLoadNetworkOptions(); onLoadNetworkOptions();
onLoadIOOptions(); onLoadIOOptions();
@ -645,7 +488,6 @@ onMounted(() => {
onBeforeUnmount(() => { onBeforeUnmount(() => {
clearInterval(Number(timer)); clearInterval(Number(timer));
timer = null; timer = null;
// window.removeEventListener('resize', changeChartSize);
}); });
</script> </script>