Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(hook): 替换窗口大小变化监听器 #638

Merged
merged 6 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"test:coverage": "echo \"no test:coverage specified,work in process\""
},
"dependencies": {
"@vueuse/core": "^10.6.1",
"axios": "^1.6.2",
"dayjs": "^1.11.10",
"echarts": "5.1.2",
Expand All @@ -32,7 +33,6 @@
"tdesign-vue-next": "^1.6.8",
"tvision-color": "^1.6.0",
"vue": "^3.3.8",
"vue-clipboard3": "^2.0.0",
"vue-i18n": "^9.6.5",
"vue-router": "~4.2.4"
},
Expand Down
8 changes: 4 additions & 4 deletions src/layouts/setting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@
</t-drawer>
</template>
<script setup lang="ts">
import { useClipboard } from '@vueuse/core';
import type { PopupVisibleChangeContext } from 'tdesign-vue-next';
import { MessagePlugin } from 'tdesign-vue-next';
import { computed, onMounted, ref, watchEffect } from 'vue';
import useClipboard from 'vue-clipboard3';

import SettingAutoIcon from '@/assets/assets-setting-auto.svg';
import SettingDarkIcon from '@/assets/assets-setting-dark.svg';
Expand Down Expand Up @@ -169,9 +169,9 @@ const onPopupVisibleChange = (visible: boolean, context: PopupVisibleChangeConte
};

const handleCopy = () => {
const text = JSON.stringify(formData.value, null, 4);
const { toClipboard } = useClipboard();
toClipboard(text)
const sourceText = JSON.stringify(formData.value, null, 4);
const { copy } = useClipboard({ source: sourceText });
copy()
.then(() => {
MessagePlugin.closeAll();
MessagePlugin.success('复制成功');
Expand Down
5 changes: 3 additions & 2 deletions src/locales/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useLocalStorage, usePreferredLanguages } from '@vueuse/core';
import { DropdownOption } from 'tdesign-vue-next';
import { computed } from 'vue';
import { createI18n } from 'vue-i18n';
Expand All @@ -12,7 +13,7 @@ export const langCode: Array<string> = [];
export const localeConfigKey = 'tdesign-starter-locale';

// 获取浏览器默认语言环境
const browserLanguage = navigator.language.replace('-', '_');
const languages = usePreferredLanguages();

// 生成语言模块列表
const generateLangModuleMap = () => {
Expand Down Expand Up @@ -42,7 +43,7 @@ const importMessages = computed(() => {

export const i18n = createI18n({
legacy: false,
locale: localStorage.getItem(localeConfigKey) || browserLanguage || 'zh_CN',
locale: useLocalStorage(localeConfigKey, 'zh_CN').value || languages.value[0] || 'zh_CN',
fallbackLocale: 'zh_CN',
messages: importMessages.value,
globalInjection: true,
Expand Down
3 changes: 2 additions & 1 deletion src/locales/useLocale.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useLocalStorage } from '@vueuse/core';
import { computed } from 'vue';
import { useI18n } from 'vue-i18n';

Expand All @@ -12,7 +13,7 @@ export function useLocale() {
}

locale.value = lang;
localStorage.setItem(localeConfigKey, lang);
useLocalStorage(localeConfigKey, 'zh_CN').value = lang;
}

const getComponentsLocale = computed(() => {
Expand Down
9 changes: 5 additions & 4 deletions src/pages/dashboard/base/components/MiddleChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@
</template>

<script setup lang="ts">
import { useWindowSize } from '@vueuse/core';
import { LineChart, PieChart } from 'echarts/charts';
import { GridComponent, LegendComponent, TooltipComponent } from 'echarts/components';
import * as echarts from 'echarts/core';
import { CanvasRenderer } from 'echarts/renderers';
import { computed, nextTick, onDeactivated, onMounted, onUnmounted, ref, watch } from 'vue';
import { computed, nextTick, onDeactivated, onMounted, ref, watch } from 'vue';

import { useSettingStore } from '@/store';
import { changeChartsTheme } from '@/utils/color';
Expand Down Expand Up @@ -128,11 +129,11 @@ onMounted(() => {
nextTick(() => {
updateContainer();
});
window.addEventListener('resize', updateContainer, false);
});

onUnmounted(() => {
window.removeEventListener('resize', updateContainer);
const { width, height } = useWindowSize();
watch([width, height], () => {
updateContainer();
});

onDeactivated(() => {
Expand Down
9 changes: 5 additions & 4 deletions src/pages/dashboard/base/components/OutputOverview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,12 @@ export default {
</script>

<script setup lang="ts">
import { useWindowSize } from '@vueuse/core';
import { LineChart } from 'echarts/charts';
import { GridComponent, LegendComponent, TooltipComponent } from 'echarts/components';
import * as echarts from 'echarts/core';
import { CanvasRenderer } from 'echarts/renderers';
import { computed, nextTick, onMounted, onUnmounted, ref, watch } from 'vue';
import { computed, nextTick, onMounted, ref, watch } from 'vue';

// 导入样式
import Trend from '@/components/trend/index.vue';
Expand Down Expand Up @@ -127,11 +128,11 @@ onMounted(() => {
nextTick(() => {
updateContainer();
});
window.addEventListener('resize', updateContainer, false);
});

onUnmounted(() => {
window.removeEventListener('resize', updateContainer);
const { width, height } = useWindowSize();
watch([width, height], () => {
updateContainer();
});

watch(
Expand Down
9 changes: 5 additions & 4 deletions src/pages/dashboard/base/components/TopPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@ export default {
</script>

<script setup lang="ts">
import { useWindowSize } from '@vueuse/core';
import { BarChart, LineChart } from 'echarts/charts';
import * as echarts from 'echarts/core';
import { CanvasRenderer } from 'echarts/renderers';
import { FileIcon, UsergroupIcon } from 'tdesign-icons-vue-next';
import { nextTick, onMounted, onUnmounted, ref, watch } from 'vue';
import { nextTick, onMounted, ref, watch } from 'vue';

// 导入样式
import Trend from '@/components/trend/index.vue';
Expand Down Expand Up @@ -152,11 +153,11 @@ onMounted(() => {
nextTick(() => {
updateContainer();
});
window.addEventListener('resize', updateContainer, false);
});

onUnmounted(() => {
window.removeEventListener('resize', updateContainer);
const { width, height } = useWindowSize();
watch([width, height], () => {
updateContainer();
});

watch(
Expand Down
9 changes: 5 additions & 4 deletions src/pages/dashboard/detail/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,12 @@ export default {
</script>

<script setup lang="ts">
import { useWindowSize } from '@vueuse/core';
import { LineChart, ScatterChart } from 'echarts/charts';
import { GridComponent, LegendComponent, TooltipComponent } from 'echarts/components';
import * as echarts from 'echarts/core';
import { CanvasRenderer } from 'echarts/renderers';
import { computed, nextTick, onDeactivated, onMounted, onUnmounted, watch } from 'vue';
import { computed, nextTick, onDeactivated, onMounted, watch } from 'vue';

import ProductCard from '@/components/product-card/index.vue';
import Trend from '@/components/trend/index.vue';
Expand Down Expand Up @@ -126,14 +127,14 @@ const renderCharts = () => {

onMounted(() => {
renderCharts();
window.addEventListener('resize', updateContainer, false);
nextTick(() => {
updateContainer();
});
});

onUnmounted(() => {
window.removeEventListener('resize', updateContainer);
const { width, height } = useWindowSize();
watch([width, height], () => {
updateContainer();
});

onDeactivated(() => {
Expand Down