Skip to content

Commit

Permalink
feat:增加小程序onError
Browse files Browse the repository at this point in the history
  • Loading branch information
xuying.xu committed Oct 25, 2023
1 parent 50235fa commit bb72701
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 33 deletions.
11 changes: 7 additions & 4 deletions packages/my/examples/test/mini.project.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"format": 2,
"compileOptions": {
"component2": true,
"enableNodeModuleBabelTransform": true
},
"scripts": {
"beforeCompile": "npm run beforeCompile"
},
"enableNodeModuleBabelTransform": true,
"component2": true
}
}
}
2 changes: 1 addition & 1 deletion packages/my/examples/test/pages/index/index.axml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<view class="container">
<f2 onRender="onRenderChart" data="{{chartData}}"></f2>
<f2 onRender="onRenderChart" data="{{chartData}}" onError="onError"></f2>
</view>
17 changes: 10 additions & 7 deletions packages/my/examples/test/pages/index/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,31 +35,34 @@ const data2 = [{
sold: 50
}];
Page({
data: {// chartData: data1,
data: {
// chartData: data1,
},

onReady() {
this.setData({
chartData: data1
}); // 模拟数据更新

});
// 模拟数据更新
setTimeout(() => {
this.setData({
chartData: data2
});
}, 2000);
},

onError(e) {
console.log(e);
},
onRenderChart(props) {
const {
data
} = props;
return _jsx(Chart, {
data: data
}); // 如果不使用 jsx, 用下面代码效果也是一样的
});

// 如果不使用 jsx, 用下面代码效果也是一样的
// return createElement(Chart, {
// data: data,
// });
}

});
3 changes: 3 additions & 0 deletions packages/my/examples/test/pages/index/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ Page({
});
}, 2000);
},
onError(e){
console.log(e)
},
onRenderChart(props) {
const { data } = props;
return <Chart data={data} />;
Expand Down
47 changes: 26 additions & 21 deletions packages/my/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,32 @@ Component({
return;
}
const { id } = this.data;
const query = my.createSelectorQuery({ page: this.$page });
query
.select(`#${id}`)
.boundingClientRect()
.exec((res) => {
// 获取画布实际宽高, 用props的宽高做失败兜底
const { width, height } = res && res[0] ? res[0] : this.props;
const pixelRatio = getPixelRatio();
// 高清解决方案
this.setData(
{
width: width * pixelRatio,
height: height * pixelRatio,
},
() => {
const myCtx = my.createCanvasContext(id);
const context = F2Context(myCtx);
this.canvasRender({ width, height, context, pixelRatio });
}
);
});
const { onError } = this.props;
try {
const query = my.createSelectorQuery({ page: this.$page });
query
.select(`#${id}`)
.boundingClientRect()
.exec((res) => {
// 获取画布实际宽高, 用props的宽高做失败兜底
const { width, height } = res && res[0] ? res[0] : this.props;
const pixelRatio = getPixelRatio();
// 高清解决方案
this.setData(
{
width: width * pixelRatio,
height: height * pixelRatio,
},
() => {
const myCtx = my.createCanvasContext(id);
const context = F2Context(myCtx);
this.canvasRender({ width, height, context, pixelRatio });
}
);
});
} catch (error) {
onError && onError(error);
}
},
didUpdate() {
const { canvas, props } = this;
Expand Down

0 comments on commit bb72701

Please sign in to comment.