Skip to content

Commit bbdf1a6

Browse files
author
xuzhiyong03
committed
fix: 修复移动端预览问题
1 parent 13fbdba commit bbdf1a6

15 files changed

Lines changed: 153 additions & 48 deletions

File tree

packages/cosmic-dqa/src/micro-content-scroll/doc/api.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,18 @@
1515
|-|-|-|-|-|-|
1616
|avatar|string|-||作者头像|PC/Mobile|
1717
|author|string|-||作者名称|PC/Mobile|
18+
|title|string|-||文本标题|PC/Mobile|
1819
|content|string|''||文本内容|PC/Mobile|
1920
|thumbnail|string|-||贴图内容|PC/Mobile|
2021
|tag|string|-||标签|PC/Mobile|
22+
|source|Source|-||来源信息|PC/Mobile|
2123
|linkInfo|[LinkInfo](/components/cosmic/link)|{}||跳转信息|PC/Mobile|
2224

25+
### Source 对象
26+
|name|string|-||来源名称|PC/Mobile|
27+
|tag|string|-||来源标签|PC/Mobile|
28+
|caption|string|''||来源说明|PC/Mobile|
29+
2330
### Events
2431

2532
|名称|参数|说明|覆盖平台|

packages/cosmic-dqa/src/micro-content-scroll/doc/multi-bottom.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,34 @@ export default class DefaultDemo extends Component {
2121
title: '以下是网友评论:',
2222
items: [
2323
{
24+
title: '标题标题标题标题标题标题标题标题标题标题标题标题标题标题标题',
2425
avatar: 'https://gips0.baidu.com/it/u=1093237061,3929050000&fm=3028&app=3028&f=PNG&fmt=auto&q=75&size=f670_792',
2526
author: '爱吃狼牙的土豆爱吃狼牙的土豆爱吃狼牙的土豆爱吃狼牙的土豆',
2627
content: '内容内容',
28+
source: {
29+
caption: '',
30+
tag: '真实案例'
31+
}
2732
},
2833
{
34+
title: '标题标题标题标题标题标题标题标题标题标题标题标题标题标题标题',
35+
thumbnail: 'https://gips0.baidu.com/it/u=2479417158,2594490198&fm=3028&app=3028&f=PNG&fmt=auto&q=75&size=f186_248',
2936
avatar: 'https://gips0.baidu.com/it/u=1093237061,3929050000&fm=3028&app=3028&f=PNG&fmt=auto&q=75&size=f670_792',
3037
author: '爱吃狼牙的土豆',
3138
content: '内容内容内容内容内容内容内容内容内容内容内内容内容内容内容内容内容内容内容内容',
39+
source: {
40+
caption: '来源来源',
41+
tag: '真实案例'
42+
}
3243
},
3344
{
3445
avatar: 'https://gips0.baidu.com/it/u=1093237061,3929050000&fm=3028&app=3028&f=PNG&fmt=auto&q=75&size=f670_792',
35-
author: '爱吃狼牙的土豆',
3646
content: '内容内容内容内容内容内容内容内容内容内容内内容内容内容内容内容内容内容内容内容',
47+
source: {
48+
caption: '来源来源',
49+
tag: '真实案例',
50+
name: '爱吃狼牙的土豆'
51+
}
3752
}
3853
],
3954
span: 8,

packages/cosmic-dqa/src/micro-content-scroll/index.pc.less

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,26 +51,38 @@
5151
&-author-name, &-author-suffix, &-author-colon {
5252
.cos-color-text-minor();
5353
.cos-font-medium();
54-
.cos-leading-none();
54+
line-height: 16px;
5555
}
5656
&-author-name {
57+
.cos-space-mr-xs();
5758
.cos-line-clamp-1();
58-
.cos-space-ml-xxs();
5959
}
6060
&-author-suffix, &-author-colon {
6161
.cos-shrink-0();
6262
}
6363
&-author-suffix {
64-
.cos-space-ml-3xs();
64+
.cos-space-mr-xs();
65+
}
66+
&-author-source-tag {
67+
.cos-shrink-0();
68+
.cos-space-pl-none();
69+
.cos-space-pr-none();
6570
}
6671
&-author-avatar {
6772
.cos-shrink-0();
73+
.cos-space-mr-xxs();
6874
}
6975

7076
&-content {
7177
.cos-flex();
7278
.cos-items-start();
7379
.cos-color-text();
80+
81+
&-title {
82+
.cos-text-body();
83+
.cos-font-medium();
84+
.cos-line-clamp-1();
85+
}
7486
}
7587
&-content-thumbnail {
7688
width: 57px;
@@ -79,8 +91,8 @@
7991
.cos-space-mr-sm();
8092
}
8193
&-content-text {
82-
.cos-line-clamp-3();
8394
position: relative;
95+
overflow: hidden;
8496
}
8597
&-content-tag {
8698
.cos-color-text-on-primary-light();

packages/cosmic-dqa/src/micro-content-scroll/interface.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ import type {LinkInfo} from '@cosui/cosmic/util/interface';
1919
export type MicroContentScrollAppearance = 'top' | 'bottom';
2020

2121
interface MicroContentItemProps {
22+
/**
23+
* 标题
24+
*/
25+
title: string;
26+
source?: Source;
2227

2328
/**
2429
* 作者头像
@@ -56,6 +61,12 @@ interface MicroContentItemProps {
5661
linkInfo?: LinkInfo;
5762
}
5863

64+
interface Source {
65+
caption?: string;
66+
name?: string;
67+
tag?: string;
68+
}
69+
5970
interface MicroContentScrollProps {
6071

6172
items: MicroContentItemProps[];

packages/cosmic-dqa/src/micro-content-scroll/item.ts

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,32 +58,44 @@ export default class MicroContentItem extends Component<MicroContentItemData> {
5858
/>
5959
</div>
6060
<div class="cosd-micro-content-scroll-item-content-text cos-text-body cos-space-m-none">
61-
<cos-tag
62-
s-if="tag"
63-
appearance="filled"
64-
class="cosd-micro-content-scroll-item-content-tag"
65-
>
66-
{{tag}}
67-
</cos-tag>
68-
{{content}}
61+
<div s-if="title" class="cosd-micro-content-scroll-item-content-title">
62+
{{title}}
63+
</div>
64+
<div class="{{title ? 'cos-line-clamp-2' : 'cos-line-clamp-3'}}">
65+
<cos-tag
66+
s-if="tag"
67+
appearance="filled"
68+
class="cosd-micro-content-scroll-item-content-tag"
69+
>
70+
{{tag}}
71+
</cos-tag>
72+
{{content}}
73+
</div>
6974
</div>
7075
</div>
7176
<!-- 作者在下 -->
7277
<div
7378
class="cosd-micro-content-scroll-item-author"
7479
s-if="appearance === 'bottom'"
7580
>
76-
<cos-avatar class="cosd-micro-content-scroll-item-author-avatar"
81+
<cos-avatar s-if="avatar" class="cosd-micro-content-scroll-item-author-avatar"
7782
src="{{avatar}}"
7883
alt="{{author}}"
7984
size="xs"
8085
/>
81-
<div class="cosd-micro-content-scroll-item-author-name">
82-
{{author}}
86+
<div s-if="author || source.name" class="cosd-micro-content-scroll-item-author-name">
87+
{{author || source.name}}
8388
</div>
8489
<div class="cosd-micro-content-scroll-item-author-suffix">
85-
的分享
90+
{{source.caption || '的分享'}}
8691
</div>
92+
<cos-tag
93+
s-if="source.tag"
94+
appearance="filled"
95+
class="cos-color-text-on-primary-light cosd-micro-content-scroll-item-author-source-tag"
96+
>
97+
{{source.tag}}
98+
</cos-tag>
8799
</div>
88100
</component>
89101
</div>
@@ -103,6 +115,8 @@ export default class MicroContentItem extends Component<MicroContentItemData> {
103115
thumbnail: '',
104116
tag: '',
105117
linkInfo: {},
118+
title: '',
119+
source: {},
106120
appearance: 'top'
107121
};
108122
}

packages/cosmic-dqa/src/search-header/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export default class SearchHeader extends Component<SearchHeaderData> {
4545
>
4646
</div>
4747
<div
48-
s-if="citationCount > 0 && !overview"
48+
s-elif="citationCount > 0 && !overview"
4949
class="cosd-search-header-citation"
5050
on-click="handleClick"
5151
>

packages/cosmic-dqa/src/transport-ticket/interface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,4 @@ interface Transfer {
156156

157157
export type TransportTicketData = Required<Omit<TransportTicketProps, 'transfer'>> &
158158
Pick<TransportTicketProps, 'transfer'>;
159-
export type {Seat, Segment, Transfer};
159+
export type {Seat, Segment, Transfer};

packages/cosmic-education/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cosui/cosmic-education",
3-
"version": "1.0.1",
3+
"version": "1.0.0",
44
"description": "",
55
"main": "./dist/mobile/index.js",
66
"exports": {

packages/cosmic-web/src/index.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Component} from 'san';
2-
import {router} from './utils/proxy-router';
2+
import {router, BASE_URL} from './utils/proxy-router';
33
import './index.less';
44
import routes from './router/routes';
55

@@ -23,21 +23,26 @@ const excludedPatterns = [
2323
/\/components\/cosmic-dqa\/overview/
2424
];
2525

26+
2627
const makeMobileLink = () => {
27-
const currentPath = location.pathname;
28+
let currentPath = location.pathname;
29+
if (BASE_URL && currentPath.startsWith(BASE_URL)) {
30+
currentPath = currentPath.slice(BASE_URL.length) || '';
31+
}
2832

2933
// 检查当前路径是否匹配任何排除模式
3034
const isExcluded = excludedPatterns.some(pattern => pattern.test(currentPath));
3135

3236
// 生成移动端链接
33-
if ((currentPath.includes('components') || currentPath.includes('json/') || currentPath.includes('agent-ui/'))
37+
if ((currentPath.includes('components') || currentPath.includes('markdown/component')
38+
|| currentPath.includes('json/') || currentPath.includes('agent-ui/'))
3439
&& !isExcluded
3540
) {
36-
return `${location.origin}/mobile/#/preview${currentPath}`;
41+
return `${location.origin}${BASE_URL}/mobile/#/preview${currentPath}`;
3742
}
3843

3944
// 生成默认链接
40-
return `${location.origin}/mobile/#/`;
45+
return `${location.origin}${BASE_URL}/mobile/#/`;
4146
};
4247

4348

packages/cosmic-web/src/mobile/components/preview.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,34 @@
11
import {Component} from 'san';
2-
import {router} from 'san-router';
2+
import {router, BASE_URL} from '../../utils/proxy-router';
33
import styles from '../../mobile.less?inline';
44

55
// eslint-disable-next-line max-len
66
const components = import.meta.glob('../../../../(cosmic|cosmic-card|cosmic-dqa|cosmic-shop)/**/doc/preview.ts');
77
const protocols = import.meta.glob('../../docs/protocol/**/preview.ts');
88
const uis = import.meta.glob('../../docs/agent-ui/**/preview.ts');
9+
const markdownComponent = import.meta.glob('../../../../cosmic-dqa/**/doc/*.ts');
910

1011

1112
const getComponents = (query: any) => {
1213
const {type, packages, component, ui} = query;
1314

1415
if (type === 'components') {
1516
const prefix = `../../../../${packages}/src/${component}/doc`;
17+
18+
if (component === 'markdown') {
19+
const alias = `${prefix}/index.ts`;
20+
return markdownComponent[alias] ? markdownComponent[alias]() : Promise.reject('load component fail');
21+
}
1622
const alias = `${prefix}/preview.ts`;
1723
return components[alias] ? components[alias]() : Promise.reject('load component fail');
1824
}
1925
else if (type === 'protocol' || type === 'agent-ui') {
2026
const prefix = `../../docs/${type}/${packages}`;
2127
let alias = null;
28+
if (packages === 'markdown') {
29+
alias = `../../../../cosmic-dqa/src/markdown/doc/${ui}.ts`;
30+
return markdownComponent[alias] ? markdownComponent[alias]() : Promise.reject('load component fail');
31+
}
2232
if (component === 'index') {
2333
alias = `${prefix}/preview.ts`;
2434
}
@@ -79,7 +89,7 @@ export default class Main extends Component {
7989
<div id="mobile-style" style="display: none;">{{styles}}</div>
8090
<div s-if="route.query.name || route.query.text" class="preview-head">
8191
<svg on-click="toHome" t="1650885692911" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="6649" width="18" height="18"><path d="M320 885.333333c-8.533333 0-17.066667-4.266667-23.466667-10.666666-12.8-12.8-10.666667-34.133333 2.133334-44.8L654.933333 512 298.666667 194.133333c-12.8-10.666667-14.933333-32-2.133334-44.8 10.666667-12.8 32-14.933333 44.8-2.133333l384 341.333333c6.4 6.4 10.666667 14.933333 10.666667 23.466667 0 8.533333-4.266667 17.066667-10.666667 23.466667l-384 341.333333c-6.4 6.4-12.8 8.533333-21.333333 8.533333z" p-id="6650"></path></svg>
82-
<span>{{route.query.name}} {{route.query.text}}</span>
92+
<span>{{route.query.name || ''}} {{route.query.text || ''}}</span>
8393
</div>
8494
<div id="content"></div>
8595
</div>
@@ -108,7 +118,7 @@ export default class Main extends Component {
108118
responsive() {
109119
if (window.innerWidth >= 600) {
110120
// eslint-disable-next-line
111-
const desktopUrl = `${location.origin}/${location.hash.replace(/#\/preview\/([^\?]+)\??.*/, '$1').toLowerCase()}`;
121+
const desktopUrl = `${location.origin}${BASE_URL}/${location.hash.replace(/#\/preview\/([^\?]+)\??.*/, '$1').toLowerCase()}`;
112122
location.href = desktopUrl;
113123
}
114124
};

0 commit comments

Comments
 (0)