feat(docs): support playground sync theme (#16735)

* feat(docs): support playground sync theme

* fix: dark mode error
This commit is contained in:
btea 2024-07-23 16:02:35 +08:00 committed by GitHub
parent 7db060b7fb
commit 39763fcfe0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,4 +1,5 @@
import { utoa } from '../utils' import { utoa } from '../utils'
import { isDark } from './dark'
const MAIN_FILE_NAME = 'App.vue' const MAIN_FILE_NAME = 'App.vue'
@ -10,11 +11,19 @@ export const usePlayground = (source: string) => {
const encoded = utoa(JSON.stringify(originCode)) const encoded = utoa(JSON.stringify(originCode))
const isPreview = location.host.startsWith('preview') const isPreview = location.host.startsWith('preview')
let link = `https://element-plus.run/#${encoded}` let link = `https://element-plus.run/`
if (isPreview) { if (isPreview) {
const pr = location.host.split('-', 2)[1] const pr = location.host.split('-', 2)[1]
link = `https://element-plus.run/?pr=${pr}#${encoded}` link = `${link}?pr=${pr}`
} }
if (isDark.value) {
if (isPreview) {
link += '&theme=dark'
} else {
link = `${link}?theme=dark`
}
}
link += `#${encoded}`
return { return {
encoded, encoded,
link, link,