Browse Source

格式化前端代码

main
pixel 3 years ago
parent
commit
bd127e679f
  1. 104
      web/src/core/element_lazy.js
  2. 6
      web/src/core/gin-vue-admin.js
  3. 2
      web/src/main.js
  4. 82
      web/src/view/systemTools/autoCode/component/previewCodeDialg.vue

104
web/src/core/element_lazy.js

@ -8,57 +8,57 @@
import Vue from 'vue' import Vue from 'vue'
// 按需引入element // 按需引入element
import { import {
Button,
Select,
Dialog,
Form,
Input,
FormItem,
Option,
Loading,
Message,
Container,
Card,
Dropdown,
DropdownMenu,
DropdownItem,
Row,
Col,
Menu,
Submenu,
MenuItem,
Aside,
Main,
Badge,
Header,
Tabs,
Breadcrumb,
BreadcrumbItem,
Scrollbar,
Avatar,
TabPane,
Divider,
Table,
TableColumn,
Cascader,
Checkbox,
CheckboxGroup,
Pagination,
Tag,
Drawer,
Tree,
Popover,
Switch,
Collapse,
CollapseItem,
Tooltip,
DatePicker,
InputNumber,
Steps,
Upload,
Progress,
MessageBox,
Image
Button,
Select,
Dialog,
Form,
Input,
FormItem,
Option,
Loading,
Message,
Container,
Card,
Dropdown,
DropdownMenu,
DropdownItem,
Row,
Col,
Menu,
Submenu,
MenuItem,
Aside,
Main,
Badge,
Header,
Tabs,
Breadcrumb,
BreadcrumbItem,
Scrollbar,
Avatar,
TabPane,
Divider,
Table,
TableColumn,
Cascader,
Checkbox,
CheckboxGroup,
Pagination,
Tag,
Drawer,
Tree,
Popover,
Switch,
Collapse,
CollapseItem,
Tooltip,
DatePicker,
InputNumber,
Steps,
Upload,
Progress,
MessageBox,
Image
} from 'element-ui' } from 'element-ui'
Vue.use(Button) Vue.use(Button)
@ -116,4 +116,4 @@ Vue.prototype.$message = Message
Vue.prototype.$confirm = MessageBox.confirm Vue.prototype.$confirm = MessageBox.confirm
Dialog.props.closeOnClickModal.default = false Dialog.props.closeOnClickModal.default = false
console.warn('[GIN-VUE-ADMIN]--按需加载elementUI成功')
console.warn('[GIN-VUE-ADMIN]--按需加载elementUI成功,如出现element-ui组件无法使用问题,请至/src/core/element_lazy 下引入对应组件即可')

6
web/src/core/gin-vue-admin.js

@ -3,7 +3,7 @@
* *
* */ * */
import Vue from 'vue' import Vue from 'vue'
import './element_lazy'
import './element_lazy' // 按需加载element
import uploader from 'vue-simple-uploader' import uploader from 'vue-simple-uploader'
import APlayer from '@moefe/vue-aplayer' import APlayer from '@moefe/vue-aplayer'
// time line css // time line css
@ -12,8 +12,8 @@ import '../../node_modules/timeline-vuejs/dist/timeline-vuejs.css'
import Bus from '@/utils/bus' import Bus from '@/utils/bus'
Vue.use(Bus) Vue.use(Bus)
Vue.use(APlayer, { Vue.use(APlayer, {
defaultCover: 'https://github.com/u3u.png',
productionTip: true
defaultCover: 'https://github.com/u3u.png',
productionTip: true
}) })
Vue.use(uploader) Vue.use(uploader)

2
web/src/main.js

@ -1,6 +1,6 @@
import Vue from 'vue' import Vue from 'vue'
import App from './App.vue' import App from './App.vue'
// 引入gin-vue-admin前端组件
// 引入gin-vue-admin前端初始化相关内容
import './core/gin-vue-admin' import './core/gin-vue-admin'
// 引入封装的router // 引入封装的router
import router from '@/router/index' import router from '@/router/index'

82
web/src/view/systemTools/autoCode/component/previewCodeDialg.vue

@ -6,60 +6,37 @@
<el-button @click="copy">复制</el-button> <el-button @click="copy">复制</el-button>
</div> </div>
<el-tabs v-model="activeName"> <el-tabs v-model="activeName">
<el-tab-pane :label="key" :name="key" v-for="(item, key) in previewCode" :key="key">
<div class="tab-info" :id="key"></div>
<el-tab-pane v-for="(item, key) in previewCode" :key="key" :label="key" :name="key">
<div :id="key" class="tab-info" />
</el-tab-pane> </el-tab-pane>
</el-tabs> </el-tabs>
</div> </div>
</template> </template>
<script> <script>
import marked from "marked";
import hljs from "highlight.js";
import marked from 'marked'
import hljs from 'highlight.js'
// import 'highlight.js/styles/atelier-cave-light.css'; // import 'highlight.js/styles/atelier-cave-light.css';
import "highlight.js/styles/atelier-plateau-light.css";
import 'highlight.js/styles/atelier-plateau-light.css'
export default { export default {
props: { props: {
previewCode: { previewCode: {
type: Object, type: Object,
default() { default() {
return {};
},
},
return {}
}
}
}, },
data() { data() {
return { return {
activeName: "",
};
},
methods: {
selectText() {
const element = document.getElementById(this.activeName);
if (document.body.createTextRange) {
let range = document.body.createTextRange();
range.moveToElementText(element);
range.select();
} else if (window.getSelection) {
let selection = window.getSelection();
let range = document.createRange();
range.selectNodeContents(element);
selection.removeAllRanges();
selection.addRange(range);
} else {
alert("none");
}
},
copy() {
this.selectText();
document.execCommand("copy");
this.$message.success("复制成功");
},
activeName: ''
}
}, },
mounted() { mounted() {
marked.setOptions({ marked.setOptions({
renderer: new marked.Renderer(), renderer: new marked.Renderer(),
highlight: function (code) {
return hljs.highlightAuto(code).value;
highlight: function(code) {
return hljs.highlightAuto(code).value
}, },
pedantic: false, pedantic: false,
gfm: true, gfm: true,
@ -68,16 +45,39 @@ export default {
sanitize: false, sanitize: false,
smartLists: true, smartLists: true,
smartypants: false, smartypants: false,
xhtml: false,
});
xhtml: false
})
for (const key in this.previewCode) { for (const key in this.previewCode) {
if (this.activeName == "") {
this.activeName = key;
if (this.activeName === '') {
this.activeName = key
} }
document.getElementById(key).innerHTML = marked(this.previewCode[key]);
document.getElementById(key).innerHTML = marked(this.previewCode[key])
} }
}, },
};
methods: {
selectText() {
const element = document.getElementById(this.activeName)
if (document.body.createTextRange) {
const range = document.body.createTextRange()
range.moveToElementText(element)
range.select()
} else if (window.getSelection) {
const selection = window.getSelection()
const range = document.createRange()
range.selectNodeContents(element)
selection.removeAllRanges()
selection.addRange(range)
} else {
alert('none')
}
},
copy() {
this.selectText()
document.execCommand('copy')
this.$message.success('复制成功')
}
}
}
</script> </script>
<style lang="scss"> <style lang="scss">

Loading…
Cancel
Save