2020-09-16 08:27:46 +08:00
|
|
|
import { createApp, nextTick } from 'vue'
|
2021-07-30 11:29:25 +08:00
|
|
|
import { hyphenate } from '@vue/shared'
|
|
|
|
import * as ElementPlusSvgIcons from '@element-plus/icons'
|
|
|
|
import clipboardCopy from 'clipboard-copy'
|
2020-08-13 15:18:26 +08:00
|
|
|
import { createRouter, createWebHashHistory } from 'vue-router'
|
|
|
|
import routes from './route.config'
|
|
|
|
import demoBlock from './components/demo-block'
|
2021-01-25 11:03:48 +08:00
|
|
|
import RightNav from './components/right-nav'
|
2020-08-13 15:18:26 +08:00
|
|
|
import MainFooter from './components/footer'
|
|
|
|
import MainHeader from './components/header'
|
|
|
|
import SideNav from './components/side-nav'
|
|
|
|
import FooterNav from './components/footer-nav'
|
2021-08-24 13:36:48 +08:00
|
|
|
import AppHeading from './components/heading'
|
|
|
|
import AppLink from './components/link'
|
|
|
|
import AppImg from './components/img'
|
|
|
|
|
2020-08-13 15:18:26 +08:00
|
|
|
import title from './i18n/title'
|
2020-09-16 08:27:46 +08:00
|
|
|
import 'highlight.js/styles/color-brewer.css'
|
2020-08-13 15:18:26 +08:00
|
|
|
import './demo-styles/index.scss'
|
2020-11-10 14:55:03 +08:00
|
|
|
import './assets/styles/common.scss'
|
2020-08-13 15:18:26 +08:00
|
|
|
import './assets/styles/fonts/style.css'
|
|
|
|
import icon from './icon.json'
|
2020-09-16 14:49:47 +08:00
|
|
|
import dayjs from 'dayjs'
|
|
|
|
import 'dayjs/locale/zh-cn'
|
|
|
|
dayjs.locale('zh-cn') // todo: locale based on Doc site lang
|
2021-07-30 11:29:25 +08:00
|
|
|
import compLang from './i18n/component.json'
|
2020-08-13 15:18:26 +08:00
|
|
|
import App from './app.vue'
|
2020-09-15 17:12:16 +08:00
|
|
|
import ElementPlus from 'element-plus'
|
2020-09-24 11:13:53 +08:00
|
|
|
import '../packages/theme-chalk/src/index.scss'
|
2021-01-31 13:06:10 +08:00
|
|
|
import '../packages/theme-chalk/src/display.scss'
|
2020-08-25 09:58:26 +08:00
|
|
|
|
2020-08-13 15:18:26 +08:00
|
|
|
const app = createApp(App)
|
|
|
|
|
2021-07-30 11:29:25 +08:00
|
|
|
const svgIcons = []
|
|
|
|
for (let i in ElementPlusSvgIcons) {
|
|
|
|
const component = ElementPlusSvgIcons[i]
|
|
|
|
app.component(component.name, component)
|
|
|
|
svgIcons.push(component.name)
|
|
|
|
}
|
|
|
|
app.config.globalProperties.$svgIcons = svgIcons
|
2020-08-13 15:18:26 +08:00
|
|
|
app.config.globalProperties.$icon = icon
|
|
|
|
|
2021-07-30 11:29:25 +08:00
|
|
|
|
2020-08-13 15:18:26 +08:00
|
|
|
app.component('DemoBlock', demoBlock)
|
2021-01-25 11:03:48 +08:00
|
|
|
app.component('RightNav', RightNav)
|
2020-08-13 15:18:26 +08:00
|
|
|
app.component('MainFooter', MainFooter)
|
|
|
|
app.component('MainHeader', MainHeader)
|
|
|
|
app.component('SideNav', SideNav)
|
|
|
|
app.component('FooterNav', FooterNav)
|
2021-08-24 13:36:48 +08:00
|
|
|
app.component('AppHeading', AppHeading)
|
|
|
|
app.component('AppLink', AppLink)
|
|
|
|
app.component('AppImg', AppImg)
|
2020-08-13 15:18:26 +08:00
|
|
|
|
|
|
|
const router = createRouter({
|
|
|
|
history: createWebHashHistory(),
|
|
|
|
routes,
|
|
|
|
})
|
2020-09-15 17:12:16 +08:00
|
|
|
app.use(ElementPlus)
|
2020-08-13 15:18:26 +08:00
|
|
|
app.use(router)
|
2020-12-12 22:33:46 +08:00
|
|
|
router.isReady().then(() => {
|
2021-07-30 11:29:25 +08:00
|
|
|
let lang = location.hash.split('/')[1]
|
|
|
|
let langConfig = compLang.filter(config => config.lang === lang)[0]['demo-block']
|
2020-08-13 15:18:26 +08:00
|
|
|
|
2021-07-30 11:29:25 +08:00
|
|
|
app.config.globalProperties.$copySvgIcon = iconName => {
|
|
|
|
clipboardCopy(
|
|
|
|
`<el-svg-icon>
|
|
|
|
<${hyphenate(iconName)} />
|
|
|
|
</el-svg-icon>
|
|
|
|
`,
|
|
|
|
).then(() => {
|
|
|
|
app.config.globalProperties.$message({
|
|
|
|
showClose: true,
|
|
|
|
message: langConfig['copy-success'],
|
|
|
|
type: 'success',
|
|
|
|
})
|
|
|
|
}).catch(() => {
|
|
|
|
app.config.globalProperties.$message({
|
|
|
|
showClose: true,
|
|
|
|
message: langConfig['copy-error'],
|
|
|
|
type: 'error',
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
2020-08-13 15:18:26 +08:00
|
|
|
router.afterEach(async route => {
|
|
|
|
await nextTick()
|
2021-07-30 11:29:25 +08:00
|
|
|
lang = location.hash.split('/')[1]
|
2020-08-13 15:18:26 +08:00
|
|
|
const data = title[route.meta.lang]
|
|
|
|
for (let val in data) {
|
|
|
|
if (new RegExp('^' + val, 'g').test(route.name)) {
|
|
|
|
document.title = data[val]
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
document.title = 'Element'
|
|
|
|
ga('send', 'event', 'PageView', route.name)
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
app.mount('#app')
|