feat: 提交模板代码
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
[*.{js,jsx,mjs,cjs,ts,tsx,mts,cts,vue,css,scss,sass,less,styl}]
|
||||
charset = utf-8
|
||||
indent_size = 2
|
||||
indent_style = space
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
end_of_line = lf
|
||||
max_line_length = 100
|
||||
@@ -0,0 +1 @@
|
||||
* text=auto eol=lf
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
# Dependencies
|
||||
node_modules
|
||||
|
||||
# Build outputs
|
||||
dist
|
||||
dist-ssr
|
||||
coverage
|
||||
*.local
|
||||
|
||||
# TypeScript
|
||||
*.tsbuildinfo
|
||||
|
||||
# ESLint
|
||||
.eslintcache
|
||||
|
||||
# OS
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
|
||||
# WeChat MiniProgram
|
||||
# npm 构建产物(通过微信开发者工具构建 npm 后生成)
|
||||
miniprogram/miniprogram_npm/
|
||||
|
||||
# 微信开发者工具私有配置文件(包含个人开发环境配置)
|
||||
project.private.config.json
|
||||
|
||||
# 微信开发者工具临时文件
|
||||
*.wxapkg
|
||||
*.wxss.map
|
||||
*.wxml.map
|
||||
*.js.map
|
||||
|
||||
# Testing
|
||||
# Cypress
|
||||
/cypress/videos/
|
||||
/cypress/screenshots/
|
||||
|
||||
# Vitest
|
||||
__screenshots__/
|
||||
@@ -0,0 +1,5 @@
|
||||
# 设置包注册表镜像
|
||||
registry=https://registry.npmmirror.com/
|
||||
|
||||
# 设置 node-sass 二进制包的镜像(非常重要,能解决很多安装失败问题)
|
||||
sass_binary_site=https://npmmirror.com/mirrors/node-sass/
|
||||
@@ -0,0 +1,12 @@
|
||||
# 依赖目录
|
||||
node_modules/
|
||||
miniprogram_npm/
|
||||
|
||||
# 构建产物
|
||||
dist/
|
||||
coverage/
|
||||
|
||||
# 其他
|
||||
*.log
|
||||
.DS_Store
|
||||
package-lock.json
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/prettierrc",
|
||||
"semi": false,
|
||||
"singleQuote": true,
|
||||
"printWidth": 100,
|
||||
"overrides": [
|
||||
{
|
||||
"files": "*.wxml",
|
||||
"options": {
|
||||
"parser": "html"
|
||||
}
|
||||
},
|
||||
{
|
||||
"files": "*.wxss",
|
||||
"options": {
|
||||
"parser": "css"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
import eslint from '@eslint/js'
|
||||
import tseslint from 'typescript-eslint'
|
||||
import prettierConfig from 'eslint-config-prettier'
|
||||
import prettierPlugin from 'eslint-plugin-prettier'
|
||||
|
||||
export default tseslint.config(
|
||||
// 全局忽略的文件和目录
|
||||
{
|
||||
ignores: [
|
||||
'**/node_modules/**',
|
||||
'**/miniprogram_npm/**',
|
||||
'**/dist/**',
|
||||
'**/coverage/**',
|
||||
'**/*.js.map',
|
||||
'**/typings/**',
|
||||
'**/*.d.ts',
|
||||
],
|
||||
},
|
||||
|
||||
// ESLint 推荐规则
|
||||
eslint.configs.recommended,
|
||||
|
||||
// TypeScript ESLint 推荐规则
|
||||
...tseslint.configs.recommended,
|
||||
|
||||
// 项目特定配置
|
||||
{
|
||||
files: ['**/*.ts'],
|
||||
languageOptions: {
|
||||
parser: tseslint.parser,
|
||||
parserOptions: {
|
||||
ecmaVersion: 'latest',
|
||||
sourceType: 'module',
|
||||
project: './tsconfig.json',
|
||||
},
|
||||
},
|
||||
plugins: {
|
||||
'@typescript-eslint': tseslint.plugin,
|
||||
prettier: prettierPlugin,
|
||||
},
|
||||
rules: {
|
||||
// Prettier 集成
|
||||
'prettier/prettier': 'error',
|
||||
|
||||
// TypeScript 规则调整(根据小程序特点)
|
||||
'@typescript-eslint/no-explicit-any': 'warn',
|
||||
'@typescript-eslint/no-unused-vars': [
|
||||
'error',
|
||||
{
|
||||
argsIgnorePattern: '^_',
|
||||
varsIgnorePattern: '^_',
|
||||
},
|
||||
],
|
||||
|
||||
// 通用规则
|
||||
'no-console': ['warn', { allow: ['warn', 'error'] }],
|
||||
'no-debugger': 'warn',
|
||||
},
|
||||
},
|
||||
|
||||
// Prettier 配置(禁用与 Prettier 冲突的规则)
|
||||
prettierConfig,
|
||||
)
|
||||
@@ -0,0 +1,31 @@
|
||||
import request from '../utils/request'
|
||||
import { StandardResponse } from './types'
|
||||
|
||||
/**
|
||||
* 登录接口请求参数类型
|
||||
*/
|
||||
export interface LoginParams {
|
||||
userName: string
|
||||
password: string
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户信息数据类型
|
||||
*/
|
||||
export interface UserInfoData {
|
||||
id: number
|
||||
username: string
|
||||
nickname: string
|
||||
avatar: string
|
||||
email: string
|
||||
phone: string
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录接口
|
||||
* @param params 登录参数
|
||||
* @returns 返回标准响应格式的登录数据
|
||||
*/
|
||||
export const loginReq = (params: LoginParams) => {
|
||||
return request.post<StandardResponse<UserInfoData>>('/wechatLogin/wechatLogin.action', params)
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* 标准响应数据格式
|
||||
*/
|
||||
export interface StandardResponse<T = unknown> {
|
||||
code: number
|
||||
data: T
|
||||
message: string
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"pages": ["pages/date/date", "pages/login/login", "pages/index/index"],
|
||||
"window": {
|
||||
"navigationStyle": "default",
|
||||
"navigationBarTextStyle": "black",
|
||||
"navigationBarBackgroundColor": "#ffffff",
|
||||
"navigationBarTitleText": "My Weapp Template"
|
||||
},
|
||||
"style": "v2",
|
||||
"renderer": "webview",
|
||||
"componentFramework": "glass-easel",
|
||||
"sitemapLocation": "sitemap.json",
|
||||
"lazyCodeLoading": "requiredComponents"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/**app.wxss**/
|
||||
page,
|
||||
view,
|
||||
scroll-view,
|
||||
image,
|
||||
text {
|
||||
box-sizing: border-box;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.container {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// app.ts
|
||||
App<IAppOption>({
|
||||
globalData: {},
|
||||
onLaunch() {},
|
||||
})
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"usingComponents": {}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/* pages/date/date.wxss */
|
||||
.container {
|
||||
padding: 20rpx;
|
||||
background-color: #f5f5f5;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.header {
|
||||
margin-bottom: 30rpx;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.title {
|
||||
font-size: 36rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.section {
|
||||
width: 100%;
|
||||
background-color: #fff;
|
||||
border-radius: 16rpx;
|
||||
padding: 30rpx;
|
||||
margin-bottom: 30rpx;
|
||||
box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 32rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
margin-bottom: 10rpx;
|
||||
}
|
||||
|
||||
.section-desc {
|
||||
font-size: 24rpx;
|
||||
color: #666;
|
||||
margin-bottom: 20rpx;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.example-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 24rpx;
|
||||
}
|
||||
|
||||
.example-item {
|
||||
padding: 20rpx;
|
||||
background-color: #f9f9f9;
|
||||
border-radius: 12rpx;
|
||||
border-left: 4rpx solid #1890ff;
|
||||
}
|
||||
|
||||
.example-label {
|
||||
font-size: 28rpx;
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
margin-bottom: 8rpx;
|
||||
}
|
||||
|
||||
.example-format {
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
margin-bottom: 12rpx;
|
||||
font-family: 'Courier New', monospace;
|
||||
}
|
||||
|
||||
.example-value {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 16rpx;
|
||||
}
|
||||
|
||||
.result-text {
|
||||
flex: 1;
|
||||
font-size: 26rpx;
|
||||
color: #1890ff;
|
||||
word-break: break-all;
|
||||
font-family: 'Courier New', monospace;
|
||||
}
|
||||
|
||||
.copy-btn {
|
||||
padding: 8rpx 20rpx;
|
||||
background-color: #1890ff;
|
||||
color: #fff;
|
||||
font-size: 24rpx;
|
||||
border-radius: 8rpx;
|
||||
white-space: nowrap;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.copy-btn:active {
|
||||
background-color: #40a9ff;
|
||||
opacity: 0.8;
|
||||
}
|
||||
@@ -0,0 +1,204 @@
|
||||
// pages/date/date.ts
|
||||
import { formatTime, formatDateTime } from '../../utils/util'
|
||||
|
||||
Page({
|
||||
/**
|
||||
* 页面的初始数据
|
||||
*/
|
||||
data: {
|
||||
// formatTime 示例
|
||||
formatTimeExamples: [] as Array<{ label: string; value: string }>,
|
||||
// formatDateTime 示例 - 不同格式模板
|
||||
formatDateTimeExamples: [] as Array<{ label: string; format: string; value: string }>,
|
||||
// formatDateTime 示例 - 不同输入类型
|
||||
inputTypeExamples: [] as Array<{ label: string; input: string; value: string }>,
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面加载
|
||||
*/
|
||||
onLoad() {
|
||||
this.initExamples()
|
||||
},
|
||||
|
||||
/**
|
||||
* 初始化所有示例数据
|
||||
*/
|
||||
initExamples() {
|
||||
const now = new Date()
|
||||
const timestamp = now.getTime()
|
||||
const dateString = '2024-01-15 14:30:45'
|
||||
const chineseDateString = '2024年1月15日'
|
||||
|
||||
// formatTime 示例
|
||||
const formatTimeExamples = [
|
||||
{
|
||||
label: '当前时间',
|
||||
value: formatTime(now),
|
||||
},
|
||||
{
|
||||
label: '指定日期',
|
||||
value: formatTime(new Date(2024, 0, 15, 14, 30, 45)),
|
||||
},
|
||||
{
|
||||
label: '昨天',
|
||||
value: formatTime(new Date(timestamp - 24 * 60 * 60 * 1000)),
|
||||
},
|
||||
{
|
||||
label: '明天',
|
||||
value: formatTime(new Date(timestamp + 24 * 60 * 60 * 1000)),
|
||||
},
|
||||
]
|
||||
|
||||
// formatDateTime 示例 - 不同格式模板
|
||||
const formatDateTimeExamples = [
|
||||
{
|
||||
label: '默认格式(YYYY/MM/DD HH:mm:ss)',
|
||||
format: 'YYYY/MM/DD HH:mm:ss',
|
||||
value: formatDateTime(now),
|
||||
},
|
||||
{
|
||||
label: '中文日期格式',
|
||||
format: 'YYYY年MM月DD日 HH:mm:ss',
|
||||
value: formatDateTime(now, 'YYYY年MM月DD日 HH:mm:ss'),
|
||||
},
|
||||
{
|
||||
label: '短日期格式',
|
||||
format: 'YY/MM/DD',
|
||||
value: formatDateTime(now, 'YY/MM/DD'),
|
||||
},
|
||||
{
|
||||
label: '12小时制格式',
|
||||
format: 'YYYY-MM-DD hh:mm:ss A',
|
||||
value: formatDateTime(now, 'YYYY-MM-DD hh:mm:ss A'),
|
||||
},
|
||||
{
|
||||
label: '24小时制格式',
|
||||
format: 'YYYY-MM-DD HH:mm:ss',
|
||||
value: formatDateTime(now, 'YYYY-MM-DD HH:mm:ss'),
|
||||
},
|
||||
{
|
||||
label: '仅日期',
|
||||
format: 'YYYY-MM-DD',
|
||||
value: formatDateTime(now, 'YYYY-MM-DD'),
|
||||
},
|
||||
{
|
||||
label: '仅时间',
|
||||
format: 'HH:mm:ss',
|
||||
value: formatDateTime(now, 'HH:mm:ss'),
|
||||
},
|
||||
{
|
||||
label: '带毫秒',
|
||||
format: 'YYYY-MM-DD HH:mm:ss.SSS',
|
||||
value: formatDateTime(now, 'YYYY-MM-DD HH:mm:ss.SSS'),
|
||||
},
|
||||
{
|
||||
label: '美式日期格式',
|
||||
format: 'MM/DD/YYYY',
|
||||
value: formatDateTime(now, 'MM/DD/YYYY'),
|
||||
},
|
||||
{
|
||||
label: '完整中文格式',
|
||||
format: 'YYYY年MM月DD日 HH时mm分ss秒',
|
||||
value: formatDateTime(now, 'YYYY年MM月DD日 HH时mm分ss秒'),
|
||||
},
|
||||
]
|
||||
|
||||
// formatDateTime 示例 - 不同输入类型
|
||||
const inputTypeExamples = [
|
||||
{
|
||||
label: 'Date 对象',
|
||||
input: 'new Date()',
|
||||
value: formatDateTime(now),
|
||||
},
|
||||
{
|
||||
label: '时间戳(数字)',
|
||||
input: `${timestamp}`,
|
||||
value: formatDateTime(timestamp),
|
||||
},
|
||||
{
|
||||
label: '日期字符串(标准格式)',
|
||||
input: dateString,
|
||||
value: formatDateTime(dateString),
|
||||
},
|
||||
{
|
||||
label: '中文日期字符串',
|
||||
input: chineseDateString,
|
||||
value: formatDateTime(chineseDateString),
|
||||
},
|
||||
{
|
||||
label: '仅年份字符串',
|
||||
input: '2024',
|
||||
value: formatDateTime('2024'),
|
||||
},
|
||||
{
|
||||
label: '年月字符串',
|
||||
input: '2024/01',
|
||||
value: formatDateTime('2024/01'),
|
||||
},
|
||||
]
|
||||
|
||||
this.setData({
|
||||
formatTimeExamples,
|
||||
formatDateTimeExamples,
|
||||
inputTypeExamples,
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面初次渲染完成
|
||||
*/
|
||||
onReady() {},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面显示
|
||||
*/
|
||||
onShow() {},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面隐藏
|
||||
*/
|
||||
onHide() {},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面卸载
|
||||
*/
|
||||
onUnload() {},
|
||||
|
||||
/**
|
||||
* 页面相关事件处理函数--监听用户下拉动作
|
||||
*/
|
||||
onPullDownRefresh() {},
|
||||
|
||||
/**
|
||||
* 页面上拉触底事件的处理函数
|
||||
*/
|
||||
onReachBottom() {},
|
||||
|
||||
/**
|
||||
* 用户点击右上角分享
|
||||
*/
|
||||
onShareAppMessage() {},
|
||||
|
||||
/**
|
||||
* 复制文本到剪贴板
|
||||
*/
|
||||
copyText(e: WechatMiniprogram.Touch) {
|
||||
const { text } = e.currentTarget.dataset
|
||||
if (!text) {
|
||||
return
|
||||
}
|
||||
|
||||
wx.setClipboardData({
|
||||
data: text,
|
||||
success: () => {
|
||||
wx.showToast({
|
||||
title: '复制成功',
|
||||
icon: 'success',
|
||||
}).catch(() => {
|
||||
console.error('showToast error')
|
||||
})
|
||||
},
|
||||
})
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,74 @@
|
||||
<!--pages/date/date.wxml-->
|
||||
<view class="container">
|
||||
<view class="header">
|
||||
<text class="title">日期时间格式化示例</text>
|
||||
</view>
|
||||
|
||||
<!-- formatTime 函数示例 -->
|
||||
<view class="section">
|
||||
<view class="section-title">formatTime 函数示例</view>
|
||||
<view class="section-desc">固定格式:YYYY/MM/DD HH:mm:ss</view>
|
||||
<view class="example-list">
|
||||
<view class="example-item" wx:for="{{formatTimeExamples}}" wx:key="label">
|
||||
<view class="example-label">{{item.label}}:</view>
|
||||
<view class="example-value">
|
||||
<text class="result-text" selectable="{{true}}">{{item.value}}</text>
|
||||
<text
|
||||
class="copy-btn"
|
||||
data-text="{{item.value}}"
|
||||
bindtap="copyText"
|
||||
wx:if="{{item.value}}"
|
||||
>
|
||||
复制
|
||||
</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- formatDateTime 函数示例 - 不同格式模板 -->
|
||||
<view class="section">
|
||||
<view class="section-title">formatDateTime 函数示例 - 不同格式模板</view>
|
||||
<view class="section-desc">支持自定义格式模板,灵活配置日期时间显示格式</view>
|
||||
<view class="example-list">
|
||||
<view class="example-item" wx:for="{{formatDateTimeExamples}}" wx:key="label">
|
||||
<view class="example-label">{{item.label}}</view>
|
||||
<view class="example-format">格式模板:{{item.format}}</view>
|
||||
<view class="example-value">
|
||||
<text class="result-text" selectable="{{true}}">{{item.value}}</text>
|
||||
<text
|
||||
class="copy-btn"
|
||||
data-text="{{item.value}}"
|
||||
bindtap="copyText"
|
||||
wx:if="{{item.value}}"
|
||||
>
|
||||
复制
|
||||
</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- formatDateTime 函数示例 - 不同输入类型 -->
|
||||
<view class="section">
|
||||
<view class="section-title">formatDateTime 函数示例 - 不同输入类型</view>
|
||||
<view class="section-desc">支持 Date 对象、时间戳、日期字符串等多种输入类型</view>
|
||||
<view class="example-list">
|
||||
<view class="example-item" wx:for="{{inputTypeExamples}}" wx:key="label">
|
||||
<view class="example-label">{{item.label}}</view>
|
||||
<view class="example-format">输入:{{item.input}}</view>
|
||||
<view class="example-value">
|
||||
<text class="result-text" selectable="{{true}}">{{item.value}}</text>
|
||||
<text
|
||||
class="copy-btn"
|
||||
data-text="{{item.value}}"
|
||||
bindtap="copyText"
|
||||
wx:if="{{item.value}}"
|
||||
>
|
||||
复制
|
||||
</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"usingComponents": {}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
/* pages/index.wxss */
|
||||
.container {
|
||||
padding: 40rpx;
|
||||
background-color: #f5f5f5;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.header {
|
||||
text-align: center;
|
||||
margin-bottom: 40rpx;
|
||||
}
|
||||
|
||||
.title {
|
||||
font-size: 36rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.section {
|
||||
width: 100%;
|
||||
background-color: #fff;
|
||||
border-radius: 16rpx;
|
||||
padding: 30rpx;
|
||||
margin-bottom: 30rpx;
|
||||
box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 32rpx;
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
margin-bottom: 24rpx;
|
||||
padding-bottom: 16rpx;
|
||||
border-bottom: 2rpx solid #eee;
|
||||
}
|
||||
|
||||
.input-textarea {
|
||||
width: 100%;
|
||||
min-height: 200rpx;
|
||||
padding: 20rpx;
|
||||
border: 2rpx solid #e0e0e0;
|
||||
border-radius: 8rpx;
|
||||
font-size: 28rpx;
|
||||
background-color: #fafafa;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.action-bar {
|
||||
display: flex;
|
||||
gap: 20rpx;
|
||||
margin-bottom: 24rpx;
|
||||
}
|
||||
|
||||
.btn {
|
||||
flex: 1;
|
||||
border-radius: 8rpx;
|
||||
font-size: 28rpx;
|
||||
border: none;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background-color: #07c160;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.btn-primary:active {
|
||||
background-color: #06ad56;
|
||||
}
|
||||
|
||||
.btn-secondary {
|
||||
background-color: #576b95;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.btn-secondary:active {
|
||||
background-color: #4a5d84;
|
||||
}
|
||||
|
||||
.result-box {
|
||||
margin-bottom: 24rpx;
|
||||
padding: 20rpx;
|
||||
background-color: #fafafa;
|
||||
border-radius: 8rpx;
|
||||
border: 2rpx solid #e0e0e0;
|
||||
}
|
||||
|
||||
.result-label {
|
||||
font-size: 24rpx;
|
||||
color: #666;
|
||||
margin-bottom: 12rpx;
|
||||
}
|
||||
|
||||
.result-content {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 16rpx;
|
||||
}
|
||||
|
||||
.result-text {
|
||||
flex: 1;
|
||||
font-size: 26rpx;
|
||||
color: #333;
|
||||
word-break: break-all;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.copy-btn {
|
||||
padding: 8rpx 20rpx;
|
||||
background-color: #07c160;
|
||||
color: #fff;
|
||||
font-size: 24rpx;
|
||||
border-radius: 6rpx;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.copy-btn:active {
|
||||
background-color: #06ad56;
|
||||
}
|
||||
|
||||
.error-box {
|
||||
margin-top: 30rpx;
|
||||
padding: 20rpx;
|
||||
background-color: #fff3cd;
|
||||
border: 2rpx solid #ffc107;
|
||||
border-radius: 8rpx;
|
||||
}
|
||||
|
||||
.error-text {
|
||||
font-size: 26rpx;
|
||||
color: #856404;
|
||||
line-height: 1.6;
|
||||
}
|
||||
@@ -0,0 +1,301 @@
|
||||
// pages/index.ts
|
||||
import { Encrypt, Decrypt, BASE64Encrypt, BASE64Decrypt, AESError } from '../../utils/aes'
|
||||
|
||||
Page({
|
||||
/**
|
||||
* 页面的初始数据
|
||||
*/
|
||||
data: {
|
||||
// 输入原文
|
||||
plainText: 'Hello, 小程序 AES 加密示例!',
|
||||
// 标准 Base64 加密结果
|
||||
encryptedText: '',
|
||||
// 标准 Base64 解密结果
|
||||
decryptedText: '',
|
||||
// URL Safe Base64 加密结果
|
||||
base64EncryptedText: '',
|
||||
// URL Safe Base64 解密结果
|
||||
base64DecryptedText: '',
|
||||
// 错误信息
|
||||
errorMessage: '',
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面加载
|
||||
*/
|
||||
onLoad() {
|
||||
// 页面加载时自动执行一次加密解密示例
|
||||
this.handleEncrypt()
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面初次渲染完成
|
||||
*/
|
||||
onReady() {},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面显示
|
||||
*/
|
||||
onShow() {},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面隐藏
|
||||
*/
|
||||
onHide() {},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面卸载
|
||||
*/
|
||||
onUnload() {},
|
||||
|
||||
/**
|
||||
* 页面相关事件处理函数--监听用户下拉动作
|
||||
*/
|
||||
onPullDownRefresh() {},
|
||||
|
||||
/**
|
||||
* 页面上拉触底事件的处理函数
|
||||
*/
|
||||
onReachBottom() {},
|
||||
|
||||
/**
|
||||
* 用户点击右上角分享
|
||||
*/
|
||||
onShareAppMessage() {},
|
||||
|
||||
/**
|
||||
* 输入原文变化
|
||||
*/
|
||||
onPlainTextInput(e: WechatMiniprogram.Input) {
|
||||
this.setData({
|
||||
plainText: e.detail.value,
|
||||
errorMessage: '',
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 执行标准 Base64 加密
|
||||
*/
|
||||
handleEncrypt() {
|
||||
try {
|
||||
const { plainText } = this.data
|
||||
if (!plainText.trim()) {
|
||||
wx.showToast({
|
||||
title: '请输入要加密的内容',
|
||||
icon: 'none',
|
||||
}).catch(() => {
|
||||
console.error('showToast error')
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 执行加密
|
||||
const encrypted = Encrypt(plainText)
|
||||
this.setData({
|
||||
encryptedText: encrypted,
|
||||
errorMessage: '',
|
||||
})
|
||||
|
||||
wx.showToast({
|
||||
title: '加密成功',
|
||||
icon: 'success',
|
||||
}).catch(() => {
|
||||
console.error('showToast error')
|
||||
})
|
||||
} catch (error) {
|
||||
const errorMsg = error instanceof AESError ? error.message : '加密失败'
|
||||
this.setData({
|
||||
errorMessage: errorMsg,
|
||||
})
|
||||
wx.showToast({
|
||||
title: errorMsg,
|
||||
icon: 'none',
|
||||
duration: 2000,
|
||||
}).catch(() => {
|
||||
console.error('showToast error')
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 执行标准 Base64 解密
|
||||
*/
|
||||
handleDecrypt() {
|
||||
try {
|
||||
const { encryptedText } = this.data
|
||||
if (!encryptedText.trim()) {
|
||||
wx.showToast({
|
||||
title: '请输入要解密的内容',
|
||||
icon: 'none',
|
||||
}).catch(() => {
|
||||
console.error('showToast error')
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 执行解密
|
||||
const decrypted = Decrypt(encryptedText)
|
||||
if (decrypted === null) {
|
||||
this.setData({
|
||||
errorMessage: '解密失败:密钥不匹配或密文被篡改',
|
||||
})
|
||||
wx.showToast({
|
||||
title: '解密失败',
|
||||
icon: 'none',
|
||||
duration: 2000,
|
||||
}).catch(() => {
|
||||
console.error('showToast error')
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
this.setData({
|
||||
decryptedText: decrypted,
|
||||
errorMessage: '',
|
||||
})
|
||||
|
||||
wx.showToast({
|
||||
title: '解密成功',
|
||||
icon: 'success',
|
||||
}).catch(() => {
|
||||
console.error('showToast error')
|
||||
})
|
||||
} catch (error) {
|
||||
const errorMsg = error instanceof AESError ? error.message : '解密失败'
|
||||
this.setData({
|
||||
errorMessage: errorMsg,
|
||||
})
|
||||
wx.showToast({
|
||||
title: errorMsg,
|
||||
icon: 'none',
|
||||
duration: 2000,
|
||||
}).catch(() => {
|
||||
console.error('showToast error')
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 执行 URL Safe Base64 加密
|
||||
*/
|
||||
handleBase64Encrypt() {
|
||||
try {
|
||||
const { plainText } = this.data
|
||||
if (!plainText.trim()) {
|
||||
wx.showToast({
|
||||
title: '请输入要加密的内容',
|
||||
icon: 'none',
|
||||
}).catch(() => {
|
||||
console.error('showToast error')
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 执行 URL Safe Base64 加密
|
||||
const encrypted = BASE64Encrypt(plainText)
|
||||
this.setData({
|
||||
base64EncryptedText: encrypted,
|
||||
errorMessage: '',
|
||||
})
|
||||
|
||||
wx.showToast({
|
||||
title: '加密成功',
|
||||
icon: 'success',
|
||||
}).catch(() => {
|
||||
console.error('showToast error')
|
||||
})
|
||||
} catch (error) {
|
||||
const errorMsg = error instanceof AESError ? error.message : '加密失败'
|
||||
this.setData({
|
||||
errorMessage: errorMsg,
|
||||
})
|
||||
wx.showToast({
|
||||
title: errorMsg,
|
||||
icon: 'none',
|
||||
duration: 2000,
|
||||
}).catch(() => {
|
||||
console.error('showToast error')
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 执行 URL Safe Base64 解密
|
||||
*/
|
||||
handleBase64Decrypt() {
|
||||
try {
|
||||
const { base64EncryptedText } = this.data
|
||||
if (!base64EncryptedText.trim()) {
|
||||
wx.showToast({
|
||||
title: '请输入要解密的内容',
|
||||
icon: 'none',
|
||||
}).catch(() => {
|
||||
console.error('showToast error')
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 执行 URL Safe Base64 解密
|
||||
const decrypted = BASE64Decrypt(base64EncryptedText)
|
||||
if (decrypted === null) {
|
||||
this.setData({
|
||||
errorMessage: '解密失败:密钥不匹配或密文被篡改',
|
||||
})
|
||||
wx.showToast({
|
||||
title: '解密失败',
|
||||
icon: 'none',
|
||||
duration: 2000,
|
||||
}).catch(() => {
|
||||
console.error('showToast error')
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
this.setData({
|
||||
base64DecryptedText: decrypted,
|
||||
errorMessage: '',
|
||||
})
|
||||
|
||||
wx.showToast({
|
||||
title: '解密成功',
|
||||
icon: 'success',
|
||||
}).catch(() => {
|
||||
console.error('showToast error')
|
||||
})
|
||||
} catch (error) {
|
||||
const errorMsg = error instanceof AESError ? error.message : '解密失败'
|
||||
this.setData({
|
||||
errorMessage: errorMsg,
|
||||
})
|
||||
wx.showToast({
|
||||
title: errorMsg,
|
||||
icon: 'none',
|
||||
duration: 2000,
|
||||
}).catch(() => {
|
||||
console.error('showToast error')
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 复制文本到剪贴板
|
||||
*/
|
||||
copyText(e: WechatMiniprogram.Touch) {
|
||||
const { text } = e.currentTarget.dataset
|
||||
if (!text) {
|
||||
return
|
||||
}
|
||||
|
||||
wx.setClipboardData({
|
||||
data: text,
|
||||
success: () => {
|
||||
wx.showToast({
|
||||
title: '复制成功',
|
||||
icon: 'success',
|
||||
}).catch(() => {
|
||||
console.error('showToast error')
|
||||
})
|
||||
},
|
||||
})
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,104 @@
|
||||
<!--pages/index.wxml-->
|
||||
<view class="container">
|
||||
<view class="header">
|
||||
<text class="title">AES 加密解密示例</text>
|
||||
</view>
|
||||
|
||||
<!-- 原文输入区域 -->
|
||||
<view class="section">
|
||||
<view class="section-title">原文输入</view>
|
||||
<textarea
|
||||
class="input-textarea"
|
||||
value="{{plainText}}"
|
||||
placeholder="请输入要加密的内容"
|
||||
bindinput="onPlainTextInput"
|
||||
maxlength="500"
|
||||
show-confirm-bar="{{false}}"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<!-- 标准 Base64 加密解密 -->
|
||||
<view class="section">
|
||||
<view class="section-title">标准 Base64 加密/解密</view>
|
||||
|
||||
<view class="action-bar">
|
||||
<button class="btn btn-primary" bindtap="handleEncrypt">加密</button>
|
||||
<button class="btn btn-secondary" bindtap="handleDecrypt">解密</button>
|
||||
</view>
|
||||
|
||||
<view class="result-box">
|
||||
<view class="result-label">加密结果:</view>
|
||||
<view class="result-content">
|
||||
<text class="result-text" selectable="{{true}}">{{encryptedText || '暂无'}}</text>
|
||||
<text
|
||||
class="copy-btn"
|
||||
data-text="{{encryptedText}}"
|
||||
bindtap="copyText"
|
||||
wx:if="{{encryptedText}}"
|
||||
>
|
||||
复制
|
||||
</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="result-box">
|
||||
<view class="result-label">解密结果:</view>
|
||||
<view class="result-content">
|
||||
<text class="result-text" selectable="{{true}}">{{decryptedText || '暂无'}}</text>
|
||||
<text
|
||||
class="copy-btn"
|
||||
data-text="{{decryptedText}}"
|
||||
bindtap="copyText"
|
||||
wx:if="{{decryptedText}}"
|
||||
>
|
||||
复制
|
||||
</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- URL Safe Base64 加密解密 -->
|
||||
<view class="section">
|
||||
<view class="section-title">URL Safe Base64 加密/解密</view>
|
||||
|
||||
<view class="action-bar">
|
||||
<button class="btn btn-primary" bindtap="handleBase64Encrypt">加密</button>
|
||||
<button class="btn btn-secondary" bindtap="handleBase64Decrypt">解密</button>
|
||||
</view>
|
||||
|
||||
<view class="result-box">
|
||||
<view class="result-label">加密结果:</view>
|
||||
<view class="result-content">
|
||||
<text class="result-text" selectable="{{true}}">{{base64EncryptedText || '暂无'}}</text>
|
||||
<text
|
||||
class="copy-btn"
|
||||
data-text="{{base64EncryptedText}}"
|
||||
bindtap="copyText"
|
||||
wx:if="{{base64EncryptedText}}"
|
||||
>
|
||||
复制
|
||||
</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="result-box">
|
||||
<view class="result-label">解密结果:</view>
|
||||
<view class="result-content">
|
||||
<text class="result-text" selectable="{{true}}">{{base64DecryptedText || '暂无'}}</text>
|
||||
<text
|
||||
class="copy-btn"
|
||||
data-text="{{base64DecryptedText}}"
|
||||
bindtap="copyText"
|
||||
wx:if="{{base64DecryptedText}}"
|
||||
>
|
||||
复制
|
||||
</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 错误信息显示 -->
|
||||
<view class="error-box" wx:if="{{errorMessage}}">
|
||||
<text class="error-text">{{errorMessage}}</text>
|
||||
</view>
|
||||
</view>
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"navigationBarTitleText": "Request 使用示例",
|
||||
"navigationBarBackgroundColor": "#FFFFFF",
|
||||
"navigationBarTextStyle": "black",
|
||||
"usingComponents": {
|
||||
"t-input": "/miniprogram_npm/tdesign-miniprogram/input/input",
|
||||
"t-button": "/miniprogram_npm/tdesign-miniprogram/button/button"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
/* pages/login/login.wxss */
|
||||
|
||||
// 容器样式
|
||||
.login-container {
|
||||
min-height: 100vh;
|
||||
background: white;
|
||||
padding: 40rpx 30rpx;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
// 头部标题区域
|
||||
.header {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
margin-bottom: 60rpx;
|
||||
|
||||
.title {
|
||||
font-size: 48rpx;
|
||||
font-weight: bold;
|
||||
color: #333333;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.subtitle {
|
||||
font-size: 28rpx;
|
||||
color: rgba(0, 0, 0, 0.8);
|
||||
}
|
||||
}
|
||||
|
||||
// 功能区块样式
|
||||
.form-section {
|
||||
background: #ffffff;
|
||||
border-radius: 20rpx;
|
||||
padding: 40rpx 30rpx;
|
||||
margin-bottom: 30rpx;
|
||||
box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.1);
|
||||
|
||||
.section-title {
|
||||
font-size: 32rpx;
|
||||
font-weight: bold;
|
||||
color: #333333;
|
||||
margin-bottom: 30rpx;
|
||||
padding-bottom: 20rpx;
|
||||
border-bottom: 2rpx solid #f0f0f0;
|
||||
}
|
||||
|
||||
// 输入框样式
|
||||
.input-item {
|
||||
margin-bottom: 25rpx;
|
||||
}
|
||||
|
||||
// 按钮组样式
|
||||
.button-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 20rpx;
|
||||
margin-top: 20rpx;
|
||||
}
|
||||
|
||||
// 信息展示框
|
||||
.info-box {
|
||||
margin-top: 30rpx;
|
||||
padding: 20rpx;
|
||||
background: #f8f9fa;
|
||||
border-radius: 12rpx;
|
||||
border-left: 6rpx solid #0052d9;
|
||||
|
||||
&.success {
|
||||
background: #e8f5e9;
|
||||
border-left-color: #4caf50;
|
||||
}
|
||||
|
||||
.info-text {
|
||||
font-size: 24rpx;
|
||||
color: #666666;
|
||||
word-break: break-all;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
}
|
||||
|
||||
// 头像区域
|
||||
.avatar-section {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
margin-bottom: 30rpx;
|
||||
|
||||
.avatar-preview {
|
||||
width: 200rpx;
|
||||
height: 200rpx;
|
||||
border-radius: 100rpx;
|
||||
border: 4rpx solid #0052d9;
|
||||
}
|
||||
|
||||
.avatar-placeholder {
|
||||
width: 200rpx;
|
||||
height: 200rpx;
|
||||
border-radius: 100rpx;
|
||||
border: 4rpx dashed #cccccc;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: #f8f9fa;
|
||||
|
||||
text {
|
||||
font-size: 24rpx;
|
||||
color: #999999;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 文档说明区域
|
||||
.doc-section {
|
||||
background: #ffffff;
|
||||
border-radius: 20rpx;
|
||||
padding: 40rpx 30rpx;
|
||||
margin-bottom: 30rpx;
|
||||
box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.1);
|
||||
|
||||
.section-title {
|
||||
font-size: 32rpx;
|
||||
font-weight: bold;
|
||||
color: #333333;
|
||||
margin-bottom: 30rpx;
|
||||
padding-bottom: 20rpx;
|
||||
border-bottom: 2rpx solid #f0f0f0;
|
||||
}
|
||||
|
||||
.doc-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 20rpx;
|
||||
|
||||
.doc-item {
|
||||
font-size: 28rpx;
|
||||
color: #666666;
|
||||
line-height: 1.8;
|
||||
padding-left: 10rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
/**
|
||||
* Login 页面 - request.ts 使用示例
|
||||
* 演示网络请求封装的各种用法:GET、POST、PUT、DELETE、文件上传等
|
||||
*/
|
||||
|
||||
import { loginReq, type LoginParams } from '../../api/login'
|
||||
|
||||
Page({
|
||||
/**
|
||||
* 页面的初始数据
|
||||
*/
|
||||
data: {
|
||||
// 登录表单数据
|
||||
username: '王波林0001',
|
||||
password: '1/OBSNrCge2rzKLaQduNpg==',
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面加载
|
||||
*/
|
||||
onLoad() {},
|
||||
|
||||
// ==================== 输入框事件处理 ====================
|
||||
|
||||
/**
|
||||
* 用户名输入变化
|
||||
*/
|
||||
onUsernameChange(e: WechatMiniprogram.Input) {
|
||||
this.setData({
|
||||
username: e.detail.value,
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 密码输入变化
|
||||
*/
|
||||
onPasswordChange(e: WechatMiniprogram.Input) {
|
||||
this.setData({
|
||||
password: e.detail.value,
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 用户ID输入变化
|
||||
*/
|
||||
onUserIdChange(e: WechatMiniprogram.Input) {
|
||||
this.setData({
|
||||
userId: e.detail.value,
|
||||
})
|
||||
},
|
||||
|
||||
// ==================== POST 请求示例 ====================
|
||||
|
||||
/**
|
||||
* 登录处理(显示 loading)
|
||||
* 演示:POST 请求 + 默认 loading + TypeScript 类型
|
||||
*/
|
||||
async handleLogin() {
|
||||
const { username, password } = this.data
|
||||
|
||||
// 表单验证
|
||||
if (!username || !password) {
|
||||
wx.showToast({
|
||||
title: '请输入用户名和密码',
|
||||
icon: 'none',
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
// POST 请求示例 - 默认显示 loading
|
||||
const loginParams: LoginParams = { userName: username, password }
|
||||
const res = await loginReq(loginParams)
|
||||
console.warn(res)
|
||||
|
||||
// 模拟保存 token
|
||||
// const app = getApp<IAppOption>()
|
||||
// if (res.data?.token) {
|
||||
// app.globalData.token = res.data.token
|
||||
// }
|
||||
|
||||
// wx.showToast({
|
||||
// title: '登录成功',
|
||||
// icon: 'success',
|
||||
// })
|
||||
|
||||
// 实际项目中可以跳转到首页
|
||||
// setTimeout(() => {
|
||||
// wx.switchTab({
|
||||
// url: '/pages/index/index'
|
||||
// })
|
||||
// }, 1500)
|
||||
} catch (error) {
|
||||
console.error('登录失败:', error)
|
||||
// 错误已在拦截器中统一处理,这里可以做额外处理
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面初次渲染完成
|
||||
*/
|
||||
onReady() {},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面显示
|
||||
*/
|
||||
onShow() {},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面隐藏
|
||||
*/
|
||||
onHide() {},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面卸载
|
||||
*/
|
||||
onUnload() {},
|
||||
|
||||
/**
|
||||
* 页面相关事件处理函数--监听用户下拉动作
|
||||
*/
|
||||
onPullDownRefresh() {},
|
||||
|
||||
/**
|
||||
* 页面上拉触底事件的处理函数
|
||||
*/
|
||||
onReachBottom() {},
|
||||
|
||||
/**
|
||||
* 用户点击右上角分享
|
||||
*/
|
||||
onShareAppMessage() {},
|
||||
})
|
||||
@@ -0,0 +1,36 @@
|
||||
<!--pages/login/login.wxml-->
|
||||
<view class="login-container">
|
||||
<!-- 标题区域 -->
|
||||
<view class="header">
|
||||
<text class="title">Request.ts 使用示例</text>
|
||||
<text class="subtitle">演示网络请求封装的各种用法</text>
|
||||
</view>
|
||||
|
||||
<!-- 登录表单区域 -->
|
||||
<view class="form-section">
|
||||
<view class="section-title">1. POST 请求示例 - 登录</view>
|
||||
|
||||
<t-input
|
||||
placeholder="请输入用户名"
|
||||
value="{{username}}"
|
||||
bind:change="onUsernameChange"
|
||||
class="input-item"
|
||||
clearable
|
||||
/>
|
||||
|
||||
<t-input
|
||||
placeholder="请输入密码"
|
||||
value="{{password}}"
|
||||
type="password"
|
||||
bind:change="onPasswordChange"
|
||||
class="input-item"
|
||||
clearable
|
||||
/>
|
||||
|
||||
<view class="button-group">
|
||||
<t-button theme="primary" size="large" bind:tap="handleLogin" block>
|
||||
登录
|
||||
</t-button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html",
|
||||
"rules": [
|
||||
{
|
||||
"action": "allow",
|
||||
"page": "*"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,233 @@
|
||||
// 小程序中使用命名空间导入 crypto-js(CommonJS 模块)
|
||||
// 注意:crypto-js 是 CommonJS 模块,在小程序中需要使用 import * as 方式导入
|
||||
import * as CryptoJS from 'crypto-js'
|
||||
|
||||
/**
|
||||
* AES 加密/解密错误类
|
||||
*/
|
||||
export class AESError extends Error {
|
||||
constructor(
|
||||
message: string,
|
||||
public readonly code?: string,
|
||||
) {
|
||||
super(message)
|
||||
this.name = 'AESError'
|
||||
}
|
||||
}
|
||||
|
||||
// KEY 和 IV
|
||||
const DEFAULT_KEY: string = 'J9w8x7z6y7A7B3C2D1E0F9G8H7I6J5K4'
|
||||
const DEFAULT_IV: string = 'Q1w2Q3T4T5y6U7i8'
|
||||
|
||||
/**
|
||||
* 统一解析 Key 和 IV
|
||||
* 强制校验长度,确保触发 AES-256
|
||||
* @throws {AESError} 当 KEY 或 IV 长度不符合要求时抛出错误
|
||||
*/
|
||||
const parseKeyIv = (keyStr: string, ivStr: string) => {
|
||||
try {
|
||||
// 验证 CryptoJS 是否正确加载
|
||||
if (!CryptoJS || !CryptoJS.enc || !CryptoJS.enc.Utf8) {
|
||||
throw new AESError('CryptoJS 模块未正确加载,请检查 crypto-js 依赖', 'MODULE_NOT_LOADED')
|
||||
}
|
||||
|
||||
const key = CryptoJS.enc.Utf8.parse(keyStr)
|
||||
const iv = CryptoJS.enc.Utf8.parse(ivStr)
|
||||
|
||||
// IV 必须是 16 字节 (128 bit),否则 AES 算法本身会出错或行为异常
|
||||
if (iv.sigBytes !== 16) {
|
||||
throw new AESError(
|
||||
`AES IV 错误: 期望 16 字节, 但实际为 ${iv.sigBytes} 字节.`,
|
||||
'INVALID_IV_LENGTH',
|
||||
)
|
||||
}
|
||||
|
||||
// Key 必须是 32 字节 (256 bit) 才能触发 AES-256
|
||||
// 如果是 16 字节会降级为 AES-128,如果是 24 字节是 AES-192
|
||||
// 为了强制 AES-256,这里必须报错
|
||||
if (key.sigBytes !== 32) {
|
||||
throw new AESError(
|
||||
`AES Key 错误: 期望 32 字节 (用于 AES-256), 但实际为 ${key.sigBytes} 字节.`,
|
||||
'INVALID_KEY_LENGTH',
|
||||
)
|
||||
}
|
||||
|
||||
return { key, iv }
|
||||
} catch (error) {
|
||||
// 如果是 AESError,直接抛出
|
||||
if (error instanceof AESError) {
|
||||
throw error
|
||||
}
|
||||
// 其他错误包装为 AESError
|
||||
throw new AESError(
|
||||
`解析 Key 或 IV 时发生错误: ${error instanceof Error ? error.message : String(error)}`,
|
||||
'PARSE_ERROR',
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 标准 AES 加密 (输出标准 Base64)
|
||||
* @param word 要加密的字符串
|
||||
* @param keyStr 密钥,可选,默认使用 DEFAULT_KEY
|
||||
* @param ivStr 初始化向量,可选,默认使用 DEFAULT_IV
|
||||
* @returns 加密后的字符串
|
||||
* @throws {AESError} 当加密失败时抛出错误
|
||||
*/
|
||||
export const Encrypt = (
|
||||
word: string,
|
||||
keyStr: string = DEFAULT_KEY,
|
||||
ivStr: string = DEFAULT_IV,
|
||||
): string => {
|
||||
try {
|
||||
// 验证输入参数
|
||||
if (typeof word !== 'string') {
|
||||
throw new AESError('要加密的内容必须是字符串类型', 'INVALID_INPUT')
|
||||
}
|
||||
|
||||
const { key, iv } = parseKeyIv(keyStr, ivStr)
|
||||
|
||||
const src = CryptoJS.enc.Utf8.parse(word)
|
||||
const encrypted = CryptoJS.AES.encrypt(src, key, {
|
||||
iv: iv,
|
||||
mode: CryptoJS.mode.CBC,
|
||||
padding: CryptoJS.pad.Pkcs7,
|
||||
})
|
||||
|
||||
const result = encrypted.toString()
|
||||
if (!result) {
|
||||
throw new AESError('加密结果为空,加密可能失败', 'ENCRYPT_FAILED')
|
||||
}
|
||||
|
||||
return result
|
||||
} catch (error) {
|
||||
// 如果是 AESError,直接抛出
|
||||
if (error instanceof AESError) {
|
||||
throw error
|
||||
}
|
||||
// 其他错误包装为 AESError
|
||||
throw new AESError(
|
||||
`加密失败: ${error instanceof Error ? error.message : String(error)}`,
|
||||
'ENCRYPT_ERROR',
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 标准 AES 解密 (输入标准 Base64)
|
||||
* @param word 要解密的字符串
|
||||
* @param keyStr 密钥,可选,默认使用 DEFAULT_KEY
|
||||
* @param ivStr 初始化向量,可选,默认使用 DEFAULT_IV
|
||||
* @returns 解密后的字符串,解密失败
|
||||
* @throws {AESError} 当解密过程中发生真正的错误时抛出
|
||||
*/
|
||||
export const Decrypt = (
|
||||
word: string,
|
||||
keyStr: string = DEFAULT_KEY,
|
||||
ivStr: string = DEFAULT_IV,
|
||||
): string => {
|
||||
try {
|
||||
// 验证输入参数
|
||||
if (typeof word !== 'string' || !word.trim()) {
|
||||
throw new AESError('要解密的内容必须是非空字符串', 'INVALID_INPUT')
|
||||
}
|
||||
|
||||
const { key, iv } = parseKeyIv(keyStr, ivStr)
|
||||
|
||||
const decrypt = CryptoJS.AES.decrypt(word, key, {
|
||||
iv: iv,
|
||||
mode: CryptoJS.mode.CBC,
|
||||
padding: CryptoJS.pad.Pkcs7,
|
||||
})
|
||||
|
||||
const result = decrypt.toString(CryptoJS.enc.Utf8)
|
||||
|
||||
// 如果解密结果为空,可能是密钥不匹配或密文被篡改(这是业务逻辑,不是错误)
|
||||
if (!result) {
|
||||
throw new AESError('解密结果为空,可能是密钥不匹配或密文被篡改', 'DECRYPT_FAILED')
|
||||
}
|
||||
|
||||
return result
|
||||
} catch (error) {
|
||||
// 如果是 AESError,直接抛出(这些是真正的错误,不应该静默处理)
|
||||
if (error instanceof AESError) {
|
||||
throw error
|
||||
}
|
||||
// 其他错误(如参数错误、模块未加载等)包装为 AESError
|
||||
throw new AESError(
|
||||
`解密失败: ${error instanceof Error ? error.message : String(error)}`,
|
||||
'DECRYPT_ERROR',
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* URL Safe Base64 加密
|
||||
* @param word 要加密的字符串
|
||||
* @param keyStr 密钥,可选,默认使用 DEFAULT_KEY
|
||||
* @param ivStr 初始化向量,可选,默认使用 DEFAULT_IV
|
||||
* @returns URL Safe Base64 编码的加密字符串
|
||||
* @throws {AESError} 当加密失败时抛出错误
|
||||
*/
|
||||
export const BASE64Encrypt = (
|
||||
word: string,
|
||||
keyStr: string = DEFAULT_KEY,
|
||||
ivStr: string = DEFAULT_IV,
|
||||
): string => {
|
||||
try {
|
||||
const encrypted = Encrypt(word, keyStr, ivStr)
|
||||
return encrypted.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '')
|
||||
} catch (error) {
|
||||
// 如果是 AESError,直接抛出
|
||||
if (error instanceof AESError) {
|
||||
throw error
|
||||
}
|
||||
// 其他错误包装为 AESError
|
||||
throw new AESError(
|
||||
`URL Safe Base64 加密失败: ${error instanceof Error ? error.message : String(error)}`,
|
||||
'BASE64_ENCRYPT_ERROR',
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* URL Safe Base64 解密
|
||||
* @param word 要解密的字符串
|
||||
* @param keyStr 密钥,可选,默认使用 DEFAULT_KEY
|
||||
* @param ivStr 初始化向量,可选,默认使用 DEFAULT_IV
|
||||
* @returns URL Safe Base64 解密后的字符串
|
||||
* @throws {AESError} 当解密过程中发生真正的错误时抛出
|
||||
*/
|
||||
export const BASE64Decrypt = (
|
||||
word: string,
|
||||
keyStr: string = DEFAULT_KEY,
|
||||
ivStr: string = DEFAULT_IV,
|
||||
): string => {
|
||||
try {
|
||||
// 验证输入参数
|
||||
if (typeof word !== 'string' || !word.trim()) {
|
||||
throw new AESError('要解密的内容必须是非空字符串', 'INVALID_INPUT')
|
||||
}
|
||||
|
||||
// 还原 Base64 格式
|
||||
let base64Str = word.replace(/-/g, '+').replace(/_/g, '/')
|
||||
|
||||
// 补全末尾的 = (Base64长度必须是4的倍数)
|
||||
const mod4 = base64Str.length % 4
|
||||
if (mod4 > 0) {
|
||||
base64Str += '='.repeat(4 - mod4)
|
||||
}
|
||||
|
||||
return Decrypt(base64Str, keyStr, ivStr)
|
||||
} catch (error) {
|
||||
// 如果是 AESError,直接抛出
|
||||
if (error instanceof AESError) {
|
||||
throw error
|
||||
}
|
||||
// 其他错误包装为 AESError
|
||||
throw new AESError(
|
||||
`URL Safe Base64 解密失败: ${error instanceof Error ? error.message : String(error)}`,
|
||||
'BASE64_DECRYPT_ERROR',
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,238 @@
|
||||
/**
|
||||
* 网络请求封装 - 基于 axios-miniprogram
|
||||
*
|
||||
* 功能特性:
|
||||
* - 自动添加 Token
|
||||
* - 统一错误处理
|
||||
* - 智能加载动画管理
|
||||
* - 完整的 TypeScript 类型支持
|
||||
* - 文件上传功能
|
||||
*/
|
||||
|
||||
import axios, { AxiosRequestConfig, AxiosResponse } from 'axios-miniprogram'
|
||||
import type { StandardResponse } from '../api/types'
|
||||
|
||||
// ==================== 类型定义 ====================
|
||||
|
||||
/**
|
||||
* 自定义请求配置接口
|
||||
* 扩展 axios 的请求配置,添加自定义参数
|
||||
*/
|
||||
interface CustomRequestConfig extends AxiosRequestConfig {
|
||||
loading?: boolean // 是否显示加载提示,默认 true
|
||||
upload?: boolean // 是否为上传请求
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件上传配置接口
|
||||
*/
|
||||
interface UploadOptions {
|
||||
apiUrl: string // 接口路径
|
||||
filePath: string // 文件本地路径
|
||||
name?: string // 文件对应的 key,默认 'file'
|
||||
formData?: Record<string, unknown> // 额外参数
|
||||
loading?: boolean // 是否显示加载提示,默认 true
|
||||
onUploadProgress?: (event: unknown) => void // 上传进度回调
|
||||
}
|
||||
|
||||
// ==================== 基础配置 ====================
|
||||
|
||||
// 配置 baseURL
|
||||
axios.defaults.baseURL = '你的后端域名'
|
||||
|
||||
// 配置超时时间(30秒)
|
||||
axios.defaults.timeout = 30000
|
||||
|
||||
// 配置默认请求头
|
||||
axios.defaults.headers.common['Content-Type'] = 'application/json'
|
||||
|
||||
// ==================== 请求白名单 ====================
|
||||
|
||||
/**
|
||||
* 请求白名单
|
||||
* 白名单内的接口不需要添加 Authorization 请求头
|
||||
* 例如:登录接口、注册接口等
|
||||
*/
|
||||
const requestWhiteList: string[] = []
|
||||
|
||||
// ==================== 加载动画管理 ====================
|
||||
|
||||
/**
|
||||
* 网络请求计数器
|
||||
* 用于管理多个并发请求的加载状态
|
||||
*/
|
||||
let netWorkNum = 0
|
||||
|
||||
/**
|
||||
* 开启加载动画
|
||||
* 使用计数器机制,防止多个请求导致的 loading 闪烁
|
||||
* @param title 加载提示文字
|
||||
*/
|
||||
function startLoading(title: string) {
|
||||
if (netWorkNum === 0) {
|
||||
wx.showLoading({
|
||||
title: title,
|
||||
mask: true,
|
||||
})
|
||||
}
|
||||
netWorkNum++
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭加载动画
|
||||
* 延迟 500ms 关闭,确保用户体验
|
||||
*/
|
||||
function endLoading() {
|
||||
netWorkNum--
|
||||
setTimeout(() => {
|
||||
if (netWorkNum === 0) {
|
||||
wx.hideLoading()
|
||||
wx.stopPullDownRefresh() // 停止当前页面下拉刷新
|
||||
}
|
||||
}, 500)
|
||||
}
|
||||
|
||||
// ==================== 请求拦截器 ====================
|
||||
|
||||
axios.interceptors.request.use(
|
||||
(config: CustomRequestConfig) => {
|
||||
// 加载提示
|
||||
if (config.loading ?? true) {
|
||||
startLoading('请稍等...')
|
||||
}
|
||||
|
||||
// Content-Type 设置
|
||||
// 注意:上传文件时 axios 会自动设置正确的 Content-Type
|
||||
if (config.headers && !config.headers['Content-Type']) {
|
||||
config.headers['Content-Type'] = 'application/json'
|
||||
}
|
||||
|
||||
// Token 自动注入(非白名单接口)
|
||||
if (!requestWhiteList.includes(config.url || '')) {
|
||||
const app = getApp<IAppOption>()
|
||||
if (app.globalData.token && config.headers) {
|
||||
config.headers['Authorization'] = app.globalData.token
|
||||
}
|
||||
}
|
||||
|
||||
// 详细日志记录
|
||||
/* eslint-disable no-console */
|
||||
console.log('============发送请求 start============')
|
||||
console.log(`[${new Date().toISOString()}] [INFO] 请求地址: ${config.baseURL}${config.url}`)
|
||||
console.log(`[${new Date().toISOString()}] [INFO] 请求方式: ${config.method?.toUpperCase()}`)
|
||||
console.log(`[${new Date().toISOString()}] [INFO] 上传模式: ${config.upload ? '是' : '否'}`)
|
||||
console.log(`[${new Date().toISOString()}] [INFO] params参数: ${JSON.stringify(config.params)}`)
|
||||
console.log(`[${new Date().toISOString()}] [INFO] data参数: ${JSON.stringify(config.data)}`)
|
||||
console.log('============发送请求 end============')
|
||||
/* eslint-enable no-console */
|
||||
|
||||
return config
|
||||
},
|
||||
(error) => {
|
||||
// 请求错误处理
|
||||
endLoading()
|
||||
return Promise.reject(error)
|
||||
},
|
||||
)
|
||||
|
||||
// ==================== 响应拦截器 ====================
|
||||
|
||||
axios.interceptors.response.use(
|
||||
(response: AxiosResponse) => {
|
||||
// 关闭加载动画
|
||||
const config = response.config as CustomRequestConfig
|
||||
if (config.loading ?? true) {
|
||||
endLoading()
|
||||
}
|
||||
|
||||
// 标准格式:{ code, data, message }
|
||||
const result = response.data as StandardResponse
|
||||
|
||||
if (result.code === 200) {
|
||||
// 只返回 data 字段(修改 response.data 为提取后的 data)
|
||||
return { ...response, data: result.data } as unknown as AxiosResponse
|
||||
} else {
|
||||
// 业务错误处理
|
||||
wx.showToast({
|
||||
title: result.message || '请求失败',
|
||||
icon: 'none',
|
||||
})
|
||||
return Promise.reject(new Error(result.message))
|
||||
}
|
||||
},
|
||||
(error: unknown) => {
|
||||
// 关闭加载动画
|
||||
const axiosError = error as {
|
||||
config?: CustomRequestConfig
|
||||
response?: AxiosResponse
|
||||
message?: string
|
||||
}
|
||||
const config = axiosError.config
|
||||
if (config?.loading ?? true) {
|
||||
endLoading()
|
||||
}
|
||||
|
||||
// 401 未授权,跳转登录页
|
||||
if (axiosError.response?.status === 401) {
|
||||
wx.showToast({
|
||||
title: '未授权,请重新登录',
|
||||
icon: 'none',
|
||||
})
|
||||
wx.reLaunch({
|
||||
url: '/pages/login/login',
|
||||
})
|
||||
return Promise.reject(error)
|
||||
}
|
||||
|
||||
// 统一错误提示
|
||||
const errorData = axiosError.response?.data as StandardResponse | undefined
|
||||
const message = errorData?.message || errorData?.data || axiosError.message || '网络请求失败'
|
||||
|
||||
wx.showToast({
|
||||
title: message as string,
|
||||
icon: 'none',
|
||||
})
|
||||
|
||||
return Promise.reject(error)
|
||||
},
|
||||
)
|
||||
|
||||
// ==================== 文件上传封装 ====================
|
||||
|
||||
/**
|
||||
* 文件上传函数
|
||||
* 基于 axios-miniprogram 内置的 upload 功能
|
||||
* @param options 上传配置
|
||||
* @returns Promise<T> 返回 data 字段的类型
|
||||
*/
|
||||
function upload<T = unknown>(options: UploadOptions): Promise<T> {
|
||||
const {
|
||||
apiUrl,
|
||||
filePath,
|
||||
name = 'file',
|
||||
formData = {},
|
||||
loading = true,
|
||||
onUploadProgress,
|
||||
} = options
|
||||
|
||||
return axios({
|
||||
url: apiUrl,
|
||||
method: 'POST',
|
||||
upload: true, // 启用上传模式
|
||||
data: {
|
||||
name, // 文件对应的 key
|
||||
filePath, // 要上传文件资源的路径
|
||||
...formData, // 额外的 formData 属性
|
||||
},
|
||||
loading, // 自定义 loading 参数(会被拦截器识别)
|
||||
onUploadProgress, // 上传进度回调
|
||||
} as CustomRequestConfig).then((res) => res.data as T)
|
||||
}
|
||||
|
||||
// ==================== 导出接口 ====================
|
||||
|
||||
// 默认导出 axios 实例(支持完整的泛型类型推导)
|
||||
export default axios
|
||||
|
||||
// 命名导出 upload 函数(支持泛型)
|
||||
export { upload }
|
||||
@@ -0,0 +1,126 @@
|
||||
/**
|
||||
* 格式化数字为两位数,不足两位前面补0
|
||||
* @param n 需要格式化的数字
|
||||
* @returns 格式化后的字符串(两位数)
|
||||
*/
|
||||
const formatNumber = (n: number) => {
|
||||
const s = n.toString()
|
||||
return s[1] ? s : '0' + s
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化日期时间为 YYYY/MM/DD HH:mm:ss 格式
|
||||
* @param date 需要格式化的日期对象
|
||||
* @returns 格式化后的日期时间字符串,格式为 YYYY/MM/DD HH:mm:ss
|
||||
*/
|
||||
export const formatTime = (date: Date) => {
|
||||
const year = date.getFullYear()
|
||||
const month = date.getMonth() + 1
|
||||
const day = date.getDate()
|
||||
const hour = date.getHours()
|
||||
const minute = date.getMinutes()
|
||||
const second = date.getSeconds()
|
||||
|
||||
return (
|
||||
[year, month, day].map(formatNumber).join('/') +
|
||||
' ' +
|
||||
[hour, minute, second].map(formatNumber).join(':')
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化日期时间
|
||||
* @param {Date|Number|String} date 日期对象、时间戳或日期字符串
|
||||
* @param {String} format 格式化模板,支持以下占位符:
|
||||
* - YYYY: 4位年份
|
||||
* - YY: 2位年份
|
||||
* - MM: 2位月份
|
||||
* - M: 1位月份
|
||||
* - DD: 2位日期
|
||||
* - D: 1位日期
|
||||
* - HH: 2位小时(24小时制)
|
||||
* - H: 1位小时(24小时制)
|
||||
* - hh: 2位小时(12小时制)
|
||||
* - h: 1位小时(12小时制)
|
||||
* - mm: 2位分钟
|
||||
* - m: 1位分钟
|
||||
* - ss: 2位秒
|
||||
* - s: 1位秒
|
||||
* - SSS: 3位毫秒
|
||||
* - A: 上午/下午
|
||||
* - a: 上午/下午(小写)
|
||||
* @return {String} 格式化后的日期时间字符串
|
||||
*/
|
||||
export const formatDateTime = (
|
||||
date: Date | number | string | undefined,
|
||||
format: string = 'YYYY/MM/DD HH:mm:ss',
|
||||
): string => {
|
||||
if (!date && date !== 0) return ''
|
||||
|
||||
let d: Date
|
||||
|
||||
// 1. 处理字符串类型的特殊清洗逻辑 (兼容原本 getDate 的脏数据处理能力)
|
||||
if (typeof date === 'string') {
|
||||
let cleanStr = date.trim()
|
||||
|
||||
// 替换中文符号和特殊符号为标准分隔符
|
||||
if (['年', '月', '日'].some((x) => cleanStr.includes(x))) {
|
||||
cleanStr = cleanStr.replace(/[年月日]/g, '/')
|
||||
}
|
||||
|
||||
// 补全简写日期 (例如 "2020" -> "2020/01/01") 以便 new Date 解析
|
||||
const parts = cleanStr.split(/[-/ :]/).filter(Boolean)
|
||||
if (parts.length === 1)
|
||||
cleanStr += '/01/01' // 只有年
|
||||
else if (parts.length === 2) cleanStr += '/01' // 只有年月
|
||||
|
||||
// 解决 iOS/Safari 不支持 "-" 连接符的问题
|
||||
cleanStr = cleanStr.replace(/-/g, '/')
|
||||
|
||||
d = new Date(cleanStr)
|
||||
} else if (typeof date === 'number') {
|
||||
d = new Date(date)
|
||||
} else {
|
||||
d = date
|
||||
}
|
||||
|
||||
// 有效性检查
|
||||
if (!(d instanceof Date) || isNaN(d.getTime())) {
|
||||
return ''
|
||||
}
|
||||
|
||||
// 提取时间分量
|
||||
const year = d.getFullYear()
|
||||
const month = d.getMonth() + 1
|
||||
const day = d.getDate()
|
||||
const hours = d.getHours()
|
||||
const minutes = d.getMinutes()
|
||||
const seconds = d.getSeconds()
|
||||
const milliseconds = d.getMilliseconds()
|
||||
|
||||
// 定义替换映射表
|
||||
const matches: Record<string, string | number> = {
|
||||
YYYY: year,
|
||||
YY: String(year).slice(-2),
|
||||
MM: String(month).padStart(2, '0'),
|
||||
M: month,
|
||||
DD: String(day).padStart(2, '0'),
|
||||
D: day,
|
||||
HH: String(hours).padStart(2, '0'),
|
||||
H: hours,
|
||||
hh: String(hours % 12 || 12).padStart(2, '0'),
|
||||
h: hours % 12 || 12,
|
||||
mm: String(minutes).padStart(2, '0'),
|
||||
m: minutes,
|
||||
ss: String(seconds).padStart(2, '0'),
|
||||
s: seconds,
|
||||
SSS: String(milliseconds).padStart(3, '0'),
|
||||
A: hours < 12 ? '上午' : '下午',
|
||||
a: hours < 12 ? 'am' : 'pm',
|
||||
}
|
||||
|
||||
// 5. 生成结果
|
||||
return format.replace(/YYYY|YY|MM|M|DD|D|HH|H|hh|h|mm|m|ss|s|SSS|A|a/g, (match) =>
|
||||
String(matches[match]),
|
||||
)
|
||||
}
|
||||
Generated
+1687
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"name": "miniprogram-ts-sass-quickstart",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"scripts": {
|
||||
"lint": "eslint .",
|
||||
"lint:fix": "eslint . --fix",
|
||||
"format": "prettier --write \"miniprogram/**/*.{ts,json,scss,wxml,wxss}\"",
|
||||
"format:check": "prettier --check \"miniprogram/**/*.{ts,json,scss,wxml,wxss}\""
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "",
|
||||
"dependencies": {
|
||||
"axios-miniprogram": "^2.7.2",
|
||||
"crypto-js": "^4.2.0",
|
||||
"tdesign-miniprogram": "^1.12.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/crypto-js": "^4.2.2",
|
||||
"@typescript-eslint/eslint-plugin": "^8.52.0",
|
||||
"@typescript-eslint/parser": "^8.52.0",
|
||||
"eslint": "^9.39.2",
|
||||
"eslint-config-prettier": "^10.1.8",
|
||||
"eslint-plugin-prettier": "^5.5.4",
|
||||
"jiti": "^2.6.1",
|
||||
"prettier": "^3.7.4",
|
||||
"typescript-eslint": "^8.52.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
{
|
||||
"description": "项目配置文件",
|
||||
"miniprogramRoot": "miniprogram/",
|
||||
"compileType": "miniprogram",
|
||||
"setting": {
|
||||
"useCompilerPlugins": ["typescript", "sass"],
|
||||
"babelSetting": {
|
||||
"ignore": [],
|
||||
"disablePlugins": [],
|
||||
"outputPath": ""
|
||||
},
|
||||
"coverView": true,
|
||||
"postcss": true,
|
||||
"minified": true,
|
||||
"enhance": true,
|
||||
"showShadowRootInWxmlPanel": true,
|
||||
"packNpmRelationList": [
|
||||
{
|
||||
"packageJsonPath": "./package.json",
|
||||
"miniprogramNpmDistDir": "./miniprogram/"
|
||||
}
|
||||
],
|
||||
"ignoreUploadUnusedFiles": true,
|
||||
"compileHotReLoad": true,
|
||||
"skylineRenderEnable": false,
|
||||
"es6": true,
|
||||
"compileWorklet": false,
|
||||
"uglifyFileName": false,
|
||||
"uploadWithSourceMap": true,
|
||||
"packNpmManually": true,
|
||||
"minifyWXSS": true,
|
||||
"minifyWXML": true,
|
||||
"localPlugins": false,
|
||||
"condition": false,
|
||||
"swc": true,
|
||||
"disableSWC": false,
|
||||
"disableUseStrict": false
|
||||
},
|
||||
"simulatorType": "wechat",
|
||||
"simulatorPluginLibVersion": {},
|
||||
"condition": {},
|
||||
"srcMiniprogramRoot": "miniprogram/",
|
||||
"editorSetting": {
|
||||
"tabIndent": "insertSpaces",
|
||||
"tabSize": 2
|
||||
},
|
||||
"libVersion": "3.7.12",
|
||||
"packOptions": {
|
||||
"ignore": [],
|
||||
"include": []
|
||||
},
|
||||
"appid": "你的appid"
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"strictNullChecks": true,
|
||||
"noImplicitAny": true,
|
||||
"module": "CommonJS",
|
||||
"target": "ES2020",
|
||||
"allowJs": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"esModuleInterop": true,
|
||||
"experimentalDecorators": true,
|
||||
"noImplicitThis": true,
|
||||
"noImplicitReturns": true,
|
||||
"alwaysStrict": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"strict": true,
|
||||
"strictPropertyInitialization": true,
|
||||
"lib": ["ES2020"],
|
||||
"typeRoots": ["./typings", "./node_modules/@types", "./node_modules/axios-miniprogram/dist"],
|
||||
"types": ["crypto-js"]
|
||||
},
|
||||
"include": ["./**/*.ts"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
/// <reference path="./types/index.d.ts" />
|
||||
/// <reference path="./npm.d.ts" />
|
||||
|
||||
interface IAppOption {
|
||||
globalData: {
|
||||
userInfo?: WechatMiniprogram.UserInfo
|
||||
token?: string
|
||||
}
|
||||
userInfoReadyCallback?: WechatMiniprogram.GetUserInfoSuccessCallback
|
||||
}
|
||||
Vendored
+27
@@ -0,0 +1,27 @@
|
||||
/// <reference path="./types/index.d.ts" />
|
||||
|
||||
/**
|
||||
* npm 包类型声明
|
||||
* 用于声明项目中使用的 npm 包的类型
|
||||
*
|
||||
* 说明:
|
||||
* - crypto-js: 类型定义通过 @types/crypto-js 提供
|
||||
* - tdesign-miniprogram: 自带完整的类型定义文件
|
||||
*
|
||||
* TypeScript 会自动从 node_modules 中读取这些类型定义
|
||||
* 此文件主要用于确保模块在小程序环境中的正确识别和类型支持
|
||||
*/
|
||||
|
||||
// crypto-js 类型声明
|
||||
// @types/crypto-js 已安装,通过三斜线指令引用类型定义
|
||||
/// <reference types="crypto-js" />
|
||||
|
||||
// tdesign-miniprogram 类型声明
|
||||
// tdesign-miniprogram 自带完整的类型定义文件
|
||||
// TypeScript 会自动从 node_modules/tdesign-miniprogram/miniprogram_dist 读取类型
|
||||
// 这里提供一个模块声明,确保在小程序环境中能正确识别
|
||||
declare module 'tdesign-miniprogram' {
|
||||
// 类型定义由 tdesign-miniprogram 包内提供
|
||||
// 实际使用时,TypeScript 会自动识别 miniprogram_dist 目录下的类型文件
|
||||
export * from 'tdesign-miniprogram/miniprogram_dist/index'
|
||||
}
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
/// <reference path="./wx/index.d.ts" />
|
||||
Vendored
+163
@@ -0,0 +1,163 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) 2025 Tencent, Inc. All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
***************************************************************************** */
|
||||
|
||||
/// <reference path="./lib.wx.app.d.ts" />
|
||||
/// <reference path="./lib.wx.page.d.ts" />
|
||||
/// <reference path="./lib.wx.api.d.ts" />
|
||||
/// <reference path="./lib.wx.cloud.d.ts" />
|
||||
/// <reference path="./lib.wx.canvas.d.ts" />
|
||||
/// <reference path="./lib.wx.component.d.ts" />
|
||||
/// <reference path="./lib.wx.behavior.d.ts" />
|
||||
/// <reference path="./lib.wx.event.d.ts" />
|
||||
/// <reference path="./lib.wx.wasm.d.ts" />
|
||||
|
||||
declare namespace WechatMiniprogram {
|
||||
type IAnyObject = Record<string, any>
|
||||
type Optional<F> = F extends (arg: infer P) => infer R ? (arg?: P) => R : F
|
||||
type OptionalInterface<T> = { [K in keyof T]: Optional<T[K]> }
|
||||
interface AsyncMethodOptionLike {
|
||||
success?: (...args: any[]) => void
|
||||
}
|
||||
type PromisifySuccessResult<
|
||||
P,
|
||||
T extends AsyncMethodOptionLike
|
||||
> = P extends {
|
||||
success: any
|
||||
}
|
||||
? void
|
||||
: P extends { fail: any }
|
||||
? void
|
||||
: P extends { complete: any }
|
||||
? void
|
||||
: Promise<Parameters<Exclude<T['success'], undefined>>[0]>
|
||||
|
||||
// TODO: Extract real definition from `lib.dom.d.ts` to replace this
|
||||
type IIRFilterNode = any
|
||||
type WaveShaperNode = any
|
||||
type ConstantSourceNode = any
|
||||
type OscillatorNode = any
|
||||
type GainNode = any
|
||||
type BiquadFilterNode = any
|
||||
type PeriodicWaveNode = any
|
||||
type AudioNode = any
|
||||
type ChannelSplitterNode = any
|
||||
type ChannelMergerNode = any
|
||||
type DelayNode = any
|
||||
type DynamicsCompressorNode = any
|
||||
type ScriptProcessorNode = any
|
||||
type PannerNode = any
|
||||
type AnalyserNode = any
|
||||
type WebGLTexture = any
|
||||
type WebGLRenderingContext = any
|
||||
|
||||
// TODO: fill worklet type
|
||||
type WorkletFunction = (...args: any) => any
|
||||
type AnimationObject = any
|
||||
type SharedValue<T = any> = T
|
||||
type DerivedValue<T = any> = T
|
||||
}
|
||||
|
||||
declare let console: WechatMiniprogram.Console
|
||||
|
||||
declare let wx: WechatMiniprogram.Wx
|
||||
/** 引入模块。返回模块通过 `module.exports` 或 `exports` 暴露的接口。 */
|
||||
interface Require {
|
||||
(
|
||||
/** 需要引入模块文件相对于当前文件的相对路径,或 npm 模块名,或 npm 模块路径。不支持绝对路径 */
|
||||
module: string,
|
||||
/** 用于异步获取其他分包中的模块的引用结果,详见 [分包异步化]((subpackages/async)) */
|
||||
callback?: (moduleExport: any) => void,
|
||||
/** 异步获取分包失败时的回调,详见 [分包异步化]((subpackages/async)) */
|
||||
errorCallback?: (err: any) => void
|
||||
): any
|
||||
/** 以 Promise 形式异步引入模块。返回模块通过 `module.exports` 或 `exports` 暴露的接口。 */
|
||||
async(
|
||||
/** 需要引入模块文件相对于当前文件的相对路径,或 npm 模块名,或 npm 模块路径。不支持绝对路径 */
|
||||
module: string
|
||||
): Promise<any>
|
||||
}
|
||||
declare const require: Require
|
||||
/** 引入插件。返回插件通过 `main` 暴露的接口。 */
|
||||
interface RequirePlugin {
|
||||
(
|
||||
/** 需要引入的插件的 alias */
|
||||
module: string,
|
||||
/** 用于异步获取其他分包中的插件的引用结果,详见 [分包异步化]((subpackages/async)) */
|
||||
callback?: (pluginExport: any) => void
|
||||
): any
|
||||
/** 以 Promise 形式异步引入插件。返回插件通过 `main` 暴露的接口。 */
|
||||
async(
|
||||
/** 需要引入的插件的 alias */
|
||||
module: string
|
||||
): Promise<any>
|
||||
}
|
||||
declare const requirePlugin: RequirePlugin
|
||||
/** 插件引入当前使用者小程序。返回使用者小程序通过 [插件配置中 `export` 暴露的接口](https://developers.weixin.qq.com/miniprogram/dev/framework/plugin/using.html#%E5%AF%BC%E5%87%BA%E5%88%B0%E6%8F%92%E4%BB%B6)。
|
||||
*
|
||||
* 该接口只在插件中存在
|
||||
*
|
||||
* 最低基础库: `2.11.1` */
|
||||
declare function requireMiniProgram(): any
|
||||
/** 当前模块对象 */
|
||||
declare let module: {
|
||||
/** 模块向外暴露的对象,使用 `require` 引用该模块时可以获取 */
|
||||
exports: any
|
||||
}
|
||||
/** `module.exports` 的引用 */
|
||||
declare let exports: any
|
||||
|
||||
/** [clearInterval(number intervalID)](https://developers.weixin.qq.com/miniprogram/dev/api/base/timer/clearInterval.html)
|
||||
*
|
||||
* 取消由 setInterval 设置的定时器。 */
|
||||
declare function clearInterval(
|
||||
/** 要取消的定时器的 ID */
|
||||
intervalID: number
|
||||
): void
|
||||
/** [clearTimeout(number timeoutID)](https://developers.weixin.qq.com/miniprogram/dev/api/base/timer/clearTimeout.html)
|
||||
*
|
||||
* 取消由 setTimeout 设置的定时器。 */
|
||||
declare function clearTimeout(
|
||||
/** 要取消的定时器的 ID */
|
||||
timeoutID: number
|
||||
): void
|
||||
/** [number setInterval(function callback, number delay, any rest)](https://developers.weixin.qq.com/miniprogram/dev/api/base/timer/setInterval.html)
|
||||
*
|
||||
* 设定一个定时器。按照指定的周期(以毫秒计)来执行注册的回调函数 */
|
||||
declare function setInterval(
|
||||
/** 回调函数 */
|
||||
callback: (...args: any[]) => any,
|
||||
/** 执行回调函数之间的时间间隔,单位 ms。 */
|
||||
delay?: number,
|
||||
/** param1, param2, ..., paramN 等附加参数,它们会作为参数传递给回调函数。 */
|
||||
...rest: any[]
|
||||
): number
|
||||
/** [number setTimeout(function callback, number delay, any rest)](https://developers.weixin.qq.com/miniprogram/dev/api/base/timer/setTimeout.html)
|
||||
*
|
||||
* 设定一个定时器。在定时到期以后执行注册的回调函数 */
|
||||
declare function setTimeout(
|
||||
/** 回调函数 */
|
||||
callback: (...args: any[]) => any,
|
||||
/** 延迟的时间,函数的调用会在该延迟之后发生,单位 ms。 */
|
||||
delay?: number,
|
||||
/** param1, param2, ..., paramN 等附加参数,它们会作为参数传递给回调函数。 */
|
||||
...rest: any[]
|
||||
): number
|
||||
Vendored
+38509
File diff suppressed because it is too large
Load Diff
Vendored
+424
@@ -0,0 +1,424 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) 2025 Tencent, Inc. All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
***************************************************************************** */
|
||||
|
||||
declare namespace WechatMiniprogram.App {
|
||||
type SceneValues =
|
||||
| 1000
|
||||
| 1001
|
||||
| 1005
|
||||
| 1006
|
||||
| 1007
|
||||
| 1008
|
||||
| 1010
|
||||
| 1011
|
||||
| 1012
|
||||
| 1013
|
||||
| 1014
|
||||
| 1017
|
||||
| 1019
|
||||
| 1020
|
||||
| 1022
|
||||
| 1023
|
||||
| 1024
|
||||
| 1025
|
||||
| 1026
|
||||
| 1027
|
||||
| 1028
|
||||
| 1029
|
||||
| 1030
|
||||
| 1031
|
||||
| 1032
|
||||
| 1034
|
||||
| 1035
|
||||
| 1036
|
||||
| 1037
|
||||
| 1038
|
||||
| 1039
|
||||
| 1042
|
||||
| 1043
|
||||
| 1044
|
||||
| 1045
|
||||
| 1046
|
||||
| 1047
|
||||
| 1048
|
||||
| 1049
|
||||
| 1052
|
||||
| 1053
|
||||
| 1054
|
||||
| 1056
|
||||
| 1057
|
||||
| 1058
|
||||
| 1059
|
||||
| 1060
|
||||
| 1064
|
||||
| 1065
|
||||
| 1067
|
||||
| 1068
|
||||
| 1069
|
||||
| 1071
|
||||
| 1072
|
||||
| 1073
|
||||
| 1074
|
||||
| 1077
|
||||
| 1078
|
||||
| 1079
|
||||
| 1081
|
||||
| 1082
|
||||
| 1084
|
||||
| 1088
|
||||
| 1089
|
||||
| 1090
|
||||
| 1091
|
||||
| 1092
|
||||
| 1095
|
||||
| 1096
|
||||
| 1097
|
||||
| 1099
|
||||
| 1100
|
||||
| 1101
|
||||
| 1102
|
||||
| 1103
|
||||
| 1104
|
||||
| 1106
|
||||
| 1107
|
||||
| 1113
|
||||
| 1114
|
||||
| 1119
|
||||
| 1120
|
||||
| 1121
|
||||
| 1124
|
||||
| 1125
|
||||
| 1126
|
||||
| 1129
|
||||
| 1131
|
||||
| 1133
|
||||
| 1135
|
||||
| 1144
|
||||
| 1145
|
||||
| 1146
|
||||
| 1148
|
||||
| 1150
|
||||
| 1151
|
||||
| 1152
|
||||
| 1153
|
||||
| 1154
|
||||
| 1155
|
||||
| 1157
|
||||
| 1158
|
||||
| 1160
|
||||
| 1167
|
||||
| 1168
|
||||
| 1169
|
||||
| 1171
|
||||
| 1173
|
||||
| 1175
|
||||
| 1176
|
||||
| 1177
|
||||
| 1178
|
||||
| 1179
|
||||
| 1181
|
||||
| 1183
|
||||
| 1184
|
||||
| 1185
|
||||
| 1186
|
||||
| 1187
|
||||
| 1189
|
||||
| 1191
|
||||
| 1192
|
||||
| 1193
|
||||
| 1194
|
||||
| 1195
|
||||
| 1196
|
||||
| 1197
|
||||
| 1198
|
||||
| 1200
|
||||
| 1201
|
||||
| 1202
|
||||
| 1203
|
||||
| 1206
|
||||
| 1207
|
||||
| 1208
|
||||
| 1212
|
||||
| 1215
|
||||
| 1216
|
||||
| 1223
|
||||
| 1228
|
||||
| 1231
|
||||
|
||||
interface LaunchShowOption {
|
||||
/** 打开小程序的路径 */
|
||||
path: string
|
||||
/** 打开小程序的query */
|
||||
query: IAnyObject
|
||||
/** 打开小程序的场景值
|
||||
* - 1000:其他
|
||||
* - 1001:发现栏小程序主入口,「最近使用」列表(基础库 2.2.4 版本起包含「我的小程序」列表)
|
||||
* - 1005:微信首页顶部搜索框的搜索结果页
|
||||
* - 1006:发现栏小程序主入口搜索框的搜索结果页
|
||||
* - 1007:单人聊天会话中的小程序消息卡片
|
||||
* - 1008:群聊会话中的小程序消息卡片
|
||||
* - 1010:收藏夹
|
||||
* - 1011:扫描二维码
|
||||
* - 1012:长按图片识别二维码
|
||||
* - 1013:扫描手机相册中选取的二维码
|
||||
* - 1014:小程序订阅消息(与 1107 相同)
|
||||
* - 1017:前往小程序体验版的入口页
|
||||
* - 1019:微信钱包(微信客户端 7.0.0 版本改为支付入口)
|
||||
* - 1020:公众号 profile 页相关小程序列表(已废弃)
|
||||
* - 1022:聊天顶部置顶小程序入口(微信客户端 6.6.1 版本起废弃)
|
||||
* - 1023:安卓系统桌面图标
|
||||
* - 1024:小程序 profile 页
|
||||
* - 1025:扫描一维码
|
||||
* - 1026:发现栏小程序主入口,「附近的小程序」列表
|
||||
* - 1027:微信首页顶部搜索框搜索结果页「使用过的小程序」列表
|
||||
* - 1028:我的卡包
|
||||
* - 1029:小程序中的卡券详情页
|
||||
* - 1030:自动化测试下打开小程序
|
||||
* - 1031:长按图片识别一维码
|
||||
* - 1032:扫描手机相册中选取的一维码
|
||||
* - 1034:微信支付完成页
|
||||
* - 1035:公众号自定义菜单
|
||||
* - 1036:App 分享消息卡片
|
||||
* - 1037:小程序打开小程序
|
||||
* - 1038:从另一个小程序返回
|
||||
* - 1039:摇电视
|
||||
* - 1042:添加好友搜索框的搜索结果页
|
||||
* - 1043:公众号模板消息
|
||||
* - 1044:带 shareTicket 的小程序消息卡片 [详情](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/share.html)
|
||||
* - 1045:朋友圈广告
|
||||
* - 1046:朋友圈广告详情页
|
||||
* - 1047:扫描小程序码
|
||||
* - 1048:长按图片识别小程序码
|
||||
* - 1049:扫描手机相册中选取的小程序码
|
||||
* - 1052:卡券的适用门店列表
|
||||
* - 1053:搜一搜的结果页
|
||||
* - 1054:顶部搜索框小程序快捷入口(微信客户端版本 6.7.4 起废弃)
|
||||
* - 1056:聊天顶部音乐播放器右上角菜单
|
||||
* - 1057:钱包中的银行卡详情页
|
||||
* - 1058:公众号文章
|
||||
* - 1059:体验版小程序绑定邀请页
|
||||
* - 1060:微信支付完成页(与 1034 相同)
|
||||
* - 1064:微信首页连 Wi-Fi 状态栏
|
||||
* - 1065:URL scheme [详情](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/url-scheme.html)
|
||||
* - 1067:公众号文章广告
|
||||
* - 1068:附近小程序列表广告(已废弃)
|
||||
* - 1069:移动应用通过 openSDK 进入微信,打开小程序
|
||||
* - 1071:钱包中的银行卡列表页
|
||||
* - 1072:二维码收款页面
|
||||
* - 1073:客服消息列表下发的小程序消息卡片
|
||||
* - 1074:公众号会话下发的小程序消息卡片
|
||||
* - 1077:摇周边
|
||||
* - 1078:微信连 Wi-Fi 成功提示页
|
||||
* - 1079:微信游戏中心
|
||||
* - 1081:客服消息下发的文字链
|
||||
* - 1082:公众号会话下发的文字链
|
||||
* - 1084:朋友圈广告原生页
|
||||
* - 1088:会话中查看系统消息,打开小程序
|
||||
* - 1089:微信聊天主界面下拉,「最近使用」栏(基础库 2.2.4 版本起包含「我的小程序」栏)
|
||||
* - 1090:长按小程序右上角菜单唤出最近使用历史
|
||||
* - 1091:公众号文章商品卡片
|
||||
* - 1092:城市服务入口
|
||||
* - 1095:小程序广告组件
|
||||
* - 1096:聊天记录,打开小程序
|
||||
* - 1097:微信支付签约原生页,打开小程序
|
||||
* - 1099:页面内嵌插件
|
||||
* - 1100:红包封面详情页打开小程序
|
||||
* - 1101:远程调试热更新(开发者工具中,预览 -> 自动预览 -> 编译并预览)
|
||||
* - 1102:公众号 profile 页服务预览
|
||||
* - 1103:发现栏小程序主入口,「我的小程序」列表(基础库 2.2.4 版本起废弃)
|
||||
* - 1104:微信聊天主界面下拉,「我的小程序」栏(基础库 2.2.4 版本起废弃)
|
||||
* - 1106:聊天主界面下拉,从顶部搜索结果页,打开小程序
|
||||
* - 1107:订阅消息,打开小程序
|
||||
* - 1113:安卓手机负一屏,打开小程序(三星)
|
||||
* - 1114:安卓手机侧边栏,打开小程序(三星)
|
||||
* - 1119:【企业微信】工作台内打开小程序
|
||||
* - 1120:【企业微信】个人资料页内打开小程序
|
||||
* - 1121:【企业微信】聊天加号附件框内打开小程序
|
||||
* - 1124:扫“一物一码”打开小程序
|
||||
* - 1125:长按图片识别“一物一码”
|
||||
* - 1126:扫描手机相册中选取的“一物一码”
|
||||
* - 1129:微信爬虫访问 [详情](https://developers.weixin.qq.com/miniprogram/dev/reference/configuration/sitemap.html)
|
||||
* - 1131:浮窗(8.0 版本起仅包含被动浮窗)
|
||||
* - 1133:硬件设备打开小程序 [详情](https://developers.weixin.qq.com/doc/oplatform/Miniprogram_Frame/)
|
||||
* - 1135:小程序 profile 页相关小程序列表,打开小程序
|
||||
* - 1144:公众号文章 - 视频贴片
|
||||
* - 1145:发现栏 - 发现小程序
|
||||
* - 1146:地理位置信息打开出行类小程序
|
||||
* - 1148:卡包-交通卡,打开小程序
|
||||
* - 1150:扫一扫商品条码结果页打开小程序
|
||||
* - 1151:发现栏 - 我的订单
|
||||
* - 1152:订阅号视频打开小程序
|
||||
* - 1153:“识物”结果页打开小程序
|
||||
* - 1154:朋友圈内打开“单页模式”
|
||||
* - 1155:“单页模式”打开小程序
|
||||
* - 1157:服务号会话页打开小程序
|
||||
* - 1158:群工具打开小程序
|
||||
* - 1160:群待办
|
||||
* - 1167:H5 通过开放标签打开小程序 [详情](https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_Open_Tag.html)
|
||||
* - 1168:移动应用直接运行小程序
|
||||
* - 1169:发现栏小程序主入口,各个生活服务入口(例如快递服务、出行服务等)
|
||||
* - 1171:微信运动记录(仅安卓)
|
||||
* - 1173:聊天素材用小程序打开 [详情](https://developers.weixin.qq.com/miniprogram/dev/framework/material/support_material.html)
|
||||
* - 1175:视频号主页商店入口
|
||||
* - 1176:视频号直播间主播打开小程序
|
||||
* - 1177:视频号直播商品
|
||||
* - 1178:在电脑打开手机上打开的小程序
|
||||
* - 1179:#话题页打开小程序
|
||||
* - 1181:网站应用打开 PC 小程序
|
||||
* - 1183:PC 微信 - 小程序面板 - 发现小程序 - 搜索
|
||||
* - 1184:视频号链接打开小程序
|
||||
* - 1185:群公告
|
||||
* - 1186:收藏 - 笔记
|
||||
* - 1187:浮窗(8.0 版本起)
|
||||
* - 1189:表情雨广告
|
||||
* - 1191:视频号活动
|
||||
* - 1192:企业微信联系人 profile 页
|
||||
* - 1193:视频号主页服务菜单打开小程序
|
||||
* - 1194:URL Link [详情](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/url-link.html)
|
||||
* - 1195:视频号主页商品 tab
|
||||
* - 1196:个人状态打开小程序
|
||||
* - 1197:视频号主播从直播间返回小游戏
|
||||
* - 1198:视频号开播界面打开小游戏
|
||||
* - 1200:视频号广告打开小程序
|
||||
* - 1201:视频号广告详情页打开小程序
|
||||
* - 1202:企微客服号会话打开小程序卡片
|
||||
* - 1203:微信小程序压测工具的请求
|
||||
* - 1206:视频号小游戏直播间打开小游戏
|
||||
* - 1207:企微客服号会话打开小程序文字链
|
||||
* - 1208:聊天打开商品卡片
|
||||
* - 1212:青少年模式申请页打开小程序
|
||||
* - 1215:广告预约打开小程序
|
||||
* - 1216:视频号订单中心打开小程序
|
||||
* - 1223:安卓桌面 Widget 打开小程序
|
||||
* - 1228:视频号原生广告组件打开小程序
|
||||
* - 1231:动态消息提醒入口打开小程序
|
||||
*/
|
||||
scene: SceneValues
|
||||
/** shareTicket,详见 [获取更多转发信息]((转发#获取更多转发信息)) */
|
||||
shareTicket: string
|
||||
/** 当场景为由从另一个小程序或公众号或App打开时,返回此字段 */
|
||||
referrerInfo?: ReferrerInfo
|
||||
/** 打开的文件信息数组,只有从聊天素材场景打开(scene为1173)才会携带该参数 */
|
||||
forwardMaterials: ForwardMaterials[]
|
||||
/** 从微信群聊/单聊打开小程序时,chatType 表示具体微信群聊/单聊类型
|
||||
*
|
||||
* 可选值:
|
||||
* - 1: 微信联系人单聊;
|
||||
* - 2: 企业微信联系人单聊;
|
||||
* - 3: 普通微信群聊;
|
||||
* - 4: 企业微信互通群聊; */
|
||||
chatType?: 1 | 2 | 3 | 4
|
||||
/** 需要基础库: `2.20.0`
|
||||
*
|
||||
* API 类别
|
||||
*
|
||||
* 可选值:
|
||||
* - 'default': 默认类别;
|
||||
* - 'nativeFunctionalized': 原生功能化,视频号直播商品、商品橱窗等场景打开的小程序;
|
||||
* - 'browseOnly': 仅浏览,朋友圈快照页等场景打开的小程序;
|
||||
* - 'embedded': 内嵌,通过打开半屏小程序能力打开的小程序; */
|
||||
apiCategory:
|
||||
| 'default'
|
||||
| 'nativeFunctionalized'
|
||||
| 'browseOnly'
|
||||
| 'embedded'
|
||||
}
|
||||
|
||||
interface PageNotFoundOption {
|
||||
/** 不存在页面的路径 */
|
||||
path: string
|
||||
/** 打开不存在页面的 query */
|
||||
query: IAnyObject
|
||||
/** 是否本次启动的首个页面(例如从分享等入口进来,首个页面是开发者配置的分享页面) */
|
||||
isEntryPage: boolean
|
||||
}
|
||||
|
||||
interface Option {
|
||||
/** 生命周期回调—监听小程序初始化
|
||||
*
|
||||
* 小程序初始化完成时触发,全局只触发一次。
|
||||
*/
|
||||
onLaunch(options: LaunchShowOption): void
|
||||
/** 生命周期回调—监听小程序显示
|
||||
*
|
||||
* 小程序启动,或从后台进入前台显示时
|
||||
*/
|
||||
onShow(options: LaunchShowOption): void
|
||||
/** 生命周期回调—监听小程序隐藏
|
||||
*
|
||||
* 小程序从前台进入后台时
|
||||
*/
|
||||
onHide(): void
|
||||
/** 错误监听函数
|
||||
*
|
||||
* 小程序发生脚本错误,或者 api
|
||||
*/
|
||||
onError(/** 错误信息,包含堆栈 */ error: string): void
|
||||
/** 页面不存在监听函数
|
||||
*
|
||||
* 小程序要打开的页面不存在时触发,会带上页面信息回调该函数
|
||||
*
|
||||
* **注意:**
|
||||
* 1. 如果开发者没有添加 `onPageNotFound` 监听,当跳转页面不存在时,将推入微信客户端原生的页面不存在提示页面。
|
||||
* 2. 如果 `onPageNotFound` 回调中又重定向到另一个不存在的页面,将推入微信客户端原生的页面不存在提示页面,并且不再回调 `onPageNotFound`。
|
||||
*
|
||||
* 最低基础库: 1.9.90
|
||||
*/
|
||||
onPageNotFound(options: PageNotFoundOption): void
|
||||
/**
|
||||
* 小程序有未处理的 Promise 拒绝时触发。也可以使用 [wx.onUnhandledRejection](https://developers.weixin.qq.com/miniprogram/dev/api/base/app/app-event/wx.onUnhandledRejection.html) 绑定监听。注意事项请参考 [wx.onUnhandledRejection](https://developers.weixin.qq.com/miniprogram/dev/api/base/app/app-event/wx.onUnhandledRejection.html)。
|
||||
* **参数**:与 [wx.onUnhandledRejection](https://developers.weixin.qq.com/miniprogram/dev/api/base/app/app-event/wx.onUnhandledRejection.html) 一致
|
||||
*/
|
||||
onUnhandledRejection: OnUnhandledRejectionCallback
|
||||
/**
|
||||
* 系统切换主题时触发。也可以使用 wx.onThemeChange 绑定监听。
|
||||
*
|
||||
* 最低基础库: 2.11.0
|
||||
*/
|
||||
onThemeChange: OnThemeChangeCallback
|
||||
}
|
||||
|
||||
type Instance<T extends IAnyObject> = Option & T
|
||||
type Options<T extends IAnyObject> = Partial<Option> &
|
||||
T &
|
||||
ThisType<Instance<T>>
|
||||
type TrivialInstance = Instance<IAnyObject>
|
||||
|
||||
interface Constructor {
|
||||
<T extends IAnyObject>(options: Options<T>): void
|
||||
}
|
||||
|
||||
interface GetAppOption {
|
||||
/** 在 `App` 未定义时返回默认实现。当App被调用时,默认实现中定义的属性会被覆盖合并到App中。一般用于独立分包
|
||||
*
|
||||
* 最低基础库: 2.2.4
|
||||
*/
|
||||
allowDefault?: boolean
|
||||
}
|
||||
|
||||
interface GetApp {
|
||||
<T extends IAnyObject = IAnyObject>(opts?: GetAppOption): Instance<T>
|
||||
}
|
||||
}
|
||||
|
||||
declare let App: WechatMiniprogram.App.Constructor
|
||||
declare let getApp: WechatMiniprogram.App.GetApp
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) 2025 Tencent, Inc. All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
***************************************************************************** */
|
||||
|
||||
declare namespace WechatMiniprogram.Behavior {
|
||||
|
||||
type BehaviorIdentifier<
|
||||
TData extends DataOption = {},
|
||||
TProperty extends PropertyOption = {},
|
||||
TMethod extends MethodOption = {},
|
||||
TBehavior extends BehaviorOption = []
|
||||
> = string & {
|
||||
[key in 'BehaviorType']?: {
|
||||
data: Component.FilterUnknownType<TData> & Component.MixinData<TBehavior>
|
||||
properties: Component.FilterUnknownType<TProperty> & Component.MixinProperties<TBehavior, true>
|
||||
methods: Component.FilterUnknownType<TMethod> & Component.MixinMethods<TBehavior>
|
||||
}
|
||||
}
|
||||
type Instance<
|
||||
TData extends DataOption,
|
||||
TProperty extends PropertyOption,
|
||||
TMethod extends MethodOption,
|
||||
TBehavior extends BehaviorOption,
|
||||
TCustomInstanceProperty extends IAnyObject = Record<string, never>
|
||||
> = Component.Instance<TData, TProperty, TMethod, TBehavior, TCustomInstanceProperty>
|
||||
type TrivialInstance = Instance<IAnyObject, IAnyObject, IAnyObject, Component.IEmptyArray>
|
||||
type TrivialOption = Options<IAnyObject, IAnyObject, IAnyObject, Component.IEmptyArray>
|
||||
type Options<
|
||||
TData extends DataOption,
|
||||
TProperty extends PropertyOption,
|
||||
TMethod extends MethodOption,
|
||||
TBehavior extends BehaviorOption,
|
||||
TCustomInstanceProperty extends IAnyObject = Record<string, never>
|
||||
> = Partial<Data<TData>> &
|
||||
Partial<Property<TProperty>> &
|
||||
Partial<Method<TMethod>> &
|
||||
Partial<Behavior<TBehavior>> &
|
||||
Partial<OtherOption> &
|
||||
Partial<Lifetimes> &
|
||||
ThisType<Instance<TData, TProperty, TMethod, TBehavior, TCustomInstanceProperty>>
|
||||
interface Constructor {
|
||||
<
|
||||
TData extends DataOption,
|
||||
TProperty extends PropertyOption,
|
||||
TMethod extends MethodOption,
|
||||
TBehavior extends BehaviorOption,
|
||||
TCustomInstanceProperty extends IAnyObject = Record<string, never>
|
||||
>(
|
||||
options: Options<TData, TProperty, TMethod, TBehavior, TCustomInstanceProperty>
|
||||
): BehaviorIdentifier<TData, TProperty, TMethod, TBehavior>
|
||||
}
|
||||
|
||||
type DataOption = Component.DataOption
|
||||
type PropertyOption = Component.PropertyOption
|
||||
type MethodOption = Component.MethodOption
|
||||
type BehaviorOption = Component.BehaviorOption
|
||||
type Data<D extends DataOption> = Component.Data<D>
|
||||
type Property<P extends PropertyOption> = Component.Property<P>
|
||||
type Method<M extends MethodOption> = Component.Method<M>
|
||||
type Behavior<B extends BehaviorOption> = Component.Behavior<B>
|
||||
|
||||
type DefinitionFilter = Component.DefinitionFilter
|
||||
type Lifetimes = Component.Lifetimes
|
||||
type OtherOption = Omit<Component.OtherOption, 'options'>
|
||||
}
|
||||
/** 注册一个 `behavior`,接受一个 `Object` 类型的参数。*/
|
||||
declare let Behavior: WechatMiniprogram.Behavior.Constructor
|
||||
Vendored
+2623
File diff suppressed because it is too large
Load Diff
Vendored
+1155
File diff suppressed because it is too large
Load Diff
+785
@@ -0,0 +1,785 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) 2025 Tencent, Inc. All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
***************************************************************************** */
|
||||
|
||||
declare namespace WechatMiniprogram.Component {
|
||||
type FilterUnknownType<T> = {
|
||||
[P in keyof T as string extends P ? never : P]: T[P]
|
||||
}
|
||||
type Instance<
|
||||
TData extends DataOption,
|
||||
TProperty extends PropertyOption,
|
||||
TMethod extends Partial<MethodOption>,
|
||||
TBehavior extends BehaviorOption,
|
||||
TCustomInstanceProperty extends IAnyObject = {},
|
||||
TIsPage extends boolean = false
|
||||
> = InstanceProperties &
|
||||
InstanceMethods<TData> &
|
||||
TMethod &
|
||||
MixinMethods<TBehavior> &
|
||||
(TIsPage extends true ? Page.ILifetime : {}) &
|
||||
Omit<TCustomInstanceProperty, 'properties' | 'methods' | 'data'> & {
|
||||
/** 组件数据,**包括内部数据和属性值** */
|
||||
data: FilterUnknownType<TData> & MixinData<TBehavior> &
|
||||
MixinProperties<TBehavior> & PropertyOptionToData<FilterUnknownType<TProperty>>
|
||||
/** 组件数据,**包括内部数据和属性值**(与 `data` 一致) */
|
||||
properties: FilterUnknownType<TData> & MixinData<TBehavior> &
|
||||
MixinProperties<TBehavior> & PropertyOptionToData<FilterUnknownType<TProperty>>
|
||||
}
|
||||
|
||||
type IEmptyArray = []
|
||||
type TrivialInstance = Instance<
|
||||
IAnyObject,
|
||||
IAnyObject,
|
||||
IAnyObject,
|
||||
IEmptyArray,
|
||||
IAnyObject
|
||||
>
|
||||
type TrivialOption = Options<IAnyObject, IAnyObject, IAnyObject, IEmptyArray, IAnyObject>
|
||||
type Options<
|
||||
TData extends DataOption,
|
||||
TProperty extends PropertyOption,
|
||||
TMethod extends MethodOption,
|
||||
TBehavior extends BehaviorOption,
|
||||
TCustomInstanceProperty extends IAnyObject = {},
|
||||
TIsPage extends boolean = false
|
||||
> = Partial<Data<TData>> &
|
||||
Partial<Property<TProperty>> &
|
||||
Partial<Method<TMethod, TIsPage>> &
|
||||
Partial<Behavior<TBehavior>> &
|
||||
Partial<OtherOption> &
|
||||
Partial<Lifetimes> &
|
||||
ThisType<
|
||||
Instance<
|
||||
TData,
|
||||
TProperty,
|
||||
TMethod,
|
||||
TBehavior,
|
||||
TCustomInstanceProperty,
|
||||
TIsPage
|
||||
>
|
||||
>
|
||||
interface Constructor {
|
||||
<
|
||||
TData extends DataOption,
|
||||
TProperty extends PropertyOption,
|
||||
TMethod extends MethodOption,
|
||||
TBehavior extends BehaviorOption,
|
||||
TCustomInstanceProperty extends IAnyObject = {},
|
||||
TIsPage extends boolean = false
|
||||
>(
|
||||
options: Options<
|
||||
TData,
|
||||
TProperty,
|
||||
TMethod,
|
||||
TBehavior,
|
||||
TCustomInstanceProperty,
|
||||
TIsPage
|
||||
>
|
||||
): string
|
||||
}
|
||||
type DataOption = Record<string, any>
|
||||
type PropertyOption = Record<string, AllProperty>
|
||||
type MethodOption = Record<string, Function>
|
||||
|
||||
type BehaviorOption = Behavior.BehaviorIdentifier[]
|
||||
type ExtractBehaviorType<T> = T extends { BehaviorType?: infer B } ? B : never
|
||||
type ExtractData<T> = T extends { data: infer D } ? D : never
|
||||
type ExtractProperties<T, TIsBehavior extends boolean = false> = T extends { properties: infer P } ?
|
||||
TIsBehavior extends true ? P : PropertyOptionToData<P extends PropertyOption ? P : {}> : never
|
||||
type ExtractMethods<T> = T extends { methods: infer M } ? M : never
|
||||
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never
|
||||
type MixinData<T extends any[]> = UnionToIntersection<ExtractData<ExtractBehaviorType<T[number]>>>
|
||||
type MixinProperties<T extends any[], TIsBehavior extends boolean = false> = UnionToIntersection<ExtractProperties<ExtractBehaviorType<T[number]>, TIsBehavior>>
|
||||
type MixinMethods<T extends any[]> = UnionToIntersection<ExtractMethods<ExtractBehaviorType<T[number]>>>
|
||||
|
||||
interface Behavior<B extends BehaviorOption> {
|
||||
/** 类似于mixins和traits的组件间代码复用机制,参见 [behaviors](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/behaviors.html) */
|
||||
behaviors?: B
|
||||
}
|
||||
|
||||
interface Data<D extends DataOption> {
|
||||
/** 组件的内部数据,和 `properties` 一同用于组件的模板渲染 */
|
||||
data?: D
|
||||
}
|
||||
interface Property<P extends PropertyOption> {
|
||||
/** 组件的对外属性,是属性名到属性设置的映射表 */
|
||||
properties: P
|
||||
}
|
||||
interface Method<M extends MethodOption, TIsPage extends boolean = false> {
|
||||
/** 组件的方法,包括事件响应函数和任意的自定义方法,关于事件响应函数的使用,参见 [组件间通信与事件](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/events.html) */
|
||||
methods: M & (TIsPage extends true ? Partial<Page.ILifetime> : {})
|
||||
}
|
||||
type PropertyType =
|
||||
| StringConstructor
|
||||
| NumberConstructor
|
||||
| BooleanConstructor
|
||||
| ArrayConstructor
|
||||
| ObjectConstructor
|
||||
| null
|
||||
type ValueType<T extends PropertyType> = T extends null
|
||||
? any
|
||||
: T extends StringConstructor
|
||||
? string
|
||||
: T extends NumberConstructor
|
||||
? number
|
||||
: T extends BooleanConstructor
|
||||
? boolean
|
||||
: T extends ArrayConstructor
|
||||
? any[]
|
||||
: T extends ObjectConstructor
|
||||
? IAnyObject
|
||||
: never
|
||||
type FullProperty<T extends PropertyType> = {
|
||||
/** 属性类型 */
|
||||
type: T
|
||||
/** 属性初始值 */
|
||||
value?: ValueType<T>
|
||||
/** 属性值被更改时的响应函数 */
|
||||
observer?:
|
||||
| string
|
||||
| ((
|
||||
newVal: ValueType<T>,
|
||||
oldVal: ValueType<T>,
|
||||
changedPath: Array<string | number>
|
||||
) => void)
|
||||
/** 属性的类型(可以指定多个) */
|
||||
optionalTypes?: ShortProperty[]
|
||||
}
|
||||
type AllFullProperty =
|
||||
| FullProperty<StringConstructor>
|
||||
| FullProperty<NumberConstructor>
|
||||
| FullProperty<BooleanConstructor>
|
||||
| FullProperty<ArrayConstructor>
|
||||
| FullProperty<ObjectConstructor>
|
||||
| FullProperty<null>
|
||||
type ShortProperty =
|
||||
| StringConstructor
|
||||
| NumberConstructor
|
||||
| BooleanConstructor
|
||||
| ArrayConstructor
|
||||
| ObjectConstructor
|
||||
| null
|
||||
type AllProperty = AllFullProperty | ShortProperty
|
||||
type PropertyToData<T extends AllProperty> = T extends ShortProperty
|
||||
? ValueType<T>
|
||||
: FullPropertyToData<Exclude<T, ShortProperty>>
|
||||
type ArrayOrObject = ArrayConstructor | ObjectConstructor
|
||||
type FullPropertyToData<T extends AllFullProperty> = T['type'] extends ArrayOrObject ? unknown extends T['value'] ? ValueType<T['type']> : T['value'] : ValueType<T['type']>
|
||||
type PropertyOptionToData<P extends PropertyOption> = {
|
||||
[name in keyof P]: PropertyToData<P[name]>
|
||||
}
|
||||
|
||||
interface Router {
|
||||
switchTab: Wx['switchTab']
|
||||
reLaunch: Wx['reLaunch']
|
||||
redirectTo: Wx['redirectTo']
|
||||
navigateTo: Wx['navigateTo']
|
||||
navigateBack: Wx['navigateBack']
|
||||
}
|
||||
|
||||
interface InstanceProperties {
|
||||
/** 组件的文件路径 */
|
||||
is: string
|
||||
/** 节点id */
|
||||
id: string
|
||||
/** 节点dataset */
|
||||
dataset: Record<string, string>
|
||||
/** 上一次退出前 onSaveExitState 保存的数据 */
|
||||
exitState: any
|
||||
/** 相对于当前自定义组件的 Router 对象 */
|
||||
router: Router
|
||||
/** 相对于当前自定义组件所在页面的 Router 对象 */
|
||||
pageRouter: Router
|
||||
/** 渲染当前组件的渲染后端 */
|
||||
renderer: 'webview' | 'skyline'
|
||||
}
|
||||
|
||||
interface InstanceMethods<D extends DataOption> {
|
||||
/** `setData` 函数用于将数据从逻辑层发送到视图层
|
||||
*(异步),同时改变对应的 `this.data` 的值(同步)。
|
||||
*
|
||||
* **注意:**
|
||||
*
|
||||
* 1. **直接修改 this.data 而不调用 this.setData 是无法改变页面的状态的,还会造成数据不一致**。
|
||||
* 1. 仅支持设置可 JSON 化的数据。
|
||||
* 1. 单次设置的数据不能超过1024kB,请尽量避免一次设置过多的数据。
|
||||
* 1. 请不要把 data 中任何一项的 value 设为 `undefined` ,否则这一项将不被设置并可能遗留一些潜在问题。
|
||||
*/
|
||||
setData(
|
||||
/** 这次要改变的数据
|
||||
*
|
||||
* 以 `key: value` 的形式表示,将 `this.data` 中的 `key` 对应的值改变成 `value`。
|
||||
*
|
||||
* 其中 `key` 可以以数据路径的形式给出,支持改变数组中的某一项或对象的某个属性,如 `array[2].message`,`a.b.c.d`,并且不需要在 this.data 中预先定义。
|
||||
*/
|
||||
data: Partial<D> & IAnyObject,
|
||||
/** setData引起的界面更新渲染完毕后的回调函数,最低基础库: `1.5.0` */
|
||||
callback?: () => void
|
||||
): void
|
||||
|
||||
/** 检查组件是否具有 `behavior` (检查时会递归检查被直接或间接引入的所有behavior) */
|
||||
hasBehavior(behavior: Behavior.BehaviorIdentifier): void
|
||||
/** 触发事件,参见组件事件 */
|
||||
triggerEvent<DetailType = any>(
|
||||
name: string,
|
||||
detail?: DetailType,
|
||||
options?: TriggerEventOption
|
||||
): void
|
||||
/** 创建一个 SelectorQuery 对象,选择器选取范围为这个组件实例内 */
|
||||
createSelectorQuery(): SelectorQuery
|
||||
/** 创建一个 IntersectionObserver 对象,选择器选取范围为这个组件实例内 */
|
||||
createIntersectionObserver(
|
||||
options: CreateIntersectionObserverOption
|
||||
): IntersectionObserver
|
||||
/** 创建一个 MediaQueryObserver 对象 */
|
||||
createMediaQueryObserver(): MediaQueryObserver
|
||||
/** 使用选择器选择组件实例节点,返回匹配到的第一个组件实例对象(会被 `wx://component-export` 影响) */
|
||||
selectComponent(selector: string): TrivialInstance
|
||||
/** 使用选择器选择组件实例节点,返回匹配到的全部组件实例对象组成的数组 */
|
||||
selectAllComponents(selector: string): TrivialInstance[]
|
||||
/**
|
||||
* 选取当前组件节点所在的组件实例(即组件的引用者),返回它的组件实例对象(会被 `wx://component-export` 影响)
|
||||
*
|
||||
* 最低基础库版本:[`2.8.2`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
|
||||
**/
|
||||
selectOwnerComponent(): TrivialInstance
|
||||
/** 获取这个关系所对应的所有关联节点,参见 组件间关系 */
|
||||
getRelationNodes(relationKey: string): TrivialInstance[]
|
||||
/**
|
||||
* 立刻执行 callback ,其中的多个 setData 之间不会触发界面绘制(只有某些特殊场景中需要,如用于在不同组件同时 setData 时进行界面绘制同步)
|
||||
*
|
||||
* 最低基础库版本:[`2.4.0`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
|
||||
**/
|
||||
groupSetData(callback?: () => void): void
|
||||
/**
|
||||
* 返回当前页面的 custom-tab-bar 的组件实例
|
||||
*
|
||||
* 最低基础库版本:[`2.6.2`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
|
||||
**/
|
||||
getTabBar(): TrivialInstance
|
||||
/**
|
||||
* 返回页面标识符(一个字符串),可以用来判断几个自定义组件实例是不是在同一个页面内
|
||||
*
|
||||
* 最低基础库版本:[`2.7.1`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
|
||||
**/
|
||||
getPageId(): string
|
||||
/**
|
||||
* 执行关键帧动画,详见[动画](https://developers.weixin.qq.com/miniprogram/dev/framework/view/animation.html)
|
||||
*
|
||||
* 最低基础库版本:[`2.9.0`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
|
||||
**/
|
||||
animate(
|
||||
selector: string,
|
||||
keyFrames: KeyFrame[],
|
||||
duration: number,
|
||||
callback?: () => void
|
||||
): void
|
||||
/**
|
||||
* 执行关键帧动画,详见[动画](https://developers.weixin.qq.com/miniprogram/dev/framework/view/animation.html)
|
||||
*
|
||||
* 最低基础库版本:[`2.9.0`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
|
||||
**/
|
||||
animate(
|
||||
selector: string,
|
||||
keyFrames: ScrollTimelineKeyframe[],
|
||||
duration: number,
|
||||
scrollTimeline: ScrollTimelineOption
|
||||
): void
|
||||
/**
|
||||
* 清除关键帧动画,详见[动画](https://developers.weixin.qq.com/miniprogram/dev/framework/view/animation.html)
|
||||
*
|
||||
* 最低基础库版本:[`2.9.0`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
|
||||
**/
|
||||
clearAnimation(selector: string, callback: () => void): void
|
||||
/**
|
||||
* 清除关键帧动画,详见[动画](https://developers.weixin.qq.com/miniprogram/dev/framework/view/animation.html)
|
||||
*
|
||||
* 最低基础库版本:[`2.9.0`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
|
||||
**/
|
||||
clearAnimation(
|
||||
selector: string,
|
||||
options?: ClearAnimationOptions,
|
||||
callback?: () => void
|
||||
): void
|
||||
/**
|
||||
* 当从另一页面跳转到该页面时,获得与来源页面实例通信当事件通道,详见 [wx.navigateTo]((wx.navigateTo))
|
||||
*
|
||||
* 最低基础库版本:[`2.7.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
|
||||
*/
|
||||
getOpenerEventChannel(): EventChannel | EmptyEventChannel
|
||||
/**
|
||||
* 绑定由 worklet 驱动的样式到相应的节点,详见 [worklet 动画](https://developers.weixin.qq.com/miniprogram/dev/framework/runtime/skyline/worklet.html)
|
||||
*
|
||||
* 最低基础库版本:[`2.29.0`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
|
||||
*/
|
||||
applyAnimatedStyle(
|
||||
selector: string,
|
||||
updater: () => Record<string, string>,
|
||||
userConfig?: { immediate: boolean, flush: 'sync' | 'async' },
|
||||
callback?: (res: { styleId: number }) => void
|
||||
): void
|
||||
/**
|
||||
* 清除节点上 worklet 驱动样式的绑定关系
|
||||
*
|
||||
* 最低基础库版本:[`2.30.1`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
|
||||
*/
|
||||
clearAnimatedStyle(
|
||||
selector: string,
|
||||
styleIds: number[],
|
||||
callback?: () => void
|
||||
): void
|
||||
/**
|
||||
* 获取更新性能统计信息,详见 [获取更新性能统计信息]((custom-component/update-perf-stat))
|
||||
*
|
||||
*
|
||||
* 最低基础库版本:[`2.12.0`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
|
||||
*/
|
||||
setUpdatePerformanceListener<WithDataPath extends boolean = false>(
|
||||
options: SetUpdatePerformanceListenerOption<WithDataPath>,
|
||||
callback?: UpdatePerformanceListener<WithDataPath>
|
||||
): void
|
||||
|
||||
/**
|
||||
* 在运行时获取页面或组件所在页面 `touch` 相关事件的 passive 配置,详见 [enablePassiveEvent]((configuration/app#enablePassiveEvent))
|
||||
*
|
||||
* 最低基础库版本:[`2.25.1`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
|
||||
*/
|
||||
getPassiveEvent(callback: (config: PassiveConfig) => void): void
|
||||
/**
|
||||
* 在运行时切换页面或组件所在页面 `touch` 相关事件的 passive 配置,详见 [enablePassiveEvent]((configuration/app#enablePassiveEvent))
|
||||
*
|
||||
* 最低基础库版本:[`2.25.1`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
|
||||
*/
|
||||
setPassiveEvent(config: PassiveConfig): void
|
||||
/**
|
||||
* 设置初始渲染缓存的动态数据
|
||||
*
|
||||
* 最低基础库版本:[`2.11.1`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
|
||||
*/
|
||||
setInitialRenderingCache(dynamicData: IAnyObject | null): void
|
||||
/**
|
||||
* 返回当前页面的 appBar 组件实例
|
||||
*
|
||||
* 最低基础库版本:[`3.3.1`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
|
||||
*/
|
||||
getAppBar(): TrivialInstance
|
||||
}
|
||||
|
||||
interface ComponentOptions {
|
||||
/**
|
||||
* [启用多slot支持](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/wxml-wxss.html#组件wxml的slot)
|
||||
*/
|
||||
multipleSlots?: boolean
|
||||
/**
|
||||
* [组件样式隔离](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/wxml-wxss.html#组件样式隔离)
|
||||
*/
|
||||
addGlobalClass?: boolean
|
||||
/**
|
||||
* [组件样式隔离](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/wxml-wxss.html#组件样式隔离)
|
||||
*/
|
||||
styleIsolation?:
|
||||
| 'isolated'
|
||||
| 'apply-shared'
|
||||
| 'shared'
|
||||
| 'page-isolated'
|
||||
| 'page-apply-shared'
|
||||
| 'page-shared'
|
||||
/**
|
||||
* [纯数据字段](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/pure-data.html) 是一些不用于界面渲染的 data 字段,可以用于提升页面更新性能。从小程序基础库版本 2.8.2 开始支持。
|
||||
*/
|
||||
pureDataPattern?: RegExp
|
||||
/**
|
||||
* [虚拟化组件节点](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/wxml-wxss.html#%E8%99%9A%E6%8B%9F%E5%8C%96%E7%BB%84%E4%BB%B6%E8%8A%82%E7%82%B9) 使自定义组件内部的第一层节点由自定义组件本身完全决定。从小程序基础库版本 [`2.11.2`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html) 开始支持 */
|
||||
virtualHost?: boolean
|
||||
}
|
||||
|
||||
interface TriggerEventOption {
|
||||
/** 事件是否冒泡
|
||||
*
|
||||
* 默认值: `false`
|
||||
*/
|
||||
bubbles?: boolean
|
||||
/** 事件是否可以穿越组件边界,为false时,事件将只能在引用组件的节点树上触发,不进入其他任何组件内部
|
||||
*
|
||||
* 默认值: `false`
|
||||
*/
|
||||
composed?: boolean
|
||||
/** 事件是否拥有捕获阶段
|
||||
*
|
||||
* 默认值: `false`
|
||||
*/
|
||||
capturePhase?: boolean
|
||||
}
|
||||
|
||||
interface RelationOption {
|
||||
/** 目标组件的相对关系 */
|
||||
type: 'parent' | 'child' | 'ancestor' | 'descendant'
|
||||
/** 关系生命周期函数,当关系被建立在页面节点树中时触发,触发时机在组件attached生命周期之后 */
|
||||
linked?(target: TrivialInstance): void
|
||||
/** 关系生命周期函数,当关系在页面节点树中发生改变时触发,触发时机在组件moved生命周期之后 */
|
||||
linkChanged?(target: TrivialInstance): void
|
||||
/** 关系生命周期函数,当关系脱离页面节点树时触发,触发时机在组件detached生命周期之后 */
|
||||
unlinked?(target: TrivialInstance): void
|
||||
/** 如果这一项被设置,则它表示关联的目标节点所应具有的behavior,所有拥有这一behavior的组件节点都会被关联 */
|
||||
target?: string
|
||||
}
|
||||
|
||||
interface PageLifetimes {
|
||||
/** 页面生命周期回调—监听页面显示
|
||||
*
|
||||
* 页面显示/切入前台时触发。
|
||||
*/
|
||||
show(): void
|
||||
/** 页面生命周期回调—监听页面隐藏
|
||||
*
|
||||
* 页面隐藏/切入后台时触发。 如 `navigateTo` 或底部 `tab` 切换到其他页面,小程序切入后台等。
|
||||
*/
|
||||
hide(): void
|
||||
/** 页面生命周期回调—监听页面尺寸变化
|
||||
*
|
||||
* 所在页面尺寸变化时执行
|
||||
*/
|
||||
resize(size: Page.IResizeOption): void
|
||||
/** 页面生命周期回调—监听页面路由动画完成
|
||||
*
|
||||
* 所在页面路由动画完成时执行
|
||||
*/
|
||||
routeDone(): void
|
||||
}
|
||||
|
||||
type DefinitionFilter = <T extends TrivialOption>(
|
||||
/** 使用该 behavior 的 component/behavior 的定义对象 */
|
||||
defFields: T,
|
||||
/** 该 behavior 所使用的 behavior 的 definitionFilter 函数列表 */
|
||||
definitionFilterArr?: DefinitionFilter[]
|
||||
) => void
|
||||
|
||||
interface Lifetimes {
|
||||
/** 组件生命周期声明对象,组件的生命周期:`created`、`attached`、`ready`、`moved`、`detached` 将收归到 `lifetimes` 字段内进行声明,原有声明方式仍旧有效,如同时存在两种声明方式,则 `lifetimes` 字段内声明方式优先级最高
|
||||
*
|
||||
* 最低基础库: `2.2.3` */
|
||||
lifetimes: Partial<{
|
||||
/**
|
||||
* 在组件实例刚刚被创建时执行,注意此时不能调用 `setData`
|
||||
*
|
||||
* 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
|
||||
*/
|
||||
created(): void
|
||||
/**
|
||||
* 在组件实例进入页面节点树时执行
|
||||
*
|
||||
* 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
|
||||
*/
|
||||
attached(): void
|
||||
/**
|
||||
* 在组件在视图层布局完成后执行
|
||||
*
|
||||
* 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
|
||||
*/
|
||||
ready(): void
|
||||
/**
|
||||
* 在组件实例被移动到节点树另一个位置时执行
|
||||
*
|
||||
* 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
|
||||
*/
|
||||
moved(): void
|
||||
/**
|
||||
* 在组件实例被从页面节点树移除时执行
|
||||
*
|
||||
* 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
|
||||
*/
|
||||
detached(): void
|
||||
/**
|
||||
* 每当组件方法抛出错误时执行
|
||||
*
|
||||
* 最低基础库版本:[`2.4.1`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
|
||||
*/
|
||||
error(err: Error): void
|
||||
}>
|
||||
/**
|
||||
* @deprecated 旧式的定义方式,基础库 `2.2.3` 起请在 lifetimes 中定义
|
||||
*
|
||||
* 在组件实例刚刚被创建时执行
|
||||
*
|
||||
* 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
|
||||
*/
|
||||
created(): void
|
||||
/**
|
||||
* @deprecated 旧式的定义方式,基础库 `2.2.3` 起请在 lifetimes 中定义
|
||||
*
|
||||
* 在组件实例进入页面节点树时执行
|
||||
*
|
||||
* 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
|
||||
*/
|
||||
attached(): void
|
||||
/**
|
||||
* @deprecated 旧式的定义方式,基础库 `2.2.3` 起请在 lifetimes 中定义
|
||||
*
|
||||
* 在组件在视图层布局完成后执行
|
||||
*
|
||||
* 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
|
||||
*/
|
||||
ready(): void
|
||||
/**
|
||||
* @deprecated 旧式的定义方式,基础库 `2.2.3` 起请在 lifetimes 中定义
|
||||
*
|
||||
* 在组件实例被移动到节点树另一个位置时执行
|
||||
*
|
||||
* 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
|
||||
*/
|
||||
moved(): void
|
||||
/**
|
||||
* @deprecated 旧式的定义方式,基础库 `2.2.3` 起请在 lifetimes 中定义
|
||||
*
|
||||
* 在组件实例被从页面节点树移除时执行
|
||||
*
|
||||
* 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
|
||||
*/
|
||||
detached(): void
|
||||
/**
|
||||
* @deprecated 旧式的定义方式,基础库 `2.2.3` 起请在 lifetimes 中定义
|
||||
*
|
||||
* 每当组件方法抛出错误时执行
|
||||
*
|
||||
* 最低基础库版本:[`2.4.1`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
|
||||
*/
|
||||
error(err: Error): void
|
||||
}
|
||||
|
||||
interface OtherOption {
|
||||
/**
|
||||
* 组件数据字段监听器,用于监听 properties 和 data 的变化,参见 [数据监听器](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/observer.html)
|
||||
*
|
||||
* 最低基础库版本:[`2.6.1`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
|
||||
*/
|
||||
observers: Record<string, (...args: any[]) => any>
|
||||
/** 组件间关系定义,参见 [组件间关系](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/lifetimes.html) */
|
||||
relations: {
|
||||
[componentName: string]: RelationOption
|
||||
}
|
||||
/** 组件接受的外部样式类,参见 [外部样式类](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/wxml-wxss.html) */
|
||||
externalClasses?: string[]
|
||||
/** 组件所在页面的生命周期声明对象,参见 [组件生命周期](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/lifetimes.html)
|
||||
*
|
||||
* 最低基础库版本: [`2.2.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html) */
|
||||
pageLifetimes?: Partial<PageLifetimes>
|
||||
/** 一些选项(文档中介绍相关特性时会涉及具体的选项设置,这里暂不列举) */
|
||||
options: ComponentOptions
|
||||
|
||||
/** 定义段过滤器,用于自定义组件扩展,参见 [自定义组件扩展](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/extend.html)
|
||||
*
|
||||
* 最低基础库版本: [`2.2.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html) */
|
||||
definitionFilter?: DefinitionFilter
|
||||
/**
|
||||
* 组件自定义导出,当使用 `behavior: wx://component-export` 时,这个定义段可以用于指定组件被 selectComponent 调用时的返回值,参见 [组件间通信与事件](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/events.html)
|
||||
* 最低基础库版本: [`2.2.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html) */
|
||||
export: () => IAnyObject
|
||||
}
|
||||
|
||||
interface KeyFrame {
|
||||
/** 关键帧的偏移,范围[0-1] */
|
||||
offset?: number
|
||||
/** 动画缓动函数 */
|
||||
ease?: string
|
||||
/** 基点位置,即 CSS transform-origin */
|
||||
transformOrigin?: string
|
||||
/** 背景颜色,即 CSS background-color */
|
||||
backgroundColor?: string
|
||||
/** 底边位置,即 CSS bottom */
|
||||
bottom?: number | string
|
||||
/** 高度,即 CSS height */
|
||||
height?: number | string
|
||||
/** 左边位置,即 CSS left */
|
||||
left?: number | string
|
||||
/** 宽度,即 CSS width */
|
||||
width?: number | string
|
||||
/** 不透明度,即 CSS opacity */
|
||||
opacity?: number | string
|
||||
/** 右边位置,即 CSS right */
|
||||
right?: number | string
|
||||
/** 顶边位置,即 CSS top */
|
||||
top?: number | string
|
||||
/** 变换矩阵,即 CSS transform matrix */
|
||||
matrix?: number[]
|
||||
/** 三维变换矩阵,即 CSS transform matrix3d */
|
||||
matrix3d?: number[]
|
||||
/** 旋转,即 CSS transform rotate */
|
||||
rotate?: number
|
||||
/** 三维旋转,即 CSS transform rotate3d */
|
||||
rotate3d?: number[]
|
||||
/** X 方向旋转,即 CSS transform rotateX */
|
||||
rotateX?: number
|
||||
/** Y 方向旋转,即 CSS transform rotateY */
|
||||
rotateY?: number
|
||||
/** Z 方向旋转,即 CSS transform rotateZ */
|
||||
rotateZ?: number
|
||||
/** 缩放,即 CSS transform scale */
|
||||
scale?: number[]
|
||||
/** 三维缩放,即 CSS transform scale3d */
|
||||
scale3d?: number[]
|
||||
/** X 方向缩放,即 CSS transform scaleX */
|
||||
scaleX?: number
|
||||
/** Y 方向缩放,即 CSS transform scaleY */
|
||||
scaleY?: number
|
||||
/** Z 方向缩放,即 CSS transform scaleZ */
|
||||
scaleZ?: number
|
||||
/** 倾斜,即 CSS transform skew */
|
||||
skew?: number[]
|
||||
/** X 方向倾斜,即 CSS transform skewX */
|
||||
skewX?: number
|
||||
/** Y 方向倾斜,即 CSS transform skewY */
|
||||
skewY?: number
|
||||
/** 位移,即 CSS transform translate */
|
||||
translate?: Array<number | string>
|
||||
/** 三维位移,即 CSS transform translate3d */
|
||||
translate3d?: Array<number | string>
|
||||
/** X 方向位移,即 CSS transform translateX */
|
||||
translateX?: number | string
|
||||
/** Y 方向位移,即 CSS transform translateY */
|
||||
translateY?: number | string
|
||||
/** Z 方向位移,即 CSS transform translateZ */
|
||||
translateZ?: number | string
|
||||
}
|
||||
interface ClearAnimationOptions {
|
||||
/** 基点位置,即 CSS transform-origin */
|
||||
transformOrigin?: boolean
|
||||
/** 背景颜色,即 CSS background-color */
|
||||
backgroundColor?: boolean
|
||||
/** 底边位置,即 CSS bottom */
|
||||
bottom?: boolean
|
||||
/** 高度,即 CSS height */
|
||||
height?: boolean
|
||||
/** 左边位置,即 CSS left */
|
||||
left?: boolean
|
||||
/** 宽度,即 CSS width */
|
||||
width?: boolean
|
||||
/** 不透明度,即 CSS opacity */
|
||||
opacity?: boolean
|
||||
/** 右边位置,即 CSS right */
|
||||
right?: boolean
|
||||
/** 顶边位置,即 CSS top */
|
||||
top?: boolean
|
||||
/** 变换矩阵,即 CSS transform matrix */
|
||||
matrix?: boolean
|
||||
/** 三维变换矩阵,即 CSS transform matrix3d */
|
||||
matrix3d?: boolean
|
||||
/** 旋转,即 CSS transform rotate */
|
||||
rotate?: boolean
|
||||
/** 三维旋转,即 CSS transform rotate3d */
|
||||
rotate3d?: boolean
|
||||
/** X 方向旋转,即 CSS transform rotateX */
|
||||
rotateX?: boolean
|
||||
/** Y 方向旋转,即 CSS transform rotateY */
|
||||
rotateY?: boolean
|
||||
/** Z 方向旋转,即 CSS transform rotateZ */
|
||||
rotateZ?: boolean
|
||||
/** 缩放,即 CSS transform scale */
|
||||
scale?: boolean
|
||||
/** 三维缩放,即 CSS transform scale3d */
|
||||
scale3d?: boolean
|
||||
/** X 方向缩放,即 CSS transform scaleX */
|
||||
scaleX?: boolean
|
||||
/** Y 方向缩放,即 CSS transform scaleY */
|
||||
scaleY?: boolean
|
||||
/** Z 方向缩放,即 CSS transform scaleZ */
|
||||
scaleZ?: boolean
|
||||
/** 倾斜,即 CSS transform skew */
|
||||
skew?: boolean
|
||||
/** X 方向倾斜,即 CSS transform skewX */
|
||||
skewX?: boolean
|
||||
/** Y 方向倾斜,即 CSS transform skewY */
|
||||
skewY?: boolean
|
||||
/** 位移,即 CSS transform translate */
|
||||
translate?: boolean
|
||||
/** 三维位移,即 CSS transform translate3d */
|
||||
translate3d?: boolean
|
||||
/** X 方向位移,即 CSS transform translateX */
|
||||
translateX?: boolean
|
||||
/** Y 方向位移,即 CSS transform translateY */
|
||||
translateY?: boolean
|
||||
/** Z 方向位移,即 CSS transform translateZ */
|
||||
translateZ?: boolean
|
||||
}
|
||||
interface ScrollTimelineKeyframe {
|
||||
composite?: 'replace' | 'add' | 'accumulate' | 'auto'
|
||||
easing?: string
|
||||
offset?: number | null
|
||||
[property: string]: string | number | null | undefined
|
||||
}
|
||||
interface ScrollTimelineOption {
|
||||
/** 指定滚动元素的选择器(只支持 scroll-view),该元素滚动时会驱动动画的进度 */
|
||||
scrollSource: string
|
||||
/** 指定滚动的方向。有效值为 horizontal 或 vertical */
|
||||
orientation?: string
|
||||
/** 指定开始驱动动画进度的滚动偏移量,单位 px */
|
||||
startScrollOffset: number
|
||||
/** 指定停止驱动动画进度的滚动偏移量,单位 px */
|
||||
endScrollOffset: number
|
||||
/** 起始和结束的滚动范围映射的时间长度,该时间可用于与关键帧动画里的时间 (duration) 相匹配,单位 ms */
|
||||
timeRange: number
|
||||
}
|
||||
|
||||
interface SetUpdatePerformanceListenerOption<WithDataPath> {
|
||||
/** 是否返回变更的 data 字段信息 */
|
||||
withDataPaths?: WithDataPath
|
||||
}
|
||||
interface UpdatePerformanceListener<WithDataPath> {
|
||||
(res: UpdatePerformance<WithDataPath>): void
|
||||
}
|
||||
interface UpdatePerformance<WithDataPath> {
|
||||
/** 此次更新过程的 ID */
|
||||
updateProcessId: number
|
||||
/** 对于子更新,返回它所属的更新过程 ID */
|
||||
parentUpdateProcessId?: number
|
||||
/** 是否是被合并更新,如果是,则 updateProcessId 表示被合并到的更新过程 ID */
|
||||
isMergedUpdate: boolean
|
||||
/** 此次更新的 data 字段信息,只有 withDataPaths 设为 true 时才会返回 */
|
||||
dataPaths: WithDataPath extends true ? string[] : undefined
|
||||
/** 此次更新进入等待队列时的时间戳 */
|
||||
pendingStartTimestamp: number
|
||||
/** 更新运算开始时的时间戳 */
|
||||
updateStartTimestamp: number
|
||||
/** 更新运算结束时的时间戳 */
|
||||
updateEndTimestamp: number
|
||||
}
|
||||
|
||||
type PassiveConfig =
|
||||
| {
|
||||
/** 是否设置 touchmove 事件为 passive,默认为 `false` */
|
||||
touchmove?: boolean
|
||||
/** 是否设置 touchstart 事件为 passive,默认为 `false` */
|
||||
touchstart?: boolean
|
||||
/** 是否设置 wheel 事件为 passive,默认为 `false` */
|
||||
wheel?: boolean
|
||||
}
|
||||
| boolean
|
||||
}
|
||||
/** Component构造器可用于定义组件,调用Component构造器时可以指定组件的属性、数据、方法等。
|
||||
*
|
||||
* * 使用 `this.data` 可以获取内部数据和属性值,但不要直接修改它们,应使用 `setData` 修改。
|
||||
* * 生命周期函数无法在组件方法中通过 `this` 访问到。
|
||||
* * 属性名应避免以 data 开头,即不要命名成 `dataXyz` 这样的形式,因为在 WXML 中, `data-xyz=""` 会被作为节点 dataset 来处理,而不是组件属性。
|
||||
* * 在一个组件的定义和使用时,组件的属性名和 data 字段相互间都不能冲突(尽管它们位于不同的定义段中)。
|
||||
* * 从基础库 `2.0.9` 开始,对象类型的属性和 data 字段中可以包含函数类型的子字段,即可以通过对象类型的属性字段来传递函数。低于这一版本的基础库不支持这一特性。
|
||||
* * `bug` : 对于 type 为 Object 或 Array 的属性,如果通过该组件自身的 `this.setData` 来改变属性值的一个子字段,则依旧会触发属性 observer ,且 observer 接收到的 `newVal` 是变化的那个子字段的值, `oldVal` 为空, `changedPath` 包含子字段的字段名相关信息。
|
||||
*/
|
||||
declare let Component: WechatMiniprogram.Component.Constructor
|
||||
Vendored
+1436
File diff suppressed because it is too large
Load Diff
Vendored
+299
@@ -0,0 +1,299 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) 2025 Tencent, Inc. All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
***************************************************************************** */
|
||||
|
||||
declare namespace WechatMiniprogram.Page {
|
||||
type Instance<
|
||||
TData extends DataOption,
|
||||
TCustom extends CustomOption
|
||||
> = OptionalInterface<ILifetime> &
|
||||
InstanceProperties &
|
||||
InstanceMethods<TData> &
|
||||
Data<TData> &
|
||||
TCustom
|
||||
type Options<
|
||||
TData extends DataOption,
|
||||
TCustom extends CustomOption
|
||||
> = (TCustom &
|
||||
Partial<Data<TData>> &
|
||||
Partial<ILifetime> & {
|
||||
options?: Component.ComponentOptions
|
||||
}) &
|
||||
ThisType<Instance<TData, TCustom>>
|
||||
type TrivialInstance = Instance<IAnyObject, IAnyObject>
|
||||
interface Constructor {
|
||||
<TData extends DataOption, TCustom extends CustomOption>(
|
||||
options: Options<TData, TCustom>
|
||||
): void
|
||||
}
|
||||
interface ILifetime {
|
||||
/** 生命周期回调—监听页面加载
|
||||
*
|
||||
* 页面加载时触发。一个页面只会调用一次,可以在 onLoad 的参数中获取打开当前页面路径中的参数。
|
||||
*/
|
||||
onLoad(
|
||||
/** 打开当前页面路径中的参数 */
|
||||
query: Record<string, string | undefined>
|
||||
): void | Promise<void>
|
||||
/** 生命周期回调—监听页面显示
|
||||
*
|
||||
* 页面显示/切入前台时触发。
|
||||
*/
|
||||
onShow(): void | Promise<void>
|
||||
/** 生命周期回调—监听页面初次渲染完成
|
||||
*
|
||||
* 页面初次渲染完成时触发。一个页面只会调用一次,代表页面已经准备妥当,可以和视图层进行交互。
|
||||
*
|
||||
|
||||
* 注意:对界面内容进行设置的 API 如`wx.setNavigationBarTitle`,请在`onReady`之后进行。
|
||||
*/
|
||||
onReady(): void | Promise<void>
|
||||
/** 生命周期回调—监听页面隐藏
|
||||
*
|
||||
* 页面隐藏/切入后台时触发。 如 `navigateTo` 或底部 `tab` 切换到其他页面,小程序切入后台等。
|
||||
*/
|
||||
onHide(): void | Promise<void>
|
||||
/** 生命周期回调—监听页面卸载
|
||||
*
|
||||
* 页面卸载时触发。如`redirectTo`或`navigateBack`到其他页面时。
|
||||
*/
|
||||
onUnload(): void | Promise<void>
|
||||
/** 生命周期回调—监听路由动画完成
|
||||
*
|
||||
* 路由动画完成时触发。如 wx.navigateTo 页面完全推入后 或 wx.navigateBack 页面完全恢复时。
|
||||
*/
|
||||
onRouteDone(): void | Promise<void>
|
||||
/** 监听用户下拉动作
|
||||
*
|
||||
* 监听用户下拉刷新事件。
|
||||
* - 需要在`app.json`的`window`选项中或页面配置中开启`enablePullDownRefresh`。
|
||||
* - 可以通过`wx.startPullDownRefresh`触发下拉刷新,调用后触发下拉刷新动画,效果与用户手动下拉刷新一致。
|
||||
* - 当处理完数据刷新后,`wx.stopPullDownRefresh`可以停止当前页面的下拉刷新。
|
||||
*/
|
||||
onPullDownRefresh(): void | Promise<void>
|
||||
/** 页面上拉触底事件的处理函数
|
||||
*
|
||||
* 监听用户上拉触底事件。
|
||||
* - 可以在`app.json`的`window`选项中或页面配置中设置触发距离`onReachBottomDistance`。
|
||||
* - 在触发距离内滑动期间,本事件只会被触发一次。
|
||||
*/
|
||||
onReachBottom(): void | Promise<void>
|
||||
/** 用户点击右上角转发
|
||||
*
|
||||
* 监听用户点击页面内转发按钮(`<button>` 组件 `open-type="share"`)或右上角菜单“转发”按钮的行为,并自定义转发内容。
|
||||
*
|
||||
* **注意:只有定义了此事件处理函数,右上角菜单才会显示“转发”按钮**
|
||||
*
|
||||
* 此事件需要 return 一个 Object,用于自定义转发内容
|
||||
*/
|
||||
onShareAppMessage(
|
||||
/** 分享发起来源参数 */
|
||||
options: IShareAppMessageOption
|
||||
):
|
||||
| ICustomShareContent
|
||||
| IAsyncCustomShareContent
|
||||
| Promise<ICustomShareContent>
|
||||
| void
|
||||
| Promise<void>
|
||||
/**
|
||||
* 监听右上角菜单“分享到朋友圈”按钮的行为,并自定义分享内容
|
||||
*
|
||||
* 本接口为 Beta 版本,暂只在 Android 平台支持,详见 [分享到朋友圈 (Beta)](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/share-timeline.html)
|
||||
*
|
||||
* 基础库 2.11.3 开始支持,低版本需做兼容处理。
|
||||
*/
|
||||
onShareTimeline(): ICustomTimelineContent | void
|
||||
|
||||
/** 页面滚动触发事件的处理函数
|
||||
*
|
||||
* 监听用户滑动页面事件。
|
||||
*/
|
||||
onPageScroll(
|
||||
/** 页面滚动参数 */
|
||||
options: IPageScrollOption
|
||||
): void | Promise<void>
|
||||
|
||||
/** 当前是 tab 页时,点击 tab 时触发,最低基础库: `1.9.0` */
|
||||
onTabItemTap(
|
||||
/** tab 点击参数 */
|
||||
options: ITabItemTapOption
|
||||
): void | Promise<void>
|
||||
|
||||
/** 窗口尺寸改变时触发,最低基础库:`2.4.0` */
|
||||
onResize(
|
||||
/** 窗口尺寸参数 */
|
||||
options: IResizeOption
|
||||
): void | Promise<void>
|
||||
|
||||
/**
|
||||
* 监听用户点击右上角菜单“收藏”按钮的行为,并自定义收藏内容。
|
||||
* 基础库 2.10.3,安卓 7.0.15 版本起支持,iOS 暂不支持
|
||||
*/
|
||||
onAddToFavorites(options: IAddToFavoritesOption): IAddToFavoritesContent
|
||||
|
||||
/** 每当小程序可能被销毁之前会被调用,可以进行退出状态的保存。最低基础库: `2.7.4` */
|
||||
onSaveExitState(): ISaveExitState
|
||||
}
|
||||
interface InstanceProperties {
|
||||
/** 页面的文件路径 */
|
||||
is: string
|
||||
|
||||
/** 到当前页面的路径 */
|
||||
route: string
|
||||
|
||||
/** 打开当前页面路径中的参数 */
|
||||
options: Record<string, string | undefined>
|
||||
|
||||
/** 上一次退出前 onSaveExitState 保存的数据 */
|
||||
exitState: any
|
||||
|
||||
/** 相对于当前页面的 Router 对象 */
|
||||
router: Component.Router
|
||||
|
||||
/** 相对于当前页面的 Router 对象 */
|
||||
pageRouter: Component.Router
|
||||
|
||||
/** 渲染当前页面的渲染后端 */
|
||||
renderer: 'webview' | 'skyline'
|
||||
}
|
||||
|
||||
type DataOption = Record<string, any>
|
||||
type CustomOption = Record<string, any>
|
||||
|
||||
type InstanceMethods<D extends DataOption> = Component.InstanceMethods<D>
|
||||
|
||||
interface Data<D extends DataOption> {
|
||||
/** 页面的初始数据
|
||||
*
|
||||
* `data` 是页面第一次渲染使用的**初始数据**。
|
||||
*
|
||||
* 页面加载时,`data` 将会以`JSON`字符串的形式由逻辑层传至渲染层,因此`data`中的数据必须是可以转成`JSON`的类型:字符串,数字,布尔值,对象,数组。
|
||||
*
|
||||
* 渲染层可以通过 `WXML` 对数据进行绑定。
|
||||
*/
|
||||
data: D
|
||||
}
|
||||
|
||||
interface ICustomShareContent {
|
||||
/** 转发标题。默认值:当前小程序名称 */
|
||||
title?: string
|
||||
/** 转发路径,必须是以 / 开头的完整路径。默认值:当前页面 path */
|
||||
path?: string
|
||||
/** 自定义图片路径,可以是本地文件路径、代码包文件路径或者网络图片路径。支持PNG及JPG。显示图片长宽比是 5:4,最低基础库: `1.5.0`。默认值:使用默认截图 */
|
||||
imageUrl?: string
|
||||
}
|
||||
|
||||
interface IAsyncCustomShareContent extends ICustomShareContent {
|
||||
promise: Promise<ICustomShareContent>
|
||||
}
|
||||
|
||||
interface ICustomTimelineContent {
|
||||
/** 自定义标题,即朋友圈列表页上显示的标题。默认值:当前小程序名称 */
|
||||
title?: string
|
||||
/** 自定义页面路径中携带的参数,如 `path?a=1&b=2` 的 “?” 后面部分 默认值:当前页面路径携带的参数 */
|
||||
query?: string
|
||||
/** 自定义图片路径,可以是本地文件路径、代码包文件路径或者网络图片路径。支持 PNG 及 JPG。显示图片长宽比是 1:1。默认值:默认使用小程序 Logo*/
|
||||
imageUrl?: string
|
||||
}
|
||||
|
||||
interface IPageScrollOption {
|
||||
/** 页面在垂直方向已滚动的距离(单位px) */
|
||||
scrollTop: number
|
||||
}
|
||||
|
||||
interface IShareAppMessageOption {
|
||||
/** 转发事件来源。
|
||||
*
|
||||
* 可选值:
|
||||
* - `button`:页面内转发按钮;
|
||||
* - `menu`:右上角转发菜单。
|
||||
*
|
||||
* 最低基础库: `1.2.4`
|
||||
*/
|
||||
from: 'button' | 'menu'
|
||||
/** 如果 `from` 值是 `button`,则 `target` 是触发这次转发事件的 `button`,否则为 `undefined`
|
||||
*
|
||||
* 最低基础库: `1.2.4` */
|
||||
target: any
|
||||
/** 页面中包含`<web-view>`组件时,返回当前`<web-view>`的url
|
||||
*
|
||||
* 最低基础库: `1.6.4`
|
||||
*/
|
||||
webViewUrl?: string
|
||||
}
|
||||
|
||||
interface ITabItemTapOption {
|
||||
/** 被点击tabItem的序号,从0开始,最低基础库: `1.9.0` */
|
||||
index: string
|
||||
/** 被点击tabItem的页面路径,最低基础库: `1.9.0` */
|
||||
pagePath: string
|
||||
/** 被点击tabItem的按钮文字,最低基础库: `1.9.0` */
|
||||
text: string
|
||||
}
|
||||
|
||||
interface IResizeOption {
|
||||
size: {
|
||||
/** 变化后的窗口宽度,单位 px */
|
||||
windowWidth: number
|
||||
/** 变化后的窗口高度,单位 px */
|
||||
windowHeight: number
|
||||
}
|
||||
}
|
||||
|
||||
interface IAddToFavoritesOption {
|
||||
/** 页面中包含web-view组件时,返回当前web-view的url */
|
||||
webviewUrl?: string
|
||||
}
|
||||
|
||||
interface IAddToFavoritesContent {
|
||||
/** 自定义标题,默认值:页面标题或账号名称 */
|
||||
title?: string
|
||||
/** 自定义图片,显示图片长宽比为 1:1,默认值:页面截图 */
|
||||
imageUrl?: string
|
||||
/** 自定义query字段,默认值:当前页面的query */
|
||||
query?: string
|
||||
}
|
||||
|
||||
interface ISaveExitState {
|
||||
/** 需要保存的数据(只能是 JSON 兼容的数据) */
|
||||
data: any
|
||||
/** 超时时刻,在这个时刻后,保存的数据保证一定被丢弃,默认为 (当前时刻 + 1 天) */
|
||||
expireTimeStamp?: number
|
||||
}
|
||||
|
||||
interface GetCurrentPages {
|
||||
(): Array<Instance<IAnyObject, IAnyObject>>
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册小程序中的一个页面。接受一个 `Object` 类型参数,其指定页面的初始数据、生命周期回调、事件处理函数等。
|
||||
*/
|
||||
declare let Page: WechatMiniprogram.Page.Constructor
|
||||
/**
|
||||
* 获取当前页面栈。数组中第一个元素为首页,最后一个元素为当前页面。
|
||||
|
||||
* __注意:__
|
||||
|
||||
* - __不要尝试修改页面栈,会导致路由以及页面状态错误。__
|
||||
* - 不要在 `App.onLaunch` 的时候调用 `getCurrentPages()`,此时 `page` 还没有生成。
|
||||
*/
|
||||
declare let getCurrentPages: WechatMiniprogram.Page.GetCurrentPages
|
||||
Vendored
+409
@@ -0,0 +1,409 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) 2025 Tencent, Inc. All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
***************************************************************************** */
|
||||
|
||||
declare namespace phys3D {
|
||||
// pvd调试配置
|
||||
export interface PhysicsDebugConfig {
|
||||
isNetwork: boolean // 采用网络的方式
|
||||
ip?: string // 如果isNetwork为true,调试信息会通过tcp转发的方式转发到打开了pvd调试软件的电脑,需要注意的是,防火墙要对pvd打开
|
||||
port?: 5425 // pvd默认接口
|
||||
timeout?: 1000 // 默认耗时
|
||||
path?: string // 如果isNetwork为false,调试信息会通过写本地文件的方式落地,文件名建议为xxx.pxd2,导入pvd调试即可
|
||||
}
|
||||
|
||||
export enum QueryTriggerInteraction {
|
||||
UseGlobal = 0,
|
||||
Ignore = 1,
|
||||
Collide = 2
|
||||
}
|
||||
|
||||
export class PhysSystem {
|
||||
constructor(config?: PhysicsDebugConfig)
|
||||
gravity: RawVec3f
|
||||
bounceThreshold: number
|
||||
defaultMaxAngularSpeed: number
|
||||
defaultSolverIterations: number
|
||||
defaultSolverVelocityIterations: number
|
||||
sleepThreshold: number
|
||||
defaultContactOffset: number
|
||||
destroyScene: () => void
|
||||
createScene: () => number
|
||||
Simulate: (step: number) => void
|
||||
SyncFromTransforms: (() => void) | undefined // added in 2021.06
|
||||
SetCollisionMask: (mask: ArrayBuffer) => void
|
||||
Raycast: (
|
||||
origin: RawVec3f,
|
||||
unitDir: RawVec3f,
|
||||
distance: number,
|
||||
hit: RaycastHit,
|
||||
layerMask?: number,
|
||||
queryTriggerInteraction?: QueryTriggerInteraction
|
||||
) => boolean
|
||||
RaycastAll: (
|
||||
origin: RawVec3f,
|
||||
unitDir: RawVec3f,
|
||||
distance: number,
|
||||
layerMask?: number,
|
||||
queryTriggerInteraction?: QueryTriggerInteraction
|
||||
) => RaycastHit[]
|
||||
CapsuleCast(
|
||||
p1: RawVec3f,
|
||||
p2: RawVec3f,
|
||||
radius: number,
|
||||
direction: RawVec3f,
|
||||
hit: RaycastHit,
|
||||
maxDistance: number,
|
||||
layerMask?: number,
|
||||
queryTriggerInteraction?: QueryTriggerInteraction
|
||||
): void
|
||||
CapsuleCastAll: (
|
||||
p1: RawVec3f,
|
||||
p2: RawVec3f,
|
||||
radius: number,
|
||||
direction: RawVec3f,
|
||||
maxDistance: number,
|
||||
layerMask?: number,
|
||||
queryTriggerInteraction?: QueryTriggerInteraction
|
||||
) => RaycastHit[]
|
||||
BoxCast(
|
||||
center: RawVec3f,
|
||||
halfExt: RawVec3f,
|
||||
direction: RawVec3f,
|
||||
hit: RaycastHit,
|
||||
orientation: RawQuaternion,
|
||||
maxDistance: number,
|
||||
layerMask?: number,
|
||||
queryTriggerInteraction?: QueryTriggerInteraction
|
||||
): void
|
||||
BoxCastAll: (
|
||||
center: RawVec3f,
|
||||
halfExt: RawVec3f,
|
||||
direction: RawVec3f,
|
||||
orientation: RawQuaternion,
|
||||
maxDistance: number,
|
||||
layerMask?: number,
|
||||
queryTriggerInteraction?: QueryTriggerInteraction
|
||||
) => RaycastHit[]
|
||||
OverlapBox: (
|
||||
center: RawVec3f,
|
||||
halfExt: RawVec3f,
|
||||
orientation: RawQuaternion,
|
||||
layermask?: number,
|
||||
queryTriggerInteraction?: QueryTriggerInteraction
|
||||
) => Collider[]
|
||||
OverlapCapsule: (
|
||||
p1: RawVec3f,
|
||||
p2: RawVec3f,
|
||||
radius: number,
|
||||
layermask?: number,
|
||||
queryTriggerInteraction?: QueryTriggerInteraction
|
||||
) => Collider[]
|
||||
}
|
||||
|
||||
export class Rigidbody {
|
||||
constructor(system: PhysSystem)
|
||||
enabled?: boolean // since 2021.06
|
||||
position: RawVec3f
|
||||
rotation: RawQuaternion
|
||||
AttachToEntity: (pollObj: any, id: number) => void
|
||||
Remove(): void
|
||||
Detach(): void
|
||||
IsAttached(): boolean
|
||||
}
|
||||
|
||||
export enum CollisionDetectionMode {
|
||||
Discrete = 0,
|
||||
Continuous = 1,
|
||||
ContinuousDynamic = 2,
|
||||
ContinuousSpeculative = 3
|
||||
}
|
||||
|
||||
export enum RigidbodyConstraints {
|
||||
None = 0,
|
||||
FreezePositionX = 1 << 0,
|
||||
FreezePositionY = 1 << 1,
|
||||
FreezePositionZ = 1 << 2,
|
||||
FreezeRotationX = 1 << 3,
|
||||
FreezeRotationY = 1 << 4,
|
||||
FreezeRotationZ = 1 << 5,
|
||||
FreezePosition = FreezePositionX | FreezePositionY | FreezePositionZ,
|
||||
FreezeRotation = FreezeRotationX | FreezeRotationY | FreezeRotationZ,
|
||||
FreezeAll = FreezePosition | FreezeRotation
|
||||
}
|
||||
|
||||
export enum ForceMode {
|
||||
kForceModeForce = 0,
|
||||
kForceModeImpulse = 1 << 0,
|
||||
kForceModeVelocityChange = 1 << 1,
|
||||
kForceModeAcceleration = 1 << 2
|
||||
}
|
||||
|
||||
export enum CombineMode {
|
||||
eAverage = 0,
|
||||
eMin,
|
||||
eMultiply,
|
||||
eMax
|
||||
}
|
||||
|
||||
export enum CookingFlag {
|
||||
None = 0,
|
||||
CookForFasterSimulation = 1 << 0,
|
||||
EnableMeshCleaning = 1 << 1,
|
||||
WeldColocatedVertices = 1 << 2
|
||||
}
|
||||
|
||||
export enum CollisionFlags {
|
||||
None = 0,
|
||||
Sides = 1 << 0,
|
||||
Above = 1 << 1,
|
||||
Below = 1 << 2
|
||||
}
|
||||
|
||||
export class RawVec3f {
|
||||
constructor()
|
||||
constructor(x: number, y: number, z: number)
|
||||
x: number
|
||||
y: number
|
||||
z: number
|
||||
}
|
||||
|
||||
export class RawQuaternion {
|
||||
constructor()
|
||||
constructor(x: number, y: number, z: number, w: number)
|
||||
x: number
|
||||
y: number
|
||||
z: number
|
||||
w: number
|
||||
}
|
||||
|
||||
export class Collider {
|
||||
attachedRigidbody: Rigidbody
|
||||
bounds: Bounds
|
||||
name: string
|
||||
contactOffset: number
|
||||
enabled: boolean
|
||||
isTrigger: boolean
|
||||
scale: RawVec3f
|
||||
material?: Material
|
||||
sharedMateiral?: Material
|
||||
ClosestPoint: (raw: RawVec3f) => RawVec3f
|
||||
ClosestPointOnBounds: (raw: RawVec3f) => RawVec3f
|
||||
|
||||
onCollisionEnter?: (collision: Collision) => void
|
||||
onCollisionExit?: (collision: Collision) => void
|
||||
onCollisionStay?: (collision: Collision) => void
|
||||
onTriggerEnter?: (collision: Collision) => void
|
||||
onTriggerExit?: (collision: Collision) => void
|
||||
onTriggerStay?: (collision: Collision) => void
|
||||
|
||||
dettachRigidbody?: () => void
|
||||
|
||||
userData?: unknown
|
||||
layer: number
|
||||
}
|
||||
|
||||
export class BoxCollider extends Collider {
|
||||
constructor(system: PhysSystem, center: RawVec3f, size: RawVec3f)
|
||||
center: RawVec3f
|
||||
size: RawVec3f
|
||||
}
|
||||
|
||||
export class SphereCollider extends Collider {
|
||||
constructor(system: PhysSystem, center: RawVec3f, radius: number)
|
||||
center: RawVec3f
|
||||
radius: number
|
||||
}
|
||||
|
||||
export class CapsuleCollider extends Collider {
|
||||
constructor(
|
||||
system: PhysSystem,
|
||||
center: RawVec3f,
|
||||
height: number,
|
||||
radius: number
|
||||
)
|
||||
center: RawVec3f
|
||||
height: number
|
||||
radius: number
|
||||
}
|
||||
|
||||
export class MeshCollider extends Collider {
|
||||
constructor(
|
||||
system: PhysSystem,
|
||||
convex: boolean,
|
||||
cookingOptions: number,
|
||||
sharedMesh: PhysMesh
|
||||
)
|
||||
cookingOptions: number
|
||||
sharedMesh: PhysMesh | null
|
||||
convex: boolean
|
||||
}
|
||||
|
||||
export class CharacterController extends Collider {
|
||||
constructor(system: PhysSystem)
|
||||
position: RawVec3f
|
||||
center: RawVec3f
|
||||
collisionFlags: CollisionFlags
|
||||
detectCollisions: boolean
|
||||
enableOverlapRecovery: boolean
|
||||
height: number
|
||||
isGrounded: boolean
|
||||
minMoveDistance: number
|
||||
radius: number
|
||||
skinWidth: number
|
||||
slopeLimit: number
|
||||
stepOffset: number
|
||||
velocity: RawVec3f
|
||||
|
||||
Move: (movement: RawVec3f) => CollisionFlags
|
||||
SimpleMove: (speed: RawVec3f) => boolean
|
||||
AttachToEntity: (pollObj: any, id: number) => void
|
||||
|
||||
OnControllerColliderHit?: (hit: ControllerColliderHit) => void
|
||||
}
|
||||
|
||||
export interface ContactPoint {
|
||||
normal: RawVec3f
|
||||
this_collider: Collider
|
||||
other_collider: Collider
|
||||
point: RawVec3f
|
||||
separation: number
|
||||
}
|
||||
|
||||
export interface Collision {
|
||||
collider: Collider
|
||||
contacts: ContactPoint[]
|
||||
impulse: RawVec3f
|
||||
relative_velocity: RawVec3f
|
||||
}
|
||||
|
||||
export interface ControllerColliderHit {
|
||||
collider: Collider
|
||||
controller: CharacterController
|
||||
moveDirection: RawVec3f
|
||||
normal: RawVec3f
|
||||
moveLength: number
|
||||
point: RawVec3f
|
||||
}
|
||||
|
||||
export class Bounds {
|
||||
constructor(center: RawVec3f, size: RawVec3f)
|
||||
|
||||
center: RawVec3f
|
||||
extents: RawVec3f
|
||||
max: RawVec3f
|
||||
min: RawVec3f
|
||||
size: RawVec3f
|
||||
|
||||
ClosestPoint: (point: RawVec3f) => RawVec3f
|
||||
Contains: (point: RawVec3f) => boolean
|
||||
Expand: (amount: number) => void
|
||||
Intersects: (bounds: Bounds) => boolean
|
||||
SetMinMax: (min: RawVec3f, max: RawVec3f) => void
|
||||
SqrDistance: (point: RawVec3f) => number
|
||||
}
|
||||
|
||||
export class Material {
|
||||
constructor(system: PhysSystem)
|
||||
dynamicFriction: number
|
||||
staticFriction: number
|
||||
bounciness: number
|
||||
frictionCombine: CombineMode
|
||||
bounceCombine: CombineMode
|
||||
id: number
|
||||
}
|
||||
|
||||
export class DynamicRigidbody extends Rigidbody {
|
||||
mass: number
|
||||
angularDamping: number
|
||||
angularVelocity: RawVec3f
|
||||
centerOfMass: RawVec3f
|
||||
collisionDetectionMode: CollisionDetectionMode
|
||||
constraints: number
|
||||
detectCollisions: boolean
|
||||
linearDamping: number
|
||||
freezeRotation: boolean
|
||||
inertiaTensor: number
|
||||
// inertiaTensorRotation
|
||||
// interpolation
|
||||
isKinematic: boolean
|
||||
maxAngularVelocity: number
|
||||
maxDepenetrationVelocity: number
|
||||
sleepThreshold: number
|
||||
solverIterations: number
|
||||
solverVelocityIterations: number
|
||||
useGravity: boolean
|
||||
velocity: RawVec3f
|
||||
userData?: unknown
|
||||
|
||||
GetWorldCenterOfMass: () => RawVec3f
|
||||
AddForce: (force: RawVec3f, mode: ForceMode) => void
|
||||
AddTorque: (torque: RawVec3f, mode: ForceMode) => void
|
||||
IsSleeping: () => boolean
|
||||
Sleep: () => void
|
||||
WakeUp: () => void
|
||||
AddExplosionForce: (
|
||||
explosionForce: number,
|
||||
explosionPosition: RawVec3f,
|
||||
explosionRadius: number,
|
||||
upwardsModifier: number,
|
||||
mode: ForceMode
|
||||
) => void
|
||||
AddForceAtPosition: (
|
||||
force: RawVec3f,
|
||||
position: RawVec3f,
|
||||
mode: ForceMode
|
||||
) => void
|
||||
AddRelativeForce: (force: RawVec3f, mode: ForceMode) => void
|
||||
AddRelativeTorque: (torque: RawVec3f, mode: ForceMode) => void
|
||||
ClosestPointOnBounds: (position: RawVec3f) => RawVec3f
|
||||
GetPointVelocity: (worldPoint: RawVec3f) => RawVec3f
|
||||
GetRelativePointVelocity: (relativePoint: RawVec3f) => RawVec3f
|
||||
MovePosition: (position: RawVec3f) => void
|
||||
MoveRotation: (rotation: RawQuaternion) => void
|
||||
ResetCenterOfMass: () => void
|
||||
ResetInertiaTensor: () => void
|
||||
SetDensity: (density: number) => void
|
||||
// SweepTest: () => void;
|
||||
// SweepTestAll: () => void;
|
||||
}
|
||||
|
||||
export class PhysMesh {
|
||||
constructor(system: PhysSystem)
|
||||
// set vertices
|
||||
SetVertices: (buffer: Float32Array, count: number) => void
|
||||
// set indices
|
||||
SetTriangles: (
|
||||
buffer: Uint16Array | Uint32Array,
|
||||
count: number,
|
||||
useUint16: boolean
|
||||
) => void
|
||||
}
|
||||
|
||||
export class RaycastHit {
|
||||
constructor()
|
||||
collider: Collider
|
||||
distance: number
|
||||
normal: RawVec3f
|
||||
point: RawVec3f
|
||||
rigidbody: Rigidbody
|
||||
}
|
||||
}
|
||||
Vendored
+152
@@ -0,0 +1,152 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) 2025 Tencent, Inc. All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
***************************************************************************** */
|
||||
|
||||
/** [WXWebAssembly](https://developers.weixin.qq.com/miniprogram/dev/framework/performance/wasm.html)
|
||||
*
|
||||
* WXWebAssembly */
|
||||
declare namespace WXWebAssembly {
|
||||
type BufferSource = ArrayBufferView | ArrayBuffer
|
||||
|
||||
type CompileError = Error
|
||||
|
||||
const CompileError: {
|
||||
prototype: CompileError
|
||||
new (message?: string): CompileError
|
||||
(message?: string): CompileError
|
||||
}
|
||||
|
||||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance) */
|
||||
interface Instance {
|
||||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance/exports) */
|
||||
readonly exports: Exports
|
||||
}
|
||||
|
||||
const Instance: {
|
||||
prototype: Instance
|
||||
new (module: Module, importObject?: Imports): Instance
|
||||
}
|
||||
|
||||
type LinkError = Error
|
||||
|
||||
const LinkError: {
|
||||
prototype: LinkError
|
||||
new (message?: string): LinkError
|
||||
(message?: string): LinkError
|
||||
}
|
||||
|
||||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory) */
|
||||
interface Memory {
|
||||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/buffer) */
|
||||
readonly buffer: ArrayBuffer
|
||||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/grow) */
|
||||
grow(delta: number): number
|
||||
}
|
||||
|
||||
const Memory: {
|
||||
prototype: Memory
|
||||
new (descriptor: MemoryDescriptor): Memory
|
||||
}
|
||||
|
||||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module) */
|
||||
interface Module {}
|
||||
|
||||
const Module: {
|
||||
prototype: Module
|
||||
new (bytes: BufferSource): Module
|
||||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/customSections) */
|
||||
customSections(moduleObject: Module, sectionName: string): ArrayBuffer[]
|
||||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/exports) */
|
||||
exports(moduleObject: Module): ModuleExportDescriptor[]
|
||||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/imports) */
|
||||
imports(moduleObject: Module): ModuleImportDescriptor[]
|
||||
}
|
||||
|
||||
interface RuntimeError extends Error {}
|
||||
|
||||
const RuntimeError: {
|
||||
prototype: RuntimeError
|
||||
new (message?: string): RuntimeError
|
||||
(message?: string): RuntimeError
|
||||
}
|
||||
|
||||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table) */
|
||||
interface Table {
|
||||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/length) */
|
||||
readonly length: number
|
||||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/get) */
|
||||
get(index: number): any
|
||||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/grow) */
|
||||
grow(delta: number, value?: any): number
|
||||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/set) */
|
||||
set(index: number, value?: any): void
|
||||
}
|
||||
|
||||
const Table: {
|
||||
prototype: Table
|
||||
new (descriptor: TableDescriptor, value?: any): Table
|
||||
}
|
||||
|
||||
interface MemoryDescriptor {
|
||||
initial: number
|
||||
maximum?: number
|
||||
shared?: boolean
|
||||
}
|
||||
|
||||
interface ModuleExportDescriptor {
|
||||
kind: ImportExportKind
|
||||
name: string
|
||||
}
|
||||
|
||||
interface ModuleImportDescriptor {
|
||||
kind: ImportExportKind
|
||||
module: string
|
||||
name: string
|
||||
}
|
||||
|
||||
interface TableDescriptor {
|
||||
element: TableKind
|
||||
initial: number
|
||||
maximum?: number
|
||||
}
|
||||
|
||||
type ImportExportKind = 'function' | 'global' | 'memory' | 'table'
|
||||
type TableKind = 'anyfunc' | 'externref'
|
||||
type ValueType =
|
||||
| 'anyfunc'
|
||||
| 'externref'
|
||||
| 'f32'
|
||||
| 'f64'
|
||||
| 'i32'
|
||||
| 'i64'
|
||||
| 'v128'
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
type ExportValue = Function | Memory | Table
|
||||
type Exports = Record<string, ExportValue>
|
||||
type ImportValue = ExportValue | number
|
||||
type Imports = Record<string, ModuleImports>
|
||||
type ModuleImports = Record<string, ImportValue>
|
||||
/** [WXWebAssembly](https://developers.weixin.qq.com/miniprogram/dev/framework/performance/wasm.html) */
|
||||
function instantiate(
|
||||
path: string,
|
||||
importObject?: Imports
|
||||
): Promise<Instance>
|
||||
}
|
||||
+16375
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user