Merge branch 'vue-i18n' of https://github.com/zouzhibin/vue-admin-perfect into ghpages

 Conflicts:
	package-lock.json
	yarn.lock
This commit is contained in:
zouzhibing 2023-02-28 14:36:49 +08:00
commit a3426174ea
11 changed files with 118 additions and 44 deletions

View File

@ -38,6 +38,8 @@
"pinia": "^2.0.21", "pinia": "^2.0.21",
"pinia-plugin-persistedstate": "^2.1.1", "pinia-plugin-persistedstate": "^2.1.1",
"print-js": "^1.6.0", "print-js": "^1.6.0",
"raf": "^3.4.1",
"resize-observer-polyfill": "^1.5.1",
"sass": "^1.54.0", "sass": "^1.54.0",
"splitpanes": "^3.1.1", "splitpanes": "^3.1.1",
"svg-sprite-loader": "^6.0.11", "svg-sprite-loader": "^6.0.11",

View File

@ -5,7 +5,7 @@
import { geoJson } from './map.js' import { geoJson } from './map.js'
import * as echarts from 'echarts' import * as echarts from 'echarts'
import { EChartsType } from 'echarts/core' import { EChartsType } from 'echarts/core'
import { onMounted } from 'vue' import { onMounted, onUnmounted } from "vue";
import { cityIconData } from './data.js' import { cityIconData } from './data.js'
import logo from '@/assets/image/logo.png' import logo from '@/assets/image/logo.png'
const props = defineProps({ const props = defineProps({
@ -318,6 +318,11 @@
chart.setOption(options) chart.setOption(options)
return chart return chart
} }
onUnmounted(()=>{
chart&&chart.dispose()
})
onMounted(() => { onMounted(() => {
chart = initChart() chart = initChart()
window.addEventListener('resize', function () { window.addEventListener('resize', function () {

View File

@ -0,0 +1,39 @@
import ResizeObserver from "resize-observer-polyfill";
import { onBeforeUnmount } from "vue";
import requestAnimationFrameThrottle from "@/utils/requestAnimationFrameThrottle"
export const useResizeElement = (chart, chartsRef)=>{
let observer = null ;
let widthW = 0;
let heightW = 0;
const handleResize = (entries )=>{
const { contentRect } = entries[0];
let {width,height} = contentRect
width = Math.floor(width);
height = Math.floor(height);
if(widthW!==width|| heightW !== height){
widthW = width
heightW = height
chart && chart.resize()
}
}
const addObserver = ()=>{
observer = new ResizeObserver(requestAnimationFrameThrottle(handleResize))
observer.observe(chartsRef)
}
const removeObserver = ()=>{
if (observer) {
observer.disconnect();
observer = null;
}
chart&&chart.dispose()
}
onBeforeUnmount(()=>{
removeObserver()
})
return{
addObserver
}
}

View File

@ -4,27 +4,46 @@ import {useRoute} from "vue-router";
const { body } = document const { body } = document
const WIDTH = 992 // refer to Bootstrap's responsive design const WIDTH = 800 // refer to Bootstrap's responsive design
const MAX_WIDTH = 1200
export const useResizeHandler = ()=>{ export const useResizeHandler = ()=>{
const SettingStore = useSettingStore() const SettingStore = useSettingStore()
const route = useRoute() const route = useRoute()
const device = computed(()=>{ const device = computed(()=>{
return SettingStore.device return SettingStore.device
}) })
function $_isMobile(){ function $_isMobile(){
const rect = body.getBoundingClientRect() const rect = body.getBoundingClientRect()
return rect.width - 1 < WIDTH return rect.width - 1 < WIDTH
} }
function collapse(){
const rect = body.getBoundingClientRect()
if(rect.width - 1 > MAX_WIDTH){
return true
}else {
return false
}
}
function $_resizeHandler(){ function $_resizeHandler(){
if (!document.hidden) { // bool型表示页面是否处于隐藏状态。页面隐藏包括页面在后台标签页或者浏览器最小化 if (!document.hidden) { // bool型表示页面是否处于隐藏状态。页面隐藏包括页面在后台标签页或者浏览器最小化
const isMobile = $_isMobile() const isMobile = $_isMobile()
const isCollapse = collapse()
SettingStore.toggleDevice(isMobile ? 'mobile' : 'desktop') SettingStore.toggleDevice(isMobile ? 'mobile' : 'desktop')
if (isMobile) { if (isMobile) {
SettingStore.closeSideBar({ withoutAnimation: true }) SettingStore.closeSideBar({ withoutAnimation: true })
} }
if(!isMobile){
SettingStore.setCollapse(isCollapse)
}
} }
} }
onMounted(()=>{ onMounted(()=>{

View File

@ -4,7 +4,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import {computed} from "vue"; import {computed} from "vue";
import { useResizeHandler } from '../../hooks/useResizeHandler' import { useResizeHandler } from '@/hooks/useResizeHandler'
import {useSettingStore} from "@/store/modules/setting" import {useSettingStore} from "@/store/modules/setting"
let { device } = useResizeHandler() let { device } = useResizeHandler()

View File

@ -12,7 +12,7 @@
import Theme from '@/components/Theme/index.vue' import Theme from '@/components/Theme/index.vue'
import Mobile from './components/Mobile/index.vue' import Mobile from './components/Mobile/index.vue'
import {useSettingStore} from "@/store/modules/setting" import {useSettingStore} from "@/store/modules/setting"
import { useResizeHandler } from './hooks/useResizeHandler' import { useResizeHandler } from '@/hooks/useResizeHandler'
import LayoutVertical from './LayoutVertical/index.vue' import LayoutVertical from './LayoutVertical/index.vue'
import LayoutHorizontal from './LayoutHorizontal/index.vue' import LayoutHorizontal from './LayoutHorizontal/index.vue'
import LayoutColumns from './LayoutColumns/index.vue' import LayoutColumns from './LayoutColumns/index.vue'

View File

@ -0,0 +1,25 @@
import raf from "raf";
/**
* requestAnimationFrame 节流
* scroll touchmove 等事件触发很频繁比屏幕刷新频率更快将导致无效的渲染和重绘
* 这里使用 requestAnimationFrame 来优化滚动处理在一帧中只进行一次有效重绘
*/
export default function requestAnimationFrameThrottle(callback) {
let id;
const factory = args => () => {
id = null;
callback(...args);
};
const throttled = (...args) => {
if (id == null) {
id = raf(factory(args));
}
};
throttled.cancel = () => raf.cancel(id);
return throttled;
};

View File

@ -1,8 +1,10 @@
import wePng from '@/assets/image/we.png'
export const chatData = [ export const chatData = [
{ {
is_self: 0, is_self: 0,
created_at: '2022-11-15', created_at: '2022-11-15',
content: 'http://182.61.5.190:8889/we.png', content: wePng,
id: 1, id: 1,
type: 2, // 文字 type: 2, // 文字
}, },

View File

@ -6,10 +6,10 @@
<script lang="ts" setup> <script lang="ts" setup>
import {ref,onMounted} from "vue"; import {ref,onMounted} from "vue";
import { EChartsType } from 'echarts/core'
import * as echarts from 'echarts' import * as echarts from 'echarts'
const chartsRef = ref<HTMLElement | null>() import {useResizeElement} from '@/hooks/useResizeElement'
const chartsRef = ref<HTMLElement | null>()
let XData = ['2022-01', '2022-02', '2022-03', '2022-04', '2022-05', '2022-06', '2022-07', '2022-08', '2022-09', '2022-10', '2022-11', '2022-12'] let XData = ['2022-01', '2022-02', '2022-03', '2022-04', '2022-05', '2022-06', '2022-07', '2022-08', '2022-09', '2022-10', '2022-11', '2022-12']
let valueData = { let valueData = {
jfsbs: [805, 860, 400, 400, 400, 400, 990, 985, 990, 850, 560, 772], jfsbs: [805, 860, 400, 400, 400, 400, 990, 985, 990, 850, 560, 772],
@ -17,7 +17,6 @@ let valueData = {
znhbl: [95, 78, 50, 60, 85, 78, 76, 70, 65, 90, 74, 66], znhbl: [95, 78, 50, 60, 85, 78, 76, 70, 65, 90, 74, 66],
} }
let options = { let options = {
tooltip: { tooltip: {
trigger: 'axis', trigger: 'axis',
axisPointer: { // axisPointer: { //
@ -217,17 +216,13 @@ let options = {
} }
] ]
}; };
let chart: EChartsType
const initChart = () => {
const chart = echarts.init(chartsRef.value)
chart.setOption(options)
return chart
}
onMounted(() => { onMounted(() => {
chart = initChart() let chart = echarts.init(chartsRef.value)
window.addEventListener('resize', function () { chart.setOption(options)
chart && chart.resize() let {addObserver} = useResizeElement(chart,chartsRef.value)
}) addObserver()
}) })
</script> </script>

View File

@ -6,12 +6,11 @@
<script lang="ts" setup> <script lang="ts" setup>
import {ref,onMounted} from "vue"; import {ref,onMounted} from "vue";
import { EChartsType } from 'echarts/core'
import * as echarts from 'echarts' import * as echarts from 'echarts'
import {useResizeElement} from '@/hooks/useResizeElement'
const chartsRef = ref<HTMLElement | null>() const chartsRef = ref<HTMLElement | null>()
let options = { let options = {
normal: { normal: {
top: 200, top: 200,
left: 300, left: 300,
@ -196,17 +195,12 @@ let options = {
}, },
], ],
}; };
let chart: EChartsType
const initChart = () => {
const chart = echarts.init(chartsRef.value)
chart.setOption(options)
return chart
}
onMounted(() => { onMounted(() => {
chart = initChart() let chart = echarts.init(chartsRef.value)
window.addEventListener('resize', function () { chart.setOption(options)
chart && chart.resize() let {addObserver} = useResizeElement(chart,chartsRef.value)
}) addObserver()
}) })
</script> </script>

View File

@ -6,7 +6,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import {ref,onMounted} from "vue"; import {ref,onMounted} from "vue";
import { EChartsType } from 'echarts/core' import {useResizeElement} from '@/hooks/useResizeElement'
import * as echarts from 'echarts' import * as echarts from 'echarts'
const chartsRef = ref<HTMLElement | null>() const chartsRef = ref<HTMLElement | null>()
@ -105,19 +105,12 @@ let options = {
], ],
}; };
let chart: EChartsType
const initChart = () => {
const chart = echarts.init(chartsRef.value)
chart.setOption(options)
return chart
}
onMounted(() => { onMounted(() => {
chart = initChart() let chart = echarts.init(chartsRef.value)
window.addEventListener('resize', function () { chart.setOption(options)
chart && chart.resize() let {addObserver} = useResizeElement(chart,chartsRef.value)
}) addObserver()
}) })
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>