Skip to content

Commit

Permalink
Merge pull request #88 from lihuacai168/feat/repalce-monaco-by-ace
Browse files Browse the repository at this point in the history
feat: replace monaco editor by ace
  • Loading branch information
lihuacai168 authored Apr 26, 2023
2 parents 0777133 + 56077f0 commit 3523528
Show file tree
Hide file tree
Showing 11 changed files with 223 additions and 732 deletions.
2 changes: 0 additions & 2 deletions web/build/webpack.dev.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const CopyWebpackPlugin = require('copy-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
const portfinder = require('portfinder')
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
// const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;

const HOST = process.env.HOST
Expand Down Expand Up @@ -52,7 +51,6 @@ const devWebpackConfig = merge(baseWebpackConfig, {
new webpack.DefinePlugin({
'process.env': require('../config/dev.env')
}),
new MonacoWebpackPlugin(),
new webpack.HotModuleReplacementPlugin(),
new webpack.NamedModulesPlugin(), // HMR shows correct file names in console on update.
new webpack.NoEmitOnErrorsPlugin(),
Expand Down
9 changes: 4 additions & 5 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@
"apexcharts": "^3.27.3",
"axios": "^0.18.0",
"babel-preset-es2015": "^6.24.1",
"brace": "^0.11.1",
"echarts": "^4.9.0",
"element-ui": "^2.13.0",
"monaco-editor": "0.20.0",
"monaco-editor-webpack-plugin": "1.9.0",
"element-ui": "2.15.13",
"sass-loader": "^11.0.1",
"v-jsoneditor": "^1.4.4",
"vue": "^2.5.2",
"vue-apexcharts": "^1.6.2",
"vue-clipboard2": "^0.3.1",
"vue-codemirror": "^4.0.6",
"vue-loader": "^13.7.3",
"vue-monaco-editor": "^0.0.19",
"vue-router": "^3.0.1",
"vuedraggable": "^2.16.0",
"vuex": "^3.0.1"
Expand Down Expand Up @@ -62,7 +61,7 @@
"vue-loader": "^13.7.3",
"vue-style-loader": "^3.0.1",
"vue-template-compiler": "^2.5.2",
"vue2-ace-editor": "0.0.15",
"vue2-ace-editor": "^0.0.15",
"webpack": "^3.6.0",
"webpack-bundle-analyzer": "^4.8.0",
"webpack-dev-server": "^2.9.1",
Expand Down
130 changes: 66 additions & 64 deletions web/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,81 +25,83 @@ Vue.use(VJsoneditor)
Vue.use(VueClipboard)
Vue.use(VueApexCharts)

import Editor from 'vue2-ace-editor'
Vue.component('ace-editor', Editor)
Vue.component('ApexCharts', VueApexCharts)

Vue.filter('datetimeFormat', datetimeObj2str);
Vue.filter("timestampToTime", timestamp2time);
Vue.filter('datetimeFormat', datetimeObj2str)

Vue.prototype.setLocalValue = function (name, value) {
if (window.localStorage) {
localStorage.setItem(name, value);
} else {
alert('This browser does NOT support localStorage');
}
};
Vue.prototype.getLocalValue = function (name) {
const value = localStorage.getItem(name);
if (value) {
// localStorage只能存字符串,布尔类型需要转换
if(value === "false" || value === "true"){
return eval(value)
}
return value;
} else {
return '';
Vue.filter('timestampToTime', timestamp2time)

Vue.prototype.setLocalValue = function(name, value) {
if (window.localStorage) {
localStorage.setItem(name, value)
} else {
alert('This browser does NOT support localStorage')
}
}
Vue.prototype.getLocalValue = function(name) {
const value = localStorage.getItem(name)
if (value) {
// localStorage只能存字符串,布尔类型需要转换
if (value === 'false' || value === 'true') {
return eval(value)
}
};
return value
} else {
return ''
}
}

router.beforeEach((to, from, next) => {
/* 路由发生变化修改页面title */
setTimeout((res) => {
if (to.meta.title) {
document.title = to.meta.title
}

if (to.meta.requireAuth) {
if (store.state.token !== '') {
next();
} else {
next({
name: 'Login',
})
}
} else {
next()
}
})
/* 路由发生变化修改页面title */
setTimeout((res) => {
if (to.meta.title) {
document.title = to.meta.title
}

if (to.meta.requireAuth) {
if (store.state.token !== '') {
next()
} else {
next({
name: 'Login'
})
}
} else {
next()
}
})
})

/* eslint-disable no-new */
new Vue({
el: '#app',
router,
store,
components: {App},
template: '<App/>',
created() {
if (this.getLocalValue("token") === null) {
this.setLocalValue("token", "");
}
if (this.getLocalValue("user") === null) {
this.setLocalValue("user", "");
}
if (this.getLocalValue("routerName") === null) {
this.setLocalValue("routerName", "ProjectList");
}
el: '#app',
router,
store,
components: {App},
template: '<App/>',
created() {
if (this.getLocalValue('token') === null) {
this.setLocalValue('token', '')
}
if (this.getLocalValue('user') === null) {
this.setLocalValue('user', '')
}
if (this.getLocalValue('routerName') === null) {
this.setLocalValue('routerName', 'ProjectList')
}

if (this.getLocalValue("is_superuser") === null) {
this.setLocalValue("is_superuser", false);
}
if (this.getLocalValue("show_hosts") === null) {
this.setLocalValue("show_hosts", false);
}
this.$store.commit("isLogin", this.getLocalValue("token"));
this.$store.commit("setUser", this.getLocalValue("user"));
this.$store.commit("setRouterName", this.getLocalValue("routerName"));
this.$store.commit("setIsSuperuser", this.getLocalValue("is_superuser"));
this.$store.commit("setShowHots", this.getLocalValue("show_hosts"));
if (this.getLocalValue('is_superuser') === null) {
this.setLocalValue('is_superuser', false)
}
if (this.getLocalValue('show_hosts') === null) {
this.setLocalValue('show_hosts', false)
}
this.$store.commit('isLogin', this.getLocalValue('token'))
this.$store.commit('setUser', this.getLocalValue('user'))
this.$store.commit('setRouterName', this.getLocalValue('routerName'))
this.$store.commit('setIsSuperuser', this.getLocalValue('is_superuser'))
this.$store.commit('setShowHots', this.getLocalValue('show_hosts'))
}
})
Loading

0 comments on commit 3523528

Please sign in to comment.