Skip to content

Commit

Permalink
fix(cli): compatible with cloudflare omit file suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
haoziqaq committed May 7, 2024
1 parent 5abe584 commit f6b9ece
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
5 changes: 3 additions & 2 deletions packages/varlet-cli/site/mobile/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ import {
watchLang,
watchTheme,
setTheme,
getMobileIndex,
type Theme,
} from '@varlet/cli/client'
import { removeEmpty, inIframe, isPhone } from '../utils'
Expand All @@ -114,15 +115,15 @@ export default defineComponent({
const changeLanguage = (lang: string) => {
language.value = lang
showMenu.value = false
window.location.href = `./mobile.html#${route.path}?language=${language.value}&replace=${route.query.replace}`
window.location.href = `${getMobileIndex()}#${route.path}?language=${language.value}&replace=${route.query.replace}`
if (!isPhone() && inIframe()) {
;(window.top as any).scrollToMenu(redirect.slice(1))
}
}
const back = () => {
window.location.href = `./mobile.html#${redirect}?language=${language.value}&replace=${redirect.slice(1)}`
window.location.href = `${getMobileIndex()}#${redirect}?language=${language.value}&replace=${redirect.slice(1)}`
if (!isPhone() && inIframe()) {
;(window.top as any).scrollToMenu(redirect.slice(1))
Expand Down
4 changes: 2 additions & 2 deletions packages/varlet-cli/site/pc/App.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import config from '@config'
import { defineComponent, onMounted, ref } from 'vue'
import { getPCLocationInfo } from '@varlet/cli/client'
import { getPCLocationInfo, getMobileIndex } from '@varlet/cli/client'
import { isPhone } from '../utils'
import { get } from 'lodash-es'
Expand All @@ -14,7 +14,7 @@ export default defineComponent({
const { language, menuName } = getPCLocationInfo()
if (isPhone() && useMobile.value) {
window.location.href = `./mobile.html#/${menuName}?language=${language || defaultLanguage}&platform=mobile`
window.location.href = `${getMobileIndex()}#/${menuName}?language=${language || defaultLanguage}&platform=mobile`
return
}
}
Expand Down
9 changes: 8 additions & 1 deletion packages/varlet-cli/site/pc/components/AppMobile.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<template>
<div class="varlet-site-mobile varlet-site-mobile--375">
<div class="varlet-site-mobile-content">
<iframe id="mobile" :src="`./mobile.html#/${componentName}?language=${language}&platform=pc&replace=${replace}${hash ? `#${hash}` : ''}`"></iframe>
<iframe id="mobile" :src="`${getMobileIndex()}#/${componentName}?language=${language}&platform=pc&replace=${replace}${hash ? `#${hash}` : ''}`"></iframe>
</div>
</div>
</template>

<script lang="ts">
import { getMobileIndex } from '@varlet/cli/client'
export default {
name: 'AppMobile',
props: {
Expand All @@ -22,6 +24,11 @@ export default {
hash: {
type: String
}
},
setup() {
return {
getMobileIndex
}
}
}
</script>
Expand Down
5 changes: 5 additions & 0 deletions packages/varlet-cli/src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,9 @@ export function watchTheme(
cb(getBrowserTheme(), 'default')
}

export function getMobileIndex() {
const isCf = window.location.origin.includes('pages.dev')
return isCf ? './mobile' : './mobile.html'
}

export { AppType, StyleProvider }

0 comments on commit f6b9ece

Please sign in to comment.