2024-04-12 10:22:47 +08:00
|
|
|
|
//本地仓库外部组件
|
|
|
|
|
|
|
|
|
|
|
|
// 存储组件列表
|
|
|
|
|
|
let components = [];
|
|
|
|
|
|
// 定义 install 方法,接收 Vue 作为参数。如果使用 use 注册插件,则所有的组件都将被注册
|
|
|
|
|
|
const install = function (Vue) {
|
|
|
|
|
|
if (install.installed) return;
|
|
|
|
|
|
// 声明全局业务对象类
|
|
|
|
|
|
const models = require.context('./model', true, /\.js$/)
|
|
|
|
|
|
if (models) {
|
|
|
|
|
|
const model = {}
|
|
|
|
|
|
models.keys().map(e => {
|
|
|
|
|
|
model[e.replace(/\.[\/\\]([^\\\/]+)\.js$/, '$1')] = models(e).default
|
|
|
|
|
|
})
|
|
|
|
|
|
Vue.prototype.MODEL = model
|
|
|
|
|
|
}
|
|
|
|
|
|
Vue.prototype.$echartTpls = require("./AiEchart/echartTpls").default
|
|
|
|
|
|
// 遍历注册全局组件
|
|
|
|
|
|
let contexts = require.context('.', true, /[\\\/]Ai([^\\\/]+)\.vue$/);
|
|
|
|
|
|
if (contexts) {
|
|
|
|
|
|
contexts.keys().map((e) => {
|
|
|
|
|
|
components.push(contexts(e).default);
|
|
|
|
|
|
Vue.component(contexts(e).default.name, contexts(e).default);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 判断是否是直接引入文件
|
|
|
|
|
|
if (typeof window !== 'undefined' && window.Vue) {
|
|
|
|
|
|
install(window.Vue);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 大屏组件数据类
|
|
|
|
|
|
*/
|
|
|
|
|
|
export class DvCompData {
|
|
|
|
|
|
static types = {
|
|
|
|
|
|
staticData: "静态数据", dynamicData: "动态数据", apiData: "接口数据", htmlData: "HTML数据"
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-04-12 18:19:49 +08:00
|
|
|
|
constructor(dataConfig = {dataType: ""}, instance) {
|
2024-04-12 10:22:47 +08:00
|
|
|
|
this.instance = instance
|
2024-04-12 18:19:49 +08:00
|
|
|
|
this.type = dataConfig.dataType
|
2024-04-12 10:22:47 +08:00
|
|
|
|
this.params = dataConfig
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-04-12 18:19:49 +08:00
|
|
|
|
getData(params) {
|
2024-04-12 10:22:47 +08:00
|
|
|
|
return this.type == 'staticData' ? this.getStaticData() :
|
|
|
|
|
|
this.type == 'htmlData' ? this.getStaticData() :
|
2024-04-12 18:19:49 +08:00
|
|
|
|
this.type == 'dynamicData' ? this.getDynamicData(params) :
|
|
|
|
|
|
this.type == 'apiData' ? this.getApiData(params) : Promise.resolve([])
|
2024-04-12 10:22:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-04-12 18:19:49 +08:00
|
|
|
|
getDynamicData(params) {
|
2024-04-12 10:22:47 +08:00
|
|
|
|
const {sourceDataId: id} = this.params
|
2024-04-12 18:19:49 +08:00
|
|
|
|
return id ? this.getAsyncData(`/app/appdiylargescreen/statisticsByLsid?id=${id}`, params) : Promise.reject("未获取到数据源id")
|
2024-04-12 10:22:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
getStaticData() {
|
|
|
|
|
|
const {staticData} = this.params
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
|
staticData ? resolve(staticData) : reject("未获取到静态数据")
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-04-12 18:19:49 +08:00
|
|
|
|
getApiData(params) {
|
2024-04-12 10:22:47 +08:00
|
|
|
|
const {api} = this.params
|
2024-04-12 18:19:49 +08:00
|
|
|
|
return api ? this.getAsyncData(api, params) : Promise.reject("未获取到api")
|
2024-04-12 10:22:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-04-12 18:19:49 +08:00
|
|
|
|
getAsyncData(api, params) {
|
|
|
|
|
|
return this.instance.post(api, null, {params}).then(res => {
|
2024-04-12 10:22:47 +08:00
|
|
|
|
if (res?.data) {
|
|
|
|
|
|
const list = res.data,
|
|
|
|
|
|
firstRecord = list?.[0] || {},
|
|
|
|
|
|
keys = Object.keys(firstRecord)
|
|
|
|
|
|
let meta = []
|
|
|
|
|
|
if (['AiDvTable', 'table'].includes(this.params.type)) {
|
|
|
|
|
|
meta = keys.map(v => {
|
|
|
|
|
|
let obj = {}
|
|
|
|
|
|
list.forEach((item, index) => {
|
|
|
|
|
|
obj[`v${index}`] = item[v]
|
|
|
|
|
|
})
|
|
|
|
|
|
return {row: v, ...obj}
|
|
|
|
|
|
})
|
|
|
|
|
|
} else if (this.params.type === 'summary') {
|
|
|
|
|
|
if (this.params.display === 'summary9') {
|
|
|
|
|
|
meta = res.data
|
|
|
|
|
|
} else {
|
|
|
|
|
|
meta = keys.map(key => ({key, value: firstRecord[key]}))
|
|
|
|
|
|
}
|
|
|
|
|
|
} else if (this.type === 'dynamicData' && !this.params.dataX && this.params.dataY?.length <= 0) {
|
|
|
|
|
|
meta = keys.map(key => ({key, value: firstRecord[key]}))
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if (this.params.dataX && this.params.dataY.length) {
|
|
|
|
|
|
list.forEach(i => {
|
|
|
|
|
|
let obj = {}
|
|
|
|
|
|
this.params.dataY.forEach(v => obj[v] = i[v])
|
|
|
|
|
|
meta.push({
|
|
|
|
|
|
[this.params.dataX]: i[this.params.dataX], ...obj
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
} else {
|
|
|
|
|
|
meta = res.data
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return meta
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
|
// 导出的对象必须具有 install,才能被 Vue.use() 方法安装
|
|
|
|
|
|
install,
|
|
|
|
|
|
// 以下组件列表
|
|
|
|
|
|
...components
|
|
|
|
|
|
};
|