st-comp 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/App.vue CHANGED
@@ -1,24 +1,87 @@
1
- <script setup lang="ts">
2
- import Table from './components/Table/index.vue'
3
- </script>
4
-
5
1
  <template>
6
- <div>
7
- <Table />
2
+ <div class="container">
3
+ <div class="header">前端公共组件库</div>
4
+ <div class="content">
5
+ <div class="content-left">
6
+ <el-menu
7
+ :default-active="route.path"
8
+ class="el-menu-vertical-demo"
9
+ text-color="rgba(255, 255, 255, 0.65)"
10
+ active-text-color="#ffffff"
11
+ background-color="#001529"
12
+ :router="true"
13
+ >
14
+ <el-menu-item
15
+ v-for="item in routes"
16
+ :index="item.path"
17
+ :key="item.name"
18
+ popper-append-to-body
19
+ >
20
+ <template #title>{{ item.name }}</template>
21
+ </el-menu-item>
22
+ </el-menu>
23
+ </div>
24
+ <div class="content-right">
25
+ <div class="content-right-main">
26
+ <router-view />
27
+ </div>
28
+ </div>
29
+ </div>
8
30
  </div>
9
31
  </template>
10
32
 
11
- <style scoped>
12
- .logo {
13
- height: 6em;
14
- padding: 1.5em;
15
- will-change: filter;
16
- transition: filter 300ms;
33
+ <script setup lang="ts">
34
+ import { useRoute } from 'vue-router'
35
+ import routes from './router/routes.ts'
36
+
37
+ const route = useRoute()
38
+ </script>
39
+
40
+ <style>
41
+ .el-menu-vertical-demo:not(.el-menu--collapse) {
42
+ width: 200px;
43
+ height: calc(100% - 64px);
44
+ }
45
+ .el-menu {
46
+ --el-menu-hover-bg-color: #1677ff !important;
47
+ border: none !important;
48
+ }
49
+ .el-menu li {
50
+ font-size: 18px;
17
51
  }
18
- .logo:hover {
19
- filter: drop-shadow(0 0 2em #646cffaa);
52
+ .el-menu-item.is-active {
53
+ background-color: #1677ff;
20
54
  }
21
- .logo.vue:hover {
22
- filter: drop-shadow(0 0 2em #42b883aa);
55
+ </style>
56
+
57
+ <style lang="scss" scoped>
58
+ .container {
59
+ min-height: 100vh;
60
+ .header {
61
+ height: 64px;
62
+ padding-left: 22px;
63
+ background: #001529;
64
+ color: #fff;
65
+ line-height: 64px;
66
+ font-size: 22px;
67
+ }
68
+ .content {
69
+ display: flex;
70
+ height: calc(100vh - 64px);
71
+ &-left {
72
+ width: 200px;
73
+ height: 100%;
74
+ background: #001529;
75
+ }
76
+ &-right {
77
+ flex: 1;
78
+ background: #ebebeb;
79
+ padding: 20px;
80
+ &-main {
81
+ background: #fff;
82
+ height: 100%;
83
+ }
84
+ }
85
+ }
23
86
  }
24
87
  </style>
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <div :style="{ width: '50%', height: '600px' }">
2
+ <div id="Kline">
3
3
  <st-kline
4
4
  code="ao8888.SHFE"
5
5
  endTime="2023-10-13T16:24:28"
@@ -13,5 +13,9 @@
13
13
  </script>
14
14
 
15
15
  <style scoped>
16
-
16
+ #Kline{
17
+ margin: auto;
18
+ width: 1200px;
19
+ height: 600px;
20
+ }
17
21
  </style>
@@ -0,0 +1,58 @@
1
+ <!-- KlineGroup [默认六宫格]多周期业务K线组件 -->
2
+ <script setup lang="ts">
3
+ import dayjs from 'dayjs'
4
+ const props = defineProps({
5
+ // 品种代码
6
+ code: {
7
+ type: String,
8
+ require: true,
9
+ },
10
+ // 周期名称
11
+ freqNameArray: {
12
+ type: Array,
13
+ default: () => {
14
+ return ['5m', '15m', '30m', '60m', '1d', '1w']
15
+ },
16
+ },
17
+ // 指标类型
18
+ indicatorType: {
19
+ type: String,
20
+ default: 'DKX_EMA',
21
+ },
22
+ // 交易日期
23
+ tradeDate: {
24
+ type: String,
25
+ default: dayjs().format('YYYY-MM-DD'),
26
+ },
27
+ })
28
+ console.log('六宫格需要接收到的参数:',props)
29
+ </script>
30
+
31
+ <template>
32
+ <h2>传入的交易时间: 2023-10-13</h2>
33
+ <div class="KlineGroup element-dark">
34
+ <st-kline
35
+ class="st-kline"
36
+ v-for="item in freqNameArray"
37
+ code="ao8888.SHFE"
38
+ indicator="DKX_EMA"
39
+ :frequency="item"
40
+ tradeDate="2023-10-13"
41
+ />
42
+ </div>
43
+ </template>
44
+
45
+ <style lang="scss" scoped>
46
+ .KlineGroup {
47
+ display: flex;
48
+ flex-wrap: wrap;
49
+ width: 100%;
50
+ height: 800px;
51
+ justify-content: space-between;
52
+ align-content: space-between;
53
+ .st-kline {
54
+ width: calc(100% / 3 - 2px);
55
+ height: calc(100% / 2 - 2px);
56
+ }
57
+ }
58
+ </style>
package/src/main.ts CHANGED
@@ -1,6 +1,10 @@
1
1
  import { createApp } from 'vue'
2
2
  import './style.css'
3
3
  import App from './App.vue'
4
+ import router from './router'
4
5
  import stComp from '../packages/index.ts'
5
6
 
6
- createApp(App).use(stComp).mount('#app')
7
+ createApp(App)
8
+ .use(router)
9
+ .use(stComp)
10
+ .mount('#app')
@@ -0,0 +1,12 @@
1
+ <template>
2
+ <div>
3
+ Button
4
+ </div>
5
+ </template>
6
+
7
+ <script setup lang="ts">
8
+ </script>
9
+
10
+ <style lang="scss" scoped>
11
+
12
+ </style>
@@ -0,0 +1,12 @@
1
+ <template>
2
+ <div>
3
+ Echarts
4
+ </div>
5
+ </template>
6
+
7
+ <script setup lang="ts">
8
+ </script>
9
+
10
+ <style lang="scss" scoped>
11
+
12
+ </style>
@@ -0,0 +1,12 @@
1
+ <template>
2
+ <div>
3
+ Kline123456
4
+ </div>
5
+ </template>
6
+
7
+ <script setup lang="ts">
8
+ </script>
9
+
10
+ <style lang="scss" scoped>
11
+
12
+ </style>
@@ -0,0 +1,12 @@
1
+ <template>
2
+ <div>
3
+ List
4
+ </div>
5
+ </template>
6
+
7
+ <script setup lang="ts">
8
+ </script>
9
+
10
+ <style lang="scss" scoped>
11
+
12
+ </style>
@@ -0,0 +1,27 @@
1
+ <template>
2
+ <div :style="{ width: '100%', height: '600px' }">
3
+ <st-table
4
+ :data="data"
5
+ :column="column"
6
+ />
7
+ </div>
8
+ </template>
9
+
10
+ <script setup lang="ts">
11
+ const data = [
12
+ { name: 'name1' },
13
+ { name: 'name2' },
14
+ { name: 'name3' },
15
+ ]
16
+
17
+ const column = [
18
+ {
19
+ label: '名称',
20
+ prop: 'name',
21
+ },
22
+ ]
23
+ </script>
24
+
25
+ <style lang="scss" scoped>
26
+
27
+ </style>
@@ -0,0 +1,9 @@
1
+ import { createRouter, createWebHashHistory } from 'vue-router'
2
+ import routes from './routes'
3
+
4
+ const router = createRouter({
5
+ history: createWebHashHistory(),
6
+ routes,
7
+ })
8
+
9
+ export default router
@@ -0,0 +1,27 @@
1
+ export default [
2
+ {
3
+ path: '/button',
4
+ name: 'Button',
5
+ component: () => import('@/pages/Button/index.vue'),
6
+ },
7
+ {
8
+ path: '/echarts',
9
+ name: 'Echarts',
10
+ component: () => import('@/pages/Echarts/index.vue'),
11
+ },
12
+ {
13
+ path: '/kline',
14
+ name: 'Kline',
15
+ component: () => import('@/pages/Kline/index.vue'),
16
+ },
17
+ {
18
+ path: '/list',
19
+ name: 'List',
20
+ component: () => import('@/pages/List/index.vue'),
21
+ },
22
+ {
23
+ path: '/table',
24
+ name: 'Table',
25
+ component: () => import('@/pages/Table/index.vue'),
26
+ },
27
+ ]
package/src/style.css CHANGED
@@ -0,0 +1,4 @@
1
+ html, body {
2
+ padding: 0;
3
+ margin: 0;
4
+ }
package/src/vite-env.d.ts CHANGED
@@ -1 +1,8 @@
1
1
  /// <reference types="vite/client" />
2
+ // vue3 报错提示 找不到模块“./XXX.vue”或其相应的类型声明
3
+ // 报错原因:typescript 只能理解 .ts 文件,无法理解 .vue文件
4
+ declare module '*.vue' {
5
+ import type { DefineComponent } from 'vue'
6
+ const component: DefineComponent<{}, {}, any>
7
+ export default component
8
+ }
package/vite.config.ts CHANGED
@@ -3,6 +3,7 @@ import vue from '@vitejs/plugin-vue'
3
3
  import AutoImport from 'unplugin-auto-import/vite' // element-plus自动引用使用
4
4
  import Components from 'unplugin-vue-components/vite' // element-plus自动引用使用
5
5
  import { ElementPlusResolver } from 'unplugin-vue-components/resolvers' // element-plus自动引用使用
6
+ import createExportFile from './vitePlugins/createExportFile.ts'
6
7
 
7
8
  // https://vitejs.dev/config/
8
9
  export default defineConfig({
@@ -14,6 +15,7 @@ export default defineConfig({
14
15
  Components({
15
16
  resolvers: [ElementPlusResolver()],
16
17
  }),
18
+ createExportFile(),
17
19
  ],
18
20
  build: {
19
21
  outDir: 'lib',
@@ -21,6 +23,23 @@ export default defineConfig({
21
23
  entry: './packages/index.ts',
22
24
  name: 'Bundle',
23
25
  fileName: 'bundle'
26
+ },
27
+ rollupOptions: {
28
+ external: ['vue', 'echarts', 'element-plus'],
29
+ }
30
+ },
31
+ resolve: {
32
+ alias: {
33
+ '@': './src'
34
+ }
35
+ },
36
+ server: {
37
+ proxy: {
38
+ '/proxy': {
39
+ target: 'http://192.168.12.49:88/',
40
+ changeOrigin: true,
41
+ rewrite: (path) => path.replace(/^\/proxy/, ''),
42
+ }
24
43
  }
25
44
  }
26
45
  })
@@ -0,0 +1,97 @@
1
+ /**
2
+ * 创建统一的导出文件
3
+ */
4
+ import fs from 'fs'
5
+
6
+ const toFirstLowerCase = (word) => {
7
+ return `${word[0].toLowerCase()}${word.substr(1)}`
8
+ }
9
+
10
+ export default () => {
11
+ return {
12
+ name: 'createExport',
13
+ buildStart() {
14
+ fs.readdir('./packages', (err, files) => {
15
+ if (err) {
16
+ console.error(err)
17
+ return
18
+ }
19
+ const filterFiles = files.filter(fileName => !fileName.includes('.'))
20
+ // 生成每个组件的导出文件
21
+ filterFiles.forEach(fileName => {
22
+ const content = `import { App } from "vue";
23
+ import St${fileName} from "./index.vue";
24
+
25
+ export default {
26
+ install(app: App) {
27
+ app.component("st-${toFirstLowerCase(fileName)}", St${fileName});
28
+ },
29
+ }
30
+ `
31
+ fs.writeFile(`./packages/${fileName}/index.ts`, content, (err) => {
32
+ if (err) throw err
33
+ })
34
+ })
35
+ // 生成统一导出文件
36
+ const mainContent = `import { App } from "vue"
37
+ ${filterFiles.map(fileName => `import St${fileName} from "./${fileName}/index.ts"`).join(`
38
+ `)}
39
+
40
+ export default {
41
+ install(app: App) {
42
+ ${filterFiles.map(fileName => `St${fileName}.install(app)`).join(`
43
+ `)}
44
+ },
45
+ }
46
+ `
47
+ fs.writeFile(`./packages/index.ts`, mainContent, (err) => {
48
+ if (err) throw err
49
+ })
50
+ // 生成routes配置
51
+ const routesContent = `export default [
52
+ ${filterFiles.map(fileName => `{
53
+ path: '/${toFirstLowerCase(fileName)}',
54
+ name: '${fileName}',
55
+ component: () => import('@/pages/${fileName}/index.vue'),
56
+ },`).join(`
57
+ `)}
58
+ ]
59
+ `
60
+ fs.writeFile(`./src/router/routes.ts`, routesContent, (err) => {
61
+ if (err) throw err
62
+ })
63
+ // 如果没有pages文件,则生成pages文件
64
+ fs.readdir('./src/pages', (pagesErr, pagesFiles) => {
65
+ if (pagesErr) {
66
+ console.error(pagesErr)
67
+ return
68
+ }
69
+ const filterPagesFiles = pagesFiles.filter(fileName => !fileName.includes('.'))
70
+ filterFiles.forEach(fileName => {
71
+ if (!filterPagesFiles.includes(fileName)) {
72
+ const pagesContent = `<template>
73
+ <div>
74
+ ${fileName}
75
+ </div>
76
+ </template>
77
+
78
+ <script setup lang="ts">
79
+ </script>
80
+
81
+ <style lang="scss" scoped>
82
+
83
+ </style>
84
+ `
85
+ fs.mkdir(`./src/pages/${fileName}`, err => {
86
+ if(err) throw err;
87
+ fs.writeFile(`./src/pages/${fileName}/index.vue`, pagesContent, (err) => {
88
+ if (err) throw err
89
+ })
90
+ })
91
+ }
92
+ })
93
+ })
94
+ })
95
+ }
96
+ }
97
+ }