-
Notifications
You must be signed in to change notification settings - Fork 4.9k
My feauture compon #17933
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
My feauture compon #17933
Changes from all commits
7365283
5751df4
fb36351
f0fa44f
49420e2
2eb98ea
2d006ec
15252d1
518f50b
8665826
6c09fcc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,64 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import * as ASCF from '@ascf/native-api' | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| import Taro from '../../../../../taroo/taro/packages/taro/types' | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import networkMappings from './ascf-mappings/network.json' | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| const transformers = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| normalizeHeaders: (headers: Record<string, any>) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const normalized: Record<string, any> = {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| Object.keys(headers).forEach(key => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| normalized[key.toLowerCase()] = headers[key] | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return normalized | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| export function ascRequest(options: Taro.request.Option): Promise<Taro.request.SuccessCallbackResult> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const mapping = networkMappings.request | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+17
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chain验证映射配置结构 建议验证 networkMappings.request 的结构,确保映射配置包含必要的字段。 运行以下脚本来验证映射配置文件的存在和结构: 🏁 Script executed: #!/bin/bash
# 描述:验证 ASCF 网络映射配置文件的存在和结构
# 预期:文件存在且包含 request 字段
# 检查映射文件是否存在
if [ -f "packages/taro-api/src/ascf-mappings/network.json" ]; then
echo "✓ 映射文件存在"
# 检查文件内容结构
cat packages/taro-api/src/ascf-mappings/network.json | jq '.request'
else
echo "✗ 映射文件不存在"
fiLength of output: 712 验证网络映射配置结构并添加运行时校验 经过验证,
为提升健壮性,建议在
这样可确保未来对映射文件的修改不会导致调用异常。 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||
| const ascfParams: Record<string, any> = {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| Object.entries(mapping).forEach(([taroKey, config]) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const value = (options as any)[taroKey] | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (value === undefined) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (config.required) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw new Error(`[ASCF] Missing required parameter: ${taroKey}`) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (config.default !== undefined) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ascfParams[config.ascfParam] = config.default | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| let transformedValue = value | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (config.valueMap) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| transformedValue = config.valueMap[value] ?? value | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (config.transform && transformers[config.transform]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| transformedValue = transformers[config.transform](value) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| ascfParams[config.ascfParam] = transformedValue | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| return ASCF.Network.request(ascfParams).then(res => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| data: res.body, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| statusCode: res.status, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| header: res.headers, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| errMsg: 'request:ok' | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+46
to
+54
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 添加错误处理和响应验证 当前实现缺少对 ASCF.Network.request 调用的错误处理,并且假设响应结构固定。建议添加错误处理和响应验证。 - return ASCF.Network.request(ascfParams).then(res => {
- return {
- data: res.body,
- statusCode: res.status,
- header: res.headers,
- errMsg: 'request:ok'
- }
- })
+ return ASCF.Network.request(ascfParams).then(res => {
+ if (!res) {
+ throw new Error('[ASCF] Invalid response from ASCF.Network.request')
+ }
+ return {
+ data: res.body,
+ statusCode: res.status || 200,
+ header: res.headers || {},
+ errMsg: 'request:ok'
+ }
+ }).catch(error => {
+ throw new Error(`[ASCF] Network request failed: ${error.message || error}`)
+ })📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const ascfApis = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| connectDevice: (options: { deviceId: string, timeout?: number }) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return ASCF.Device.connect({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| deviceId: options.deviceId, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| timeout: options.timeout || 5000 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+57
to
+64
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 添加参数验证和错误处理 建议为 connectDevice 函数添加参数验证和错误处理,以提高代码健壮性。 export const ascfApis = {
- connectDevice: (options: { deviceId: string, timeout?: number }) => {
+ connectDevice: (options: { deviceId: string, timeout?: number }) => {
+ if (!options || !options.deviceId) {
+ throw new Error('[ASCF] deviceId is required for connectDevice')
+ }
+ if (options.timeout && (options.timeout < 0 || options.timeout > 60000)) {
+ throw new Error('[ASCF] timeout must be between 0 and 60000ms')
+ }
return ASCF.Device.connect({
deviceId: options.deviceId,
timeout: options.timeout || 5000
- })
+ }).catch(error => {
+ throw new Error(`[ASCF] Device connection failed: ${error.message || error}`)
+ })
}
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| { | ||
| "request": { | ||
| "url": { | ||
| "ascfParam": "endpoint", | ||
| "type": "string", | ||
| "required": true, | ||
| "docLink": "https://ascf.docs/apis/network#endpoint" | ||
| }, | ||
| "method": { | ||
| "ascfParam": "httpMethod", | ||
| "valueMap": { | ||
| "GET": "GET", | ||
| "POST": "POST", | ||
| "PUT": "PUT", | ||
| "DELETE": "DELETE" | ||
| }, | ||
| "default": "GET", | ||
| "docLink": "https://ascf.docs/apis/network#http-method" | ||
| }, | ||
| "header": { | ||
| "ascfParam": "headers", | ||
| "type": "object", | ||
| "transform": "normalizeHeaders", | ||
| "docLink": "https://ascf.docs/apis/network#headers" | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| { | ||
| "Button": { | ||
| "size": { | ||
| "ascfProp": "dimension", | ||
| "valueMap": { | ||
| "mini": "XS", | ||
| "small": "S", | ||
| "default": "M", | ||
| "large": "L" | ||
| }, | ||
| "required": false, | ||
| "default": "M", | ||
| "docLink": "https://ascf.docs/components/button#dimension" | ||
| }, | ||
| "loading": { | ||
| "ascfProp": "isLoading", | ||
| "type": "boolean", | ||
| "required": false, | ||
| "default": false, | ||
| "docLink": "https://ascf.docs/components/button#isloading" | ||
| } | ||
| }, | ||
| "Input": { | ||
| "password": { | ||
| "ascfProp": "secretInput", | ||
| "type": "boolean", | ||
| "required": false, | ||
| "default": false, | ||
| "docLink": "https://ascf.docs/components/input#secretinput" | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import { h } from '@stencil/core' | ||
| import React from 'react' | ||
|
|
||
| import coreMappings from '../../ascf-mappings/core.json' | ||
|
|
||
| const ASCF_MAPPINGS = { | ||
| ...coreMappings | ||
| } | ||
|
|
||
| export function withAscfAdapter<T extends IntrinsicAttributes & T>(WrappedComponent: React.ComponentType<T>) { | ||
| const componentName = WrappedComponent.name | ||
| const mapping = ASCF_MAPPINGS[componentName] || {} | ||
|
|
||
| // eslint-disable-next-line react/display-name | ||
| return (props: T) => { | ||
| if (process.env.TARO_ENV !== 'ascf') { | ||
| return <WrappedComponent {...props} /> | ||
| } | ||
|
|
||
| const ascfProps: any = {} | ||
|
|
||
| Object.entries(props).forEach(([key, value]) => { | ||
| const propMapping = mapping[key] | ||
|
|
||
| if (propMapping) { | ||
| ascfProps[propMapping.ascfProp] = propMapping.valueMap | ||
| ? propMapping.valueMap[value] ?? value | ||
| : value | ||
| } else { | ||
| ascfProps[key] = value | ||
| } | ||
| }) | ||
|
|
||
| Object.entries(mapping).forEach(([, config]) => { | ||
| const ascfKey = config.ascfProp | ||
| if (ascfProps[ascfKey] === undefined && config.default !== undefined) { | ||
| ascfProps[ascfKey] = config.default | ||
| } | ||
| }) | ||
|
|
||
| return <WrappedComponent {...ascfProps} /> | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -440,6 +440,33 @@ declare namespace ButtonProps { | |||||||||||||||||||||||||||
| authorizePrivateMessage | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| declare namespace TaroGeneral { | ||||||||||||||||||||||||||||
| interface ENV_TYPE { | ||||||||||||||||||||||||||||
| ascf: boolean | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| type ASCFAdaptedProps<Props, Mapping> = { | ||||||||||||||||||||||||||||
| [K in keyof Props]: | ||||||||||||||||||||||||||||
| K extends keyof Mapping | ||||||||||||||||||||||||||||
| ? Mapping[K]['ascfProp'] extends string | ||||||||||||||||||||||||||||
| ? Props[K] | ||||||||||||||||||||||||||||
| : never | ||||||||||||||||||||||||||||
| : Props[K] | ||||||||||||||||||||||||||||
| } & { | ||||||||||||||||||||||||||||
| [K in keyof Mapping as Mapping[K]['ascfProp']]?: any | ||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||
| interface ButtonProps { | ||||||||||||||||||||||||||||
| size?: 'mini' | 'small' | 'default' | 'large' | ||||||||||||||||||||||||||||
| loading?: boolean | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
Comment on lines
+460
to
+463
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 接口重复声明导致编译错误
- interface ButtonProps {
+ interface SimplifiedButtonProps {
size?: 'mini' | 'small' | 'default' | 'large'
loading?: boolean
}同时更新第467行的引用: - ? ASCFAdaptedProps<ButtonProps, typeof coreMappings.Button>
- : ButtonProps;
+ ? ASCFAdaptedProps<SimplifiedButtonProps, typeof coreMappings.Button>
+ : SimplifiedButtonProps;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| type TaroButtonProps = | ||||||||||||||||||||||||||||
| TaroGeneral.ENV_TYPE['ascf'] extends true | ||||||||||||||||||||||||||||
| ? ASCFAdaptedProps<ButtonProps, typeof coreMappings.Button> | ||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 缺少 coreMappings 导入 代码引用了 在文件顶部添加导入语句: import coreMappings from '../ascf-mappings/core.json'🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||
| : ButtonProps; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
Comment on lines
+465
to
+469
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chain条件类型实现可能存在问题 当前条件类型检查 建议重新考虑类型设计,可能需要使用不同的方法来实现平台特定的类型切换。请验证当前实现是否能正确工作: 🏁 Script executed: #!/bin/bash
# 检查其他文件中是否有类似的条件类型实现模式
ast-grep --pattern 'type $_ = $_["$_"] extends true ? $_ : $_'
# 查找 ENV_TYPE 的使用方式
rg -A 3 "ENV_TYPE\['ascf'\]"Length of output: 408 🏁 Script executed: #!/bin/bash
# 查找 TaroGeneral 接口定义及 ENV_TYPE 的声明
rg -n "interface TaroGeneral" -C 5 .
rg -n "type TaroGeneral" -C 5 .
rg -n "ENV_TYPE" -C 5 .Length of output: 23498 修复 Button.d.ts 中 当前实现 // packages/taro-components/types/Button.d.ts:445-447
declare namespace TaroGeneral {
interface ENV_TYPE {
ascf: boolean
}
}
// packages/taro-components/types/Button.d.ts:465-469
type TaroButtonProps =
TaroGeneral.ENV_TYPE['ascf'] extends true
? ASCFAdaptedProps<ButtonProps, typeof coreMappings.Button>
: ButtonProps;问题 请在以下位置进行修正:
示例(仅供参考): - type TaroButtonProps =
- TaroGeneral.ENV_TYPE['ascf'] extends true
- ? ASCFAdaptedProps<ButtonProps, typeof coreMappings.Button>
- : ButtonProps;
+ // 方式一:字面量化 ENV_TYPE 定义
+ declare namespace TaroGeneral {
+ interface ENV_TYPE {
+ ascf: true
+ // ...其他平台字段同理
+ }
+ }
+ type TaroButtonProps =
+ TaroGeneral.ENV_TYPE['ascf'] extends true
+ ? ASCFAdaptedProps<ButtonProps, typeof coreMappings.Button>
+ : ButtonProps;
+
+ // 或 方式二:使用类型参数
+ type TaroButtonProps<IsASCF extends boolean> =
+ IsASCF extends true
+ ? ASCFAdaptedProps<ButtonProps, typeof coreMappings.Button>
+ : ButtonProps;
+ // 使用处:TaroButtonProps<typeof TaroGeneral.ENV_TYPE['ascf']>请根据项目实际需求选择合适方案并修复,确保 ASCF 环境下能正确生成 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||
| /** lang 的合法值 */ | ||||||||||||||||||||||||||||
| interface Lang { | ||||||||||||||||||||||||||||
| /** 英文 */ | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # `@tarojs/plugin-platform-ascf` | ||
|
|
||
| Taro 插件。用于支持编译为ascf。 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| module.exports = require('./dist/index.js').default | ||
|
|
||
| module.exports.default = module.exports | ||
| module.exports.AscfApp = require('./dist/index.js').AscfApp | ||
|
Comment on lines
+1
to
+4
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent ❓ Verification inconclusive模块导出结构符合约定 导出文件遵循了 Taro 平台包的标准模式,确保了 CommonJS 和 ES 模块的兼容性。 建议验证编译后的分发文件是否正确导出了预期的内容: 🏁 Script executed: #!/bin/bash
# 检查 dist 目录和导出文件是否存在
fd "dist" --type d packages/taro-platform-ascf/ --exec ls -la {}/index.js \;Length of output: 79 脚本未返回任何结果,可能是目录不存在或命令路径有误。请使用更直接的方式验证 🏁 Script executed: #!/bin/bash
# 查找并列出 dist 目录下的 index.js
find packages/taro-platform-ascf/dist -maxdepth 1 -type f -name index.js -exec ls -la {} \;
# 如存在,则检查默认和 AscfApp 导出
if [ -f packages/taro-platform-ascf/dist/index.js ]; then
grep -E "export default|export (\\{[^}]*\\}|AscfApp)" -n packages/taro-platform-ascf/dist/index.js || echo "未找到预期的导出"
fiLength of output: 219 缺少 dist 构建产物 在 – 确认 🤖 Prompt for AI Agents |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| { | ||
| "name": "@tarojs/plugin-platform-ascf", | ||
| "version": "4.0.12", | ||
| "description": "ascf平台插件", | ||
| "author": "ascf", | ||
| "license": "MIT", | ||
| "main": "index.js", | ||
| "types": "dist/types/index.d.ts", | ||
| "keywords": [ | ||
| "taro" | ||
| ], | ||
| "files": [ | ||
| "index.js", | ||
| "dist" | ||
| ], | ||
| "scripts": { | ||
| "prod": "pnpm run build", | ||
| "build": "rollup -c", | ||
| "dev": "rollup -c -w" | ||
| }, | ||
| "bugs": { | ||
| "url": "https://github.com/NervJS/taro/issues" | ||
| }, | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git+https://github.com/NervJS/taro.git" | ||
| }, | ||
| "engines": { | ||
| "node": ">= 18" | ||
| }, | ||
| "devDependencies": { | ||
| "@tarojs/components": "workspace:*", | ||
| "@tarojs/service": "workspace:*", | ||
| "@tarojs/shared": "workspace:*" | ||
| }, | ||
| "peerDependencies": { | ||
| "@tarojs/service": "workspace:*", | ||
| "@tarojs/shared": "workspace:*" | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
修复导入路径
这个导入路径看起来不正确,包含了
taroo而不是taro,并且相对路径层级过深。请确认正确的导入路径。建议修复为:
📝 Committable suggestion
🤖 Prompt for AI Agents