Commit 86a0996a authored by 郭铭瑶's avatar 郭铭瑶 🤘

优化调用方法

parent 197562d0
# 动态组件库 # 动态组件库
## usage ## Dev
1. 执行命令`npm install`安装依赖
2. 执行命令`npm run serve`启动本地服务进行开发
## Build
1. 执行命令`npm run build:unpkg`进行打包; 1. 执行命令`npm run build:unpkg`进行打包;
...@@ -12,23 +18,18 @@ ...@@ -12,23 +18,18 @@
import fetchComponents from 'http://127.0.0.1:8080/component-lib.min.js' // 假设打包文件放在http://127.0.0.1:8080上 import fetchComponents from 'http://127.0.0.1:8080/component-lib.min.js' // 假设打包文件放在http://127.0.0.1:8080上
import * as vue from 'vue' import * as vue from 'vue'
fetchComponents(vue) // 需要和大屏共用一个vue,因此将vue作为参数传入 // 需要和大屏共用一个vue,因此将vue作为参数传入
// 第二个参数为请求数据地址
const { const { A001, A002, A003, A004, A005, A006 } = fetchComponents(vue)(
Property, 'http://127.0.0.1:8082',
PropertyFeatures, )
PartyLead,
PublicEarning,
Bid,
IndustrySupervision,
} = window._component_lib // 组件默认会设置在window._component_lib上
export default { export default {
Property, A001,
PropertyFeatures, A002,
PartyLead, A003,
PublicEarning, A004,
Bid, A005,
IndustrySupervision, A006,
} }
``` ```
...@@ -18,8 +18,6 @@ import * as components from '@/lib/index' ...@@ -18,8 +18,6 @@ import * as components from '@/lib/index'
<style lang="stylus" scoped> <style lang="stylus" scoped>
#main #main
width 100%
max-height 100%
box-sizing border-box box-sizing border-box
padding .05rem padding .05rem
-moz-column-count 4 -moz-column-count 4
...@@ -57,7 +55,6 @@ html, body ...@@ -57,7 +55,6 @@ html, body
#app #app
width 100% width 100%
height 100% height 100%
overflow hidden
font-size .1rem font-size .1rem
background url('../src/assets/images/background.jpg') center/100% 100% no-repeat background url('../src/assets/images/background.jpg') center/100% 100% no-repeat
color #fff color #fff
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
"scripts": { "scripts": {
"serve": "vue-cli-service serve dev/serve.ts", "serve": "vue-cli-service serve dev/serve.ts",
"prebuild": "rimraf ./dist", "prebuild": "rimraf ./dist",
"build": "cross-env NODE_ENV=production rollup --config build/rollup.config.js", "build": "cross-env NODE_ENV=production rollup --config build/rollup.config.js && node ./repair.js",
"build:ssr": "cross-env NODE_ENV=production rollup --config build/rollup.config.js --format cjs", "build:ssr": "cross-env NODE_ENV=production rollup --config build/rollup.config.js --format cjs",
"build:es": "cross-env NODE_ENV=production rollup --config build/rollup.config.js --format es", "build:es": "cross-env NODE_ENV=production rollup --config build/rollup.config.js --format es",
"build:unpkg": "cross-env NODE_ENV=production rollup --config build/rollup.config.js --format iife && node ./repair.js", "build:unpkg": "cross-env NODE_ENV=production rollup --config build/rollup.config.js --format iife && node ./repair.js",
......
...@@ -15,5 +15,6 @@ declare module '*.jpeg' ...@@ -15,5 +15,6 @@ declare module '*.jpeg'
declare module '*.gif' declare module '*.gif'
declare interface Window { declare interface Window {
_base_url: string
_component_lib: any _component_lib: any
} }
...@@ -2,16 +2,11 @@ import { App, Plugin } from 'vue' ...@@ -2,16 +2,11 @@ import { App, Plugin } from 'vue'
import * as components from '@/lib/index' import * as components from '@/lib/index'
const install: Exclude<Plugin['install'], undefined> = function installCom( const install: Exclude<Plugin['install'], undefined> = function (app: App) {
app: App,
) {
Object.entries(components).forEach(([componentName, component]) => { Object.entries(components).forEach(([componentName, component]) => {
app.component(componentName, component) app.component(componentName, component)
}) })
} }
export default install export default install
export * from '@/lib/index' export * from '@/lib/index'
window._component_lib = components
// iife/cjs usage extends esm default export - so import it all import * as components from '@/lib/index'
import plugin, * as components from '@/entry.esm'
// Attach named exports directly to plugin. IIFE/CJS will export default function (url: string) {
// only expose one global var, with component exports exposed as properties of window._base_url = url
// that global var (eg. plugin.component) return components
type NamedExports = Exclude<typeof components, 'default'> }
type ExtendedPlugin = typeof plugin & NamedExports
Object.entries(components).forEach(([componentName, component]) => {
if (componentName !== 'default') {
const key = componentName as Exclude<keyof NamedExports, 'default'>
const val = component as Exclude<ExtendedPlugin, typeof plugin>
;(plugin as ExtendedPlugin)[key] = val
}
})
export default plugin
...@@ -36,7 +36,8 @@ ...@@ -36,7 +36,8 @@
<script lang="ts"> <script lang="ts">
export default { export default {
name: 'Property', name: 'A001',
title: '物业',
} }
</script> </script>
<script lang="ts" setup> <script lang="ts" setup>
...@@ -44,7 +45,6 @@ import icon1 from '@/assets/images/icon1.png' ...@@ -44,7 +45,6 @@ import icon1 from '@/assets/images/icon1.png'
import icon2 from '@/assets/images/icon2.png' import icon2 from '@/assets/images/icon2.png'
import icon3 from '@/assets/images/icon3.png' import icon3 from '@/assets/images/icon3.png'
import Brief from '@/components/brief.vue' import Brief from '@/components/brief.vue'
const summary = [ const summary = [
{ icon: icon1, name: '小区', value: 904 }, { icon: icon1, name: '小区', value: 904 },
{ icon: icon2, name: '业委会', value: 400 }, { icon: icon2, name: '业委会', value: 400 },
......
...@@ -11,7 +11,8 @@ ...@@ -11,7 +11,8 @@
<script lang="ts"> <script lang="ts">
export default { export default {
name: 'PropertyFeatures', name: 'A002',
title: '物业体征',
} }
</script> </script>
<script lang="ts" setup> <script lang="ts" setup>
......
...@@ -25,6 +25,12 @@ ...@@ -25,6 +25,12 @@
</m-card> </m-card>
</template> </template>
<script lang="ts">
export default {
name: 'A003',
title: '党建引领',
}
</script>
<script lang="ts" setup> <script lang="ts" setup>
import { computed } from 'vue' import { computed } from 'vue'
import Circle from '@/components/circle.vue' import Circle from '@/components/circle.vue'
......
...@@ -35,6 +35,12 @@ ...@@ -35,6 +35,12 @@
</m-card> </m-card>
</template> </template>
<script lang="ts">
export default {
name: 'A004',
title: '公共收益',
}
</script>
<script lang="ts" setup></script> <script lang="ts" setup></script>
<style lang="stylus" scoped> <style lang="stylus" scoped>
......
...@@ -34,6 +34,12 @@ ...@@ -34,6 +34,12 @@
</m-card> </m-card>
</template> </template>
<script lang="ts">
export default {
name: 'A005',
title: '招投标',
}
</script>
<script lang="ts" setup> <script lang="ts" setup>
import Circle from '@/components/circle.vue' import Circle from '@/components/circle.vue'
</script> </script>
......
...@@ -65,6 +65,12 @@ ...@@ -65,6 +65,12 @@
</m-card> </m-card>
</template> </template>
<script lang="ts">
export default {
name: 'A006',
title: '行业监管',
}
</script>
<script lang="ts" setup></script> <script lang="ts" setup></script>
<style lang="stylus" scoped> <style lang="stylus" scoped>
......
export { default as Property } from './a001/property.vue' export { default as A001 } from './A001/index.vue'
export { default as PropertyFeatures } from './a002/property-features.vue' export { default as A002 } from './A002/index.vue'
export { default as PartyLead } from './a003/party-lead.vue' export { default as A003 } from './A003/index.vue'
export { default as PublicEarning } from './a004/public-earning.vue' export { default as A004 } from './A004/index.vue'
export { default as Bid } from './a005/bid.vue' export { default as A005 } from './A005/index.vue'
export { default as IndustrySupervision } from './a006/industry-supervision.vue' export { default as A006 } from './A006/index.vue'
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment