添加全局变量

This commit is contained in:
GGJ
2024-10-16 10:49:48 +08:00
parent 376f6cc31b
commit 89535b6059
11 changed files with 57 additions and 40 deletions

View File

@@ -23,9 +23,10 @@
<Icon size="14" name="el-icon-ArrowUp" style="color: #fff" v-if="showSelect" /> <Icon size="14" name="el-icon-ArrowUp" style="color: #fff" v-if="showSelect" />
<Icon size="14" name="el-icon-ArrowDown" style="color: #fff" v-else /> <Icon size="14" name="el-icon-ArrowDown" style="color: #fff" v-else />
</el-button> </el-button>
<el-button @click="onComSearch" v-if="showSearch" type="primary" :icon="Search">查询</el-button> <el-button @click="onComSearch" v-if="showSearch" type="primary" :icon="Search">查询</el-button>
<el-button @click="onResetForm" v-if="showSearch" :icon="RefreshLeft">重置</el-button> <el-button @click="onResetForm" v-if="showSearch" :icon="RefreshLeft">重置</el-button>
</template> </template>
<!-- :loading="tableStore.table.loading" -->
<slot name="operation"></slot> <slot name="operation"></slot>
</div> </div>
<el-form <el-form

View File

@@ -1,4 +1,4 @@
import { createApp } from 'vue' import { createApp, reactive } from 'vue'
import App from './App.vue' import App from './App.vue'
import router from './router' import router from './router'
import pinia from '@/stores/index' import pinia from '@/stores/index'
@@ -15,25 +15,23 @@ import '@/styles/index.scss'
import '@/assets/font/iconfont.css' import '@/assets/font/iconfont.css'
import { ElDialog } from 'element-plus' import { ElDialog } from 'element-plus'
import BaiduMap from 'vue-baidu-map-3x' import BaiduMap from 'vue-baidu-map-3x'
import BaiduMapOffline from 'vue-baidu-map-offline'; import BaiduMapOffline from 'vue-baidu-map-offline'
import ExcelJS from 'exceljs' import ExcelJS from 'exceljs'
import VXETablePluginExportXLSX from 'vxe-table-plugin-export-xlsx' import VXETablePluginExportXLSX from 'vxe-table-plugin-export-xlsx'
// 方式1NPM 安装,注入 ExcelJS 对象 // 方式1NPM 安装,注入 ExcelJS 对象
VXETable.use(VXETablePluginExportXLSX, { VXETable.use(VXETablePluginExportXLSX, {
ExcelJS ExcelJS
}) })
window.XEUtils = XEUtils window.XEUtils = XEUtils
// 初始化多语言 // 初始化多语言
import { setupI18n } from '@/plugins/vueI18n' import { setupI18n } from '@/plugins/vueI18n'
// 引入 form-create // 引入 form-create
import { setupFormCreate } from '@/plugins/formCreate' import { setupFormCreate } from '@/plugins/formCreate'
// 创建实例 // 创建实例
const setupAll = async () => { const setupAll = async () => {
const app = createApp(App) const app = createApp(App)
//开启离线地图 //开启离线地图
@@ -43,8 +41,8 @@ const setupAll = async () => {
// }); // });
app.use(BaiduMap, { app.use(BaiduMap, {
ak: 'Yp57V71dkOPiXjiN8VdcFRsVELzlVNKK', ak: 'Yp57V71dkOPiXjiN8VdcFRsVELzlVNKK',
v: '3.0', v: '3.0'
}); })
await setupI18n(app) await setupI18n(app)
app.use(router) app.use(router)
@@ -55,7 +53,10 @@ const setupAll = async () => {
registerIcons(app) // icons registerIcons(app) // icons
app.config.globalProperties.eventBus = mitt() app.config.globalProperties.eventBus = mitt()
// 配置全局变量
app.config.globalProperties.$allVariables = reactive({
butLoading: false
})
setupFormCreate(app) setupFormCreate(app)
await router.isReady() await router.isReady()

View File

@@ -9,13 +9,13 @@ interface TableStoreParams {
pk?: string pk?: string
column: TableColumn[] column: TableColumn[]
params?: anyObj params?: anyObj
method?: Method // 请求方式 method?: Method // 请求方式
isWebPaging?: boolean // 是否前端分页 isWebPaging?: boolean // 是否前端分页
showPage?: boolean //是否需要分页 showPage?: boolean //是否需要分页
paramsPOST?: boolean // post请求 params传参 paramsPOST?: boolean // post请求 params传参
publicHeight?: number //计算高度 publicHeight?: number //计算高度
resetCallback?: () => void // 重置 resetCallback?: () => void // 重置
loadCallback?: () => void // 接口调用后的回调 loadCallback?: () => void // 接口调用后的回调
beforeSearchFun?: () => void // 接口调用前的回调 beforeSearchFun?: () => void // 接口调用前的回调
} }
@@ -78,24 +78,28 @@ export default class TableStore {
}, },
requestPayload(this.method, this.table.params, this.paramsPOST) requestPayload(this.method, this.table.params, this.paramsPOST)
) )
).then((res: any) => { )
if (res.data) { .then((res: any) => {
this.table.data = res.data.records || res.data if (res.data) {
this.table.total = res.data?.total || res.data.length || 0 this.table.data = res.data.records || res.data
} else { this.table.total = res.data?.total || res.data.length || 0
this.table.data = [] } else {
this.table.total = 0 this.table.data = []
} this.table.total = 0
if (Array.isArray(res)) { }
this.table.data = res if (Array.isArray(res)) {
} this.table.data = res
if (this.isWebPaging) { }
this.table.webPagingData = window.XEUtils.chunk(this.table.data, this.table.params.pageSize) if (this.isWebPaging) {
this.table.data = this.table.webPagingData[this.table.params.pageNum - 1] this.table.webPagingData = window.XEUtils.chunk(this.table.data, this.table.params.pageSize)
} this.table.data = this.table.webPagingData[this.table.params.pageNum - 1]
this.table.loadCallback && this.table.loadCallback() }
this.table.loading = false this.table.loadCallback && this.table.loadCallback()
}) this.table.loading = false
})
.catch(() => {
this.table.loading = false
})
} }
/** /**

View File

@@ -1,5 +1,6 @@
<template> <template>
<div class="default-main"> <div class="default-main">
<!-- <el-button :loading="$allVariables.butLoading ">123</el-button> -->
<el-tabs v-model="activeName" type="border-card"> <el-tabs v-model="activeName" type="border-card">
<el-tab-pane label="终端在线率列表" name="1"> <el-tab-pane label="终端在线率列表" name="1">
<Table /> <Table />
@@ -12,7 +13,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { onMounted, reactive, ref, provide } from 'vue' import { onMounted, reactive, ref, getCurrentInstance } from 'vue'
import { mainHeight } from '@/utils/layout' import { mainHeight } from '@/utils/layout'
import Table from './components/table.vue' import Table from './components/table.vue'
@@ -23,6 +24,15 @@ defineOptions({
const activeName = ref('1') const activeName = ref('1')
const layout = mainHeight(63) as any const layout = mainHeight(63) as any
// const { proxy } = getCurrentInstance()
// onMounted(() => {
// setTimeout(() => {
// proxy.$allVariables.butLoading = true
// setTimeout(() => {
// proxy.$allVariables.butLoading = false
// }, 3000);
// }, 3000);
// })
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@@ -30,6 +40,7 @@ const layout = mainHeight(63) as any
width: 100%; width: 100%;
height: 500px; height: 500px;
} }
:deep(.el-tabs__content) { :deep(.el-tabs__content) {
height: v-bind('layout.height'); height: v-bind('layout.height');
overflow-y: auto; overflow-y: auto;

View File

@@ -48,7 +48,7 @@
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-button type="primary" @click="init">查询</el-button> <el-button type="primary" @click="init" icon="el-icon-Search">查询</el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
<div style="flex: 1; overflow: hidden" class="mt10"> <div style="flex: 1; overflow: hidden" class="mt10">

View File

@@ -5,7 +5,7 @@
<DatePicker ref='datePickerRef'></DatePicker> <DatePicker ref='datePickerRef'></DatePicker>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-button type='primary' @click='init'>查询</el-button> <el-button type='primary' @click='init' icon="el-icon-Search">查询</el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
<div style='flex: 1;' class='mt10'> <div style='flex: 1;' class='mt10'>

View File

@@ -58,7 +58,7 @@
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-button type="primary" @click="init">查询</el-button> <el-button type="primary" @click="init" icon="el-icon-Search">查询</el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
<div style="flex: 1; overflow-y: scroll" class="mt10"> <div style="flex: 1; overflow-y: scroll" class="mt10">

View File

@@ -15,7 +15,7 @@
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-button type="primary" @click="init">查询</el-button> <el-button type="primary" @click="init" icon="el-icon-Search">查询</el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
<div style="flex: 1" class="mt10"> <div style="flex: 1" class="mt10">

View File

@@ -5,7 +5,7 @@
<DatePicker ref="datePickerRef"></DatePicker> <DatePicker ref="datePickerRef"></DatePicker>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-button type="primary" @click="init">查询</el-button> <el-button type="primary" @click="init" icon="el-icon-Search">查询</el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
<div style="flex: 1" class="mt10"> <div style="flex: 1" class="mt10">

View File

@@ -11,7 +11,7 @@
</el-radio-group> </el-radio-group>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-button type="primary" @click="init">查询</el-button> <el-button type="primary" @click="init" icon="el-icon-Search">查询</el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
<vxe-table :data="analysisData" v-bind="defaultAttribute"> <vxe-table :data="analysisData" v-bind="defaultAttribute">

View File

@@ -15,7 +15,7 @@
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-button type="primary" @click="init">查询</el-button> <el-button type="primary" @click="init" icon="el-icon-Search">查询</el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
<div style="flex: 1; display: flex; overflow: hidden" class="mt10"> <div style="flex: 1; display: flex; overflow: hidden" class="mt10">