@cys26/zpb-comp 0.1.0 → 0.2.0
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/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @cys26/zpb-comp
|
|
2
2
|
|
|
3
|
-
基于 Vue 3
|
|
3
|
+
基于 Vue 3 的业务组件库,当前提供聊天文字气泡 **`zp-chat-text-bubble`**(与 wot-ui 类似的 `zp-` 前缀目录结构),适用于 **uni-app / Vite** 等能直接编译 `node_modules` 内 `.vue` 源码的工程。
|
|
4
4
|
|
|
5
5
|
## 安装
|
|
6
6
|
|
|
@@ -12,9 +12,36 @@ npm install @cys26/zpb-comp
|
|
|
12
12
|
|
|
13
13
|
依赖:**Vue ^3.5**(已声明为 `peerDependencies`,请在使用方项目中安装 Vue)。
|
|
14
14
|
|
|
15
|
-
##
|
|
15
|
+
## uni-app:easycom 自动引入(推荐)
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
在 **`pages.json`** 的 `easycom.custom` 中增加(将包名换成你实际安装的 scope):
|
|
18
|
+
|
|
19
|
+
```json
|
|
20
|
+
{
|
|
21
|
+
"easycom": {
|
|
22
|
+
"autoscan": true,
|
|
23
|
+
"custom": {
|
|
24
|
+
"^zp-(.*)": "@cys26/zpb-comp/src/components/zp-$1/zp-$1.vue"
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
页面模板里**无需 import**,直接使用与路径一致的标签名,例如聊天气泡:
|
|
31
|
+
|
|
32
|
+
```vue
|
|
33
|
+
<zp-chat-text-bubble
|
|
34
|
+
role="receiver"
|
|
35
|
+
avatar-text="收"
|
|
36
|
+
text="正文内容"
|
|
37
|
+
/>
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
规则说明:标签 `zp-chat-text-bubble` 对应目录 `components/zp-chat-text-bubble/zp-chat-text-bubble.vue`,与 `'^wd-(.*)': '@wot-ui/ui/components/wd-$1/wd-$1.vue'` 同一套写法。
|
|
41
|
+
|
|
42
|
+
## 其他用法
|
|
43
|
+
|
|
44
|
+
### 默认插件(全局注册 `ZpChatTextBubble`)
|
|
18
45
|
|
|
19
46
|
```ts
|
|
20
47
|
// main.ts
|
|
@@ -28,34 +55,28 @@ export function createApp() {
|
|
|
28
55
|
}
|
|
29
56
|
```
|
|
30
57
|
|
|
31
|
-
|
|
58
|
+
模板中可使用 `<ZpChatTextBubble />` 或 `<zp-chat-text-bubble />`。
|
|
32
59
|
|
|
33
|
-
|
|
34
|
-
<ChatTextBubble
|
|
35
|
-
role="receiver"
|
|
36
|
-
avatar-text="收"
|
|
37
|
-
text="正文内容"
|
|
38
|
-
/>
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
### 方式二:具名导出(按需 import)
|
|
60
|
+
### 具名导出(按需 import)
|
|
42
61
|
|
|
43
62
|
```vue
|
|
44
63
|
<script setup lang="ts">
|
|
45
|
-
import {
|
|
64
|
+
import { ZpChatTextBubble } from '@cys26/zpb-comp'
|
|
46
65
|
</script>
|
|
47
66
|
|
|
48
67
|
<template>
|
|
49
|
-
<
|
|
68
|
+
<ZpChatTextBubble role="sender" avatar-text="我" text="发送方气泡" />
|
|
50
69
|
</template>
|
|
51
70
|
```
|
|
52
71
|
|
|
53
|
-
###
|
|
72
|
+
### 深路径导入 SFC
|
|
54
73
|
|
|
55
74
|
```ts
|
|
56
|
-
import
|
|
75
|
+
import ZpChatTextBubble from '@cys26/zpb-comp/components/zp-chat-text-bubble/zp-chat-text-bubble.vue'
|
|
57
76
|
```
|
|
58
77
|
|
|
78
|
+
旧路径 `components/chat-text-bubble/chat-text-bubble.vue` 在 `package.json` 的 `exports` 中仍重定向到新文件,便于渐进迁移。
|
|
79
|
+
|
|
59
80
|
## 发布说明(维护者)
|
|
60
81
|
|
|
61
82
|
作用域包发布到 npm 公共仓库:
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "0.
|
|
6
|
+
"version": "0.2.0",
|
|
7
7
|
"description": "基于 uni-app 原生能力的业务组件库(H5 / 小程序等)",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"engines": {
|
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
"import": "./src/index.ts",
|
|
19
19
|
"default": "./src/index.ts"
|
|
20
20
|
},
|
|
21
|
-
"./components/chat-text-bubble/chat-text-bubble.vue": "./src/components/chat-text-bubble/chat-text-bubble.vue"
|
|
21
|
+
"./components/zp-chat-text-bubble/zp-chat-text-bubble.vue": "./src/components/zp-chat-text-bubble/zp-chat-text-bubble.vue",
|
|
22
|
+
"./components/chat-text-bubble/chat-text-bubble.vue": "./src/components/zp-chat-text-bubble/zp-chat-text-bubble.vue"
|
|
22
23
|
},
|
|
23
24
|
"files": [
|
|
24
25
|
"src"
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
import { computed, onUnmounted, ref, watch } from 'vue'
|
|
3
3
|
|
|
4
4
|
defineOptions({
|
|
5
|
-
name: '
|
|
5
|
+
name: 'ZpChatTextBubble',
|
|
6
6
|
})
|
|
7
7
|
|
|
8
8
|
const props = withDefaults(
|
|
9
9
|
defineProps<{
|
|
10
|
-
/**
|
|
10
|
+
/** 发送方:右侧绿气泡;接收方:左侧白底气泡 */
|
|
11
11
|
role: 'sender' | 'receiver'
|
|
12
12
|
/** 头像内展示文案,通常取昵称首字 */
|
|
13
13
|
avatarText?: string
|
package/src/index.ts
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import type { App, Plugin } from 'vue'
|
|
2
|
-
import
|
|
2
|
+
import ZpChatTextBubble from './components/zp-chat-text-bubble/zp-chat-text-bubble.vue'
|
|
3
3
|
|
|
4
|
-
export
|
|
5
|
-
export { ZP_CHAT_STREAM_END } from './types/chat'
|
|
6
|
-
|
|
7
|
-
export { ChatTextBubble }
|
|
4
|
+
export { ZpChatTextBubble }
|
|
8
5
|
|
|
9
6
|
const plugin: Plugin = {
|
|
10
7
|
install(app: App) {
|
|
11
|
-
app.component('
|
|
8
|
+
app.component('ZpChatTextBubble', ZpChatTextBubble)
|
|
12
9
|
},
|
|
13
10
|
}
|
|
14
11
|
|
package/src/types/chat.ts
CHANGED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export type ZpChatFrom = 'self' | 'peer'
|
|
2
|
-
|
|
3
|
-
/** 单条消息:流式场景用 segments 多段拼接展示 */
|
|
4
|
-
export interface ZpChatMessage {
|
|
5
|
-
id: string
|
|
6
|
-
from: ZpChatFrom
|
|
7
|
-
segments: string[]
|
|
8
|
-
ts: number
|
|
9
|
-
/** 为 true 时在文本末尾显示闪烁光标(流式未结束) */
|
|
10
|
-
printing?: boolean
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/** 与后端约定:单独一帧为该值(trim 后)表示本条流结束,不展示该帧 */
|
|
14
|
-
export const ZP_CHAT_STREAM_END = 'end'
|