New Huajishe Check ChaoXing

This commit is contained in:
e2hang
2025-10-01 10:01:52 +08:00
parent 240b884eac
commit 80be8ae3cf
1094 changed files with 61709 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
:: BASE_DOC ::
## API
### Navbar Props
name | type | default | description | required
-- | -- | -- | -- | --
style | Object | - | CSS(Cascading Style Sheets) | N
custom-style | Object | - | CSS(Cascading Style Sheets)used to set style on virtual component | N
animation | Boolean | true | \- | N
capsule | Slot | - | [see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/src/common/common.ts) | N
delta | Number | 1 | \- | N
fixed | Boolean | true | \- | N
left | Slot | - | `0.26.0`。[see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/src/common/common.ts) | N
left-arrow | Boolean | false | `0.26.0` | N
title | String / Slot | - | page title。[see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/src/common/common.ts) | N
title-max-length | Number | - | \- | N
visible | Boolean | true | \- | N
### Navbar Events
name | params | description
-- | -- | --
complete | \- | \-
fail | \- | \-
go-back | \- | \-
success | \- | \-
### Navbar External Classes
className | Description
-- | --
t-class | \-
t-class-capsule | \-
t-class-center | \-
t-class-home-icon | \-
t-class-left | \-
t-class-left-icon | \-
t-class-nav-btn | \-
t-class-title | \-
### CSS Variables
The component provides the following CSS variables, which can be used to customize styles.
Name | Default Value | Description
-- | -- | --
--td-navbar-bg-color | @bg-color-container | -
--td-navbar-capsule-border-color | #e3e6ea | -
--td-navbar-capsule-border-radius | 32rpx | -
--td-navbar-capsule-height | 64rpx | -
--td-navbar-capsule-width | 176rpx | -
--td-navbar-color | @font-gray-1 | -
--td-navbar-height | 96rpx | -
--td-navbar-left-arrow-size | 48rpx | -
--td-navbar-title-font-size | 36rpx | -
--td-navbar-title-font-weight | 600 | -

View File

@@ -0,0 +1,105 @@
---
title: Navbar 导航栏
description: 用于不同页面之间切换或者跳转,位于内容区的上方,系统状态栏的下方。
spline: navigation
isComponent: true
---
<span class="coverages-badge" style="margin-right: 10px"><img src="https://img.shields.io/badge/coverages%3A%20lines-97%25-blue" /></span><span class="coverages-badge" style="margin-right: 10px"><img src="https://img.shields.io/badge/coverages%3A%20functions-87%25-blue" /></span><span class="coverages-badge" style="margin-right: 10px"><img src="https://img.shields.io/badge/coverages%3A%20statements-95%25-blue" /></span><span class="coverages-badge" style="margin-right: 10px"><img src="https://img.shields.io/badge/coverages%3A%20branches-84%25-blue" /></span>
## 引入
全局引入,在 miniprogram 根目录下的`app.json`中配置,局部引入,在需要引入的页面或组件的`index.json`中配置。
```json
"usingComponents": {
"t-navbar": "tdesign-miniprogram/navbar/navbar",
}
```
## 代码演示
<a href="https://developers.weixin.qq.com/s/REHT3emm7kS5" title="在开发者工具中预览效果" target="_blank" rel="noopener noreferrer"> 在开发者工具中预览效果 </a>
<blockquote style="background-color: #d9e1ff; font-size: 15px; line-height: 26px;margin: 16px 0 0;padding: 16px; border-radius: 6px; color: #0052d9" >
<p>Tips: 请确保开发者工具为打开状态。导入开发者工具后依次执行npm i > 构建npm包 > 勾选 "将JS编译成ES5"</p>
</blockquote>
### 基础导航栏
{{ base }}
### 胶囊样式导航栏
{{ back-home }}
### 带搜索导航栏
{{ search }}
### 带图片导航栏
{{ img }}
### 组件样式
{{ left-title }}
### 自定义颜色
{{ custom-color }}
## API
### Navbar Props
名称 | 类型 | 默认值 | 描述 | 必传
-- | -- | -- | -- | --
style | Object | - | 样式 | N
custom-style | Object | - | 样式,一般用于开启虚拟化组件节点场景 | N
animation | Boolean | true | 是否添加动画效果 | N
capsule | Slot | - | 左侧胶囊区域。[通用类型定义](https://github.com/Tencent/tdesign-miniprogram/blob/develop/src/common/common.ts) | N
delta | Number | 1 | 后退按钮后退层数,含义参考 [wx.navigateBack](https://developers.weixin.qq.com/miniprogram/dev/api/route/wx.navigateBack.html),特殊的,传入 0 不会发生执行 wx.navigateBack | N
fixed | Boolean | true | 是否固定在顶部 | N
left | Slot | - | `0.26.0`。左侧内容区域。[通用类型定义](https://github.com/Tencent/tdesign-miniprogram/blob/develop/src/common/common.ts) | N
left-arrow | Boolean | false | `0.26.0`。是否展示左侧箭头 | N
title | String / Slot | - | 页面标题。[通用类型定义](https://github.com/Tencent/tdesign-miniprogram/blob/develop/src/common/common.ts) | N
title-max-length | Number | - | 标题文字最大长度,超出的范围使用 `...` 表示 | N
visible | Boolean | true | 是否显示 | N
### Navbar Events
名称 | 参数 | 描述
-- | -- | --
complete | \- | navigateBack 执行完成后触发(失败或成功均会触发)
fail | \- | navigateBack 执行失败后触发
go-back | \- | 点击左侧箭头时触发
success | \- | navigateBack 执行成功后触发
### Navbar External Classes
类名 | 描述
-- | --
t-class | 根节点样式类
t-class-capsule | 左侧胶囊区域样式类
t-class-center | 中间内容样式类
t-class-home-icon | 首页图标样式类
t-class-left | 左侧内容样式类
t-class-left-icon | 左侧图标样式类
t-class-nav-btn | 导航按钮样式类
t-class-title | 标题样式类
### CSS Variables
组件提供了下列 CSS 变量,可用于自定义样式。
名称 | 默认值 | 描述
-- | -- | --
--td-navbar-bg-color | @bg-color-container | -
--td-navbar-capsule-border-color | #e3e6ea | -
--td-navbar-capsule-border-radius | 32rpx | -
--td-navbar-capsule-height | 64rpx | -
--td-navbar-capsule-width | 176rpx | -
--td-navbar-color | @font-gray-1 | -
--td-navbar-height | 96rpx | -
--td-navbar-left-arrow-size | 48rpx | -
--td-navbar-title-font-size | 36rpx | -
--td-navbar-title-font-weight | 600 | -

View File

@@ -0,0 +1,36 @@
import { SuperComponent } from '../common/src/index';
export default class Navbar extends SuperComponent {
externalClasses: string[];
timer: any;
options: {
multipleSlots: boolean;
};
properties: import("./type").TdNavbarProps;
observers: {
visible(this: Navbar, visible: any): void;
'title,titleMaxLength'(this: any): void;
};
data: {
prefix: string;
classPrefix: string;
boxStyle: string;
showTitle: string;
hideLeft: boolean;
hideCenter: boolean;
_menuRect: any;
_leftRect: any;
_boxStyle: {};
};
attached(): void;
detached(): void;
methods: {
initStyle(): void;
calcCenterStyle(leftRect: WechatMiniprogram.BoundingClientRectResult, menuRect: WechatMiniprogram.BoundingClientRectResult, defaultStyle: object): void;
getLeftRect(): void;
getMenuRect(): void;
onMenuButtonBoundingClientRectWeightChange(): void;
offMenuButtonBoundingClientRectWeightChange(): void;
queryElements(capsuleRect: any): void;
goBack(): void;
};
}

View File

@@ -0,0 +1,186 @@
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { SuperComponent, wxComponent } from '../common/src/index';
import { getRect, systemInfo } from '../common/utils';
import config from '../common/config';
import props from './props';
const { prefix } = config;
const name = `${prefix}-navbar`;
let Navbar = class Navbar extends SuperComponent {
constructor() {
super(...arguments);
this.externalClasses = [
`${prefix}-class`,
`${prefix}-class-placeholder`,
`${prefix}-class-content`,
`${prefix}-class-title`,
`${prefix}-class-left`,
`${prefix}-class-center`,
`${prefix}-class-left-icon`,
`${prefix}-class-home-icon`,
`${prefix}-class-capsule`,
`${prefix}-class-nav-btn`,
];
this.timer = null;
this.options = {
multipleSlots: true,
};
this.properties = props;
this.observers = {
visible(visible) {
const { animation } = this.properties;
const visibleClass = `${name}${visible ? '--visible' : '--hide'}`;
this.setData({
visibleClass: `${visibleClass}${animation ? '-animation' : ''}`,
});
if (this.timer) {
clearTimeout(this.timer);
}
if (animation) {
this.timer = setTimeout(() => {
this.setData({
visibleClass,
});
}, 300);
}
},
'title,titleMaxLength'() {
const { title } = this.properties;
const titleMaxLength = this.properties.titleMaxLength || Number.MAX_SAFE_INTEGER;
let temp = title.slice(0, titleMaxLength);
if (titleMaxLength < title.length)
temp += '...';
this.setData({
showTitle: temp,
});
},
};
this.data = {
prefix,
classPrefix: name,
boxStyle: '',
showTitle: '',
hideLeft: false,
hideCenter: false,
_menuRect: null,
_leftRect: null,
_boxStyle: {},
};
this.methods = {
initStyle() {
this.getMenuRect();
const { _menuRect, _leftRect } = this.data;
if (!_menuRect || !_leftRect || !systemInfo)
return;
const _boxStyle = {
'--td-navbar-padding-top': `${systemInfo.statusBarHeight}px`,
'--td-navbar-right': `${systemInfo.windowWidth - _menuRect.left}px`,
'--td-navbar-left-max-width': `${_menuRect.left}px`,
'--td-navbar-capsule-height': `${_menuRect.height}px`,
'--td-navbar-capsule-width': `${_menuRect.width}px`,
'--td-navbar-height': `${(_menuRect.top - systemInfo.statusBarHeight) * 2 + _menuRect.height}px`,
};
this.calcCenterStyle(_leftRect, _menuRect, _boxStyle);
},
calcCenterStyle(leftRect, menuRect, defaultStyle) {
const maxSpacing = Math.max(leftRect.right, systemInfo.windowWidth - menuRect.left);
const _boxStyle = Object.assign(Object.assign({}, defaultStyle), { '--td-navbar-center-left': `${maxSpacing}px`, '--td-navbar-center-width': `${Math.max(menuRect.left - maxSpacing, 0)}px` });
const boxStyle = Object.entries(_boxStyle)
.map(([k, v]) => `${k}: ${v}`)
.join('; ');
this.setData({
boxStyle,
_boxStyle,
});
},
getLeftRect() {
getRect(this, `.${name}__left`).then((res) => {
if (res.right > this.data._leftRect.right) {
this.calcCenterStyle(res, this.data._menuRect, this.data._boxStyle);
}
});
},
getMenuRect() {
if (wx.getMenuButtonBoundingClientRect) {
const rect = wx.getMenuButtonBoundingClientRect();
this.setData({
_menuRect: rect,
_leftRect: {
right: systemInfo.windowWidth - rect.left,
},
});
}
},
onMenuButtonBoundingClientRectWeightChange() {
if (wx.onMenuButtonBoundingClientRectWeightChange) {
wx.onMenuButtonBoundingClientRectWeightChange((res) => this.queryElements(res));
}
},
offMenuButtonBoundingClientRectWeightChange() {
if (wx.offMenuButtonBoundingClientRectWeightChange) {
wx.offMenuButtonBoundingClientRectWeightChange((res) => this.queryElements(res));
}
},
queryElements(capsuleRect) {
Promise.all([
getRect(this, `.${this.data.classPrefix}__left`),
getRect(this, `.${this.data.classPrefix}__center`),
]).then(([leftRect, centerRect]) => {
if (Math.round(leftRect.right) > capsuleRect.left) {
this.setData({
hideLeft: true,
hideCenter: true,
});
}
else if (Math.round(centerRect.right) > capsuleRect.left) {
this.setData({
hideLeft: false,
hideCenter: true,
});
}
else {
this.setData({
hideLeft: false,
hideCenter: false,
});
}
});
},
goBack() {
const { delta } = this.data;
const that = this;
this.triggerEvent('go-back');
if (delta > 0) {
wx.navigateBack({
delta,
fail(e) {
that.triggerEvent('fail', e);
},
complete(e) {
that.triggerEvent('complete', e);
},
success(e) {
that.triggerEvent('success', e);
},
});
}
},
};
}
attached() {
this.initStyle();
this.getLeftRect();
this.onMenuButtonBoundingClientRectWeightChange();
}
detached() {
this.offMenuButtonBoundingClientRectWeightChange();
}
};
Navbar = __decorate([
wxComponent()
], Navbar);
export default Navbar;

View File

@@ -0,0 +1,7 @@
{
"component": true,
"styleIsolation": "apply-shared",
"usingComponents": {
"t-icon": "../icon/icon"
}
}

View File

@@ -0,0 +1,22 @@
<wxs src="../common/utils.wxs" module="_" />
<view
class="{{_.cls(classPrefix, [['fixed', fixed]])}} {{visibleClass}} class {{prefix}}-class"
style="{{_._style([boxStyle, style, customStyle])}}"
>
<view wx:if="{{fixed}}" class="{{classPrefix}}__placeholder {{prefix}}-class-placeholder" />
<view class="{{classPrefix}}__content {{prefix}}-class-content">
<view class="{{classPrefix}}__left {{hideLeft ? classPrefix + '__left--hide' : ''}} {{prefix}}-class-left">
<view wx:if="{{leftArrow}}" class="{{classPrefix}}__btn" bind:tap="goBack" aria-role="button" aria-label="返回">
<t-icon name="chevron-left" class="{{classPrefix}}__left-arrow" />
</view>
<slot name="left" />
<view class="{{classPrefix}}__capsule {{prefix}}-class-capsule">
<slot name="capsule" />
</view>
</view>
<view class="{{classPrefix}}__center {{hideCenter ? classPrefix + '__center--hide' : ''}} {{prefix}}-class-center">
<slot name="title" />
<text wx:if="{{title}}" class="{{classPrefix}}__center-title {{prefix}}-class-title">{{showTitle}}</text>
</view>
</view>
</view>

View File

@@ -0,0 +1,136 @@
.t-float-left {
float: left;
}
.t-float-right {
float: right;
}
@keyframes tdesign-fade-out {
from {
opacity: 1;
}
to {
opacity: 0;
}
}
.hotspot-expanded.relative {
position: relative;
}
.hotspot-expanded::after {
content: '';
display: block;
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
transform: scale(1.5);
}
.t-navbar--fixed .t-navbar__content {
position: fixed;
top: 0;
left: 0;
z-index: 5001;
}
.t-navbar--visible {
display: '';
}
.t-navbar--visible-animation {
opacity: 1;
transition: opacity 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
}
.t-navbar--hide-animation {
opacity: 0;
transition: opacity 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
}
.t-navbar--hide {
display: none;
}
.t-navbar__placeholder {
height: var(--td-navbar-height, 48px);
padding-top: var(--td-navbar-padding-top, 20px);
position: relative;
visibility: hidden;
box-sizing: content-box;
}
.t-navbar__content {
position: relative;
z-index: 1;
height: var(--td-navbar-height, 48px);
width: calc(100% - var(--td-navbar-right, 95px));
padding-right: var(--td-navbar-right, 95px);
padding-top: var(--td-navbar-padding-top, 20px);
color: var(--td-navbar-color, var(--td-text-color-primary, var(--td-font-gray-1, rgba(0, 0, 0, 0.9))));
background-color: var(--td-navbar-bg-color, var(--td-bg-color-container, var(--td-font-white-1, #ffffff)));
display: flex;
align-items: center;
box-sizing: content-box;
}
.t-navbar__left {
position: relative;
box-sizing: border-box;
max-width: var(--td-navbar-left-max-width);
overflow: hidden;
display: flex;
align-items: center;
margin-left: var(--td-spacer-1, 24rpx);
transition: opacity 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
}
.t-navbar__left-arrow {
font-size: var(--td-navbar-left-arrow-size, 24px);
}
.t-navbar__left--hide {
opacity: 0;
}
.t-navbar__capsule {
box-sizing: border-box;
width: var(--td-navbar-capsule-width, 88px);
height: var(--td-navbar-capsule-height, 32px);
display: flex;
align-items: center;
}
.t-navbar__capsule::before {
content: '';
position: absolute;
z-index: -1;
top: 0;
left: 0;
width: 200%;
height: 200%;
transform: scale(0.5);
transform-origin: 0 0;
box-sizing: border-box;
border-radius: calc(var(--td-navbar-capsule-border-radius, 16px) * 2);
border: 2rpx solid var(--td-navbar-capsule-border-color, var(--td-border-level-1-color, var(--td-gray-color-3, #e7e7e7)));
}
.t-navbar__capsule:empty {
display: none;
}
.t-navbar__center {
font-size: 18px;
text-align: center;
position: absolute;
bottom: 0;
left: var(--td-navbar-center-left, var(--td-navbar-right, 95px));
width: var(--td-navbar-center-width);
height: var(--td-navbar-height, 48px);
line-height: var(--td-navbar-height, 48px);
flex: 1;
display: flex;
align-items: center;
justify-content: center;
overflow: hidden;
transition: opacity 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
}
.t-navbar__center:empty {
display: none;
}
.t-navbar__center-title {
font-size: var(--td-navbar-title-font-size, 18px);
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
font-weight: var(--td-navbar-title-font-weight, 600);
}
.t-navbar__center--hide {
opacity: 0;
}

View File

@@ -0,0 +1,3 @@
import { TdNavbarProps } from './type';
declare const props: TdNavbarProps;
export default props;

View File

@@ -0,0 +1,29 @@
const props = {
animation: {
type: Boolean,
value: true,
},
delta: {
type: Number,
value: 1,
},
fixed: {
type: Boolean,
value: true,
},
leftArrow: {
type: Boolean,
value: false,
},
title: {
type: String,
},
titleMaxLength: {
type: Number,
},
visible: {
type: Boolean,
value: true,
},
};
export default props;

View File

@@ -0,0 +1,30 @@
export interface TdNavbarProps {
animation?: {
type: BooleanConstructor;
value?: boolean;
};
delta?: {
type: NumberConstructor;
value?: number;
};
fixed?: {
type: BooleanConstructor;
value?: boolean;
};
leftArrow?: {
type: BooleanConstructor;
value?: boolean;
};
title?: {
type: StringConstructor;
value?: string;
};
titleMaxLength?: {
type: NumberConstructor;
value?: number;
};
visible?: {
type: BooleanConstructor;
value?: boolean;
};
}

View File

@@ -0,0 +1 @@
export {};