Skip to content

Commit

Permalink
chore: 添加小程序演示示例 (#1830)
Browse files Browse the repository at this point in the history
  • Loading branch information
zengyue authored Aug 25, 2023
1 parent f00dac9 commit fbb3445
Show file tree
Hide file tree
Showing 32 changed files with 578 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/f2-my/examples/test/.mini-ide/project-ide.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"enableLegacyRemoteDebug": false
}
3 changes: 3 additions & 0 deletions packages/f2-my/examples/test/app.acss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
page {
background: #f7f7f7;
}
12 changes: 12 additions & 0 deletions packages/f2-my/examples/test/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* eslint-disable */
App({
onLaunch(_options) {
// 第一次打开
// options.query == {number:1}
console.info('App onLaunch');
},
onShow(_options) {
// 从后台被 scheme 重新打开
// options.query == {number:1}
},
});
8 changes: 8 additions & 0 deletions packages/f2-my/examples/test/app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"pages": [
"pages/index/index"
],
"window": {
"defaultTitle": "My App"
}
}
11 changes: 11 additions & 0 deletions packages/f2-my/examples/test/babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"plugins": [
[
"@babel/plugin-transform-react-jsx",
{
"runtime": "automatic",
"importSource": "@antv/f2"
}
]
]
}
8 changes: 8 additions & 0 deletions packages/f2-my/examples/test/mini.project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"scripts": {
"beforeCompile": "npm run beforeCompile"
},
"enableNodeModuleBabelTransform": true,
"component2": true,
"enableAppxNg": true
}
12 changes: 12 additions & 0 deletions packages/f2-my/examples/test/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"scripts": {
"beforeCompile": "babel pages --out-dir pages --only **/*.jsx"
},
"dependencies": {
"@antv/f2": "^5.0.0",
"@antv/f-my": "^1.0.0",
"@babel/cli": "^7.16.0",
"@babel/core": "^7.16.0",
"@babel/plugin-transform-react-jsx": "^7.16.0"
}
}
23 changes: 23 additions & 0 deletions packages/f2-my/examples/test/pages/index/chart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Chart, Interval } from '@antv/f2';
import { jsx as _jsx } from "@antv/f2/jsx-runtime";
export default (props => {
const {
data
} = props;
return _jsx(Chart, {
data: data,
children: _jsx(Interval, {
x: "genre",
y: "sold",
color: "genre",
selection: {
selectedStyle: {
fillOpacity: 1
},
unSelectedStyle: {
fillOpacity: 0.4
}
}
})
});
});
22 changes: 22 additions & 0 deletions packages/f2-my/examples/test/pages/index/chart.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Chart, Interval } from '@antv/f2';

export default (props) => {
const { data } = props;
return (
<Chart data={data}>
<Interval
x="genre"
y="sold"
color="genre"
selection={{
selectedStyle: {
fillOpacity: 1,
},
unSelectedStyle: {
fillOpacity: 0.4,
},
}}
/>
</Chart>
);
};
5 changes: 5 additions & 0 deletions packages/f2-my/examples/test/pages/index/index.acss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* required by usingComponents */
.container {
width: 100%;
height: 600rpx;
}
3 changes: 3 additions & 0 deletions packages/f2-my/examples/test/pages/index/index.axml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<view class="container">
<f-canvas onRender="onRenderChart" data="{{chartData}}"></f-canvas>
</view>
71 changes: 71 additions & 0 deletions packages/f2-my/examples/test/pages/index/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// 通过 createElement 方式创建
// import { createElement } from '@antv/f2';
import Chart from './chart';

/* eslint-disable */
import { jsx as _jsx } from "@antv/f2/jsx-runtime";
const data1 = [{
genre: 'Sports',
sold: 275
}, {
genre: 'Strategy',
sold: 115
}, {
genre: 'Action',
sold: 120
}, {
genre: 'Shooter',
sold: 350
}, {
genre: 'Other',
sold: 150
}];
const data2 = [{
genre: 'Sports',
sold: 275
}, {
genre: 'Strategy',
sold: 115
}, {
genre: 'Action',
sold: 20
}, {
genre: 'Shooter',
sold: 50
}, {
genre: 'Other',
sold: 50
}];
var isAppX2CanvasEnv = function isAppX2CanvasEnv() {
return my.canIUse('canvas.onReady') && my.canIUse('createSelectorQuery.return.node');
};
Page({
data: {
// chartData: data1,
},
onReady() {
this.setData({
chartData: data1
});
// 模拟数据更新
setTimeout(() => {
this.setData({
chartData: data2
});
}, 2000);
},
onRenderChart(props) {
console.log('isAppX2CanvasEnv', isAppX2CanvasEnv());
const {
data
} = props;
return _jsx(Chart, {
data: data
});

// 如果不使用 jsx, 用下面代码效果也是一样的
// return createElement(Chart, {
// data: data,
// });
}
});
5 changes: 5 additions & 0 deletions packages/f2-my/examples/test/pages/index/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"usingComponents": {
"f-canvas": "@antv/f-my"
}
}
52 changes: 52 additions & 0 deletions packages/f2-my/examples/test/pages/index/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// 通过 createElement 方式创建
// import { createElement } from '@antv/f2';
import Chart from './chart';

/* eslint-disable */

const data1 = [
{ genre: 'Sports', sold: 275 },
{ genre: 'Strategy', sold: 115 },
{ genre: 'Action', sold: 120 },
{ genre: 'Shooter', sold: 350 },
{ genre: 'Other', sold: 150 },
];

const data2 = [
{ genre: 'Sports', sold: 275 },
{ genre: 'Strategy', sold: 115 },
{ genre: 'Action', sold: 20 },
{ genre: 'Shooter', sold: 50 },
{ genre: 'Other', sold: 50 },
];

var isAppX2CanvasEnv = function isAppX2CanvasEnv() {
return my.canIUse('canvas.onReady') && my.canIUse('createSelectorQuery.return.node');
};

Page({
data: {
// chartData: data1,
},
onReady() {
this.setData({
chartData: data1,
});
// 模拟数据更新
setTimeout(() => {
this.setData({
chartData: data2,
});
}, 2000);
},
onRenderChart(props) {
console.log('isAppX2CanvasEnv', isAppX2CanvasEnv());
const { data } = props;
return <Chart data={data} />;

// 如果不使用 jsx, 用下面代码效果也是一样的
// return createElement(Chart, {
// data: data,
// });
},
});
Binary file added packages/f2-my/examples/test/snapshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions packages/f2-my/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "@antv/f2-my",
"private": true,
"version": "5.0.0",
"homepage": "https://github.com/antvis/f2",
"bugs": {
"url": "https://github.com/antvis/f2/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/antvis/f2"
},
"author": "https://github.com/orgs/antvis/people"
}
20 changes: 20 additions & 0 deletions packages/f2-wx/examples/test/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// app.js
/* eslint-disable */
App({
onLaunch() {
// 展示本地存储能力
const logs = wx.getStorageSync('logs') || [];
logs.unshift(Date.now());
wx.setStorageSync('logs', logs);

// 登录
wx.login({
success: () => {
// 发送 res.code 到后台换取 openId, sessionKey, unionId
},
});
},
globalData: {
userInfo: null,
},
});
13 changes: 13 additions & 0 deletions packages/f2-wx/examples/test/app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"pages":[
"pages/index/index"
],
"window":{
"backgroundTextStyle":"light",
"navigationBarBackgroundColor": "#fff",
"navigationBarTitleText": "Weixin",
"navigationBarTextStyle":"black"
},
"style": "v2",
"sitemapLocation": "sitemap.json"
}
1 change: 1 addition & 0 deletions packages/f2-wx/examples/test/app.wxss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/**app.wxss**/
11 changes: 11 additions & 0 deletions packages/f2-wx/examples/test/babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"plugins": [
[
"@babel/plugin-transform-react-jsx",
{
"runtime": "automatic",
"importSource": "@antv/f-engine"
}
]
]
}
14 changes: 14 additions & 0 deletions packages/f2-wx/examples/test/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"scripts": {
"beforeCompile": "babel pages --out-dir pages --only **/*.jsx"
},
"dependencies": {
"@antv/f2": "^5.0.0",
"@antv/f-wx": "^1.0.0"
},
"devDependencies": {
"@babel/cli": "^7.16.0",
"@babel/core": "^7.16.0",
"@babel/plugin-transform-react-jsx": "^7.16.0"
}
}
28 changes: 28 additions & 0 deletions packages/f2-wx/examples/test/pages/index/chart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Chart, Interval, Axis, Legend, Tooltip } from '@antv/f2';
import { jsx as _jsx } from "@antv/f-engine/jsx-runtime";
import { jsxs as _jsxs } from "@antv/f-engine/jsx-runtime";
export default (props => {
const {
data
} = props;
return _jsxs(Chart, {
data: data,
children: [_jsx(Axis, {
field: "genre"
}), _jsx(Axis, {
field: "sold"
}), _jsx(Interval, {
x: "genre",
y: "sold",
color: "genre",
selection: {
selectedStyle: {
fillOpacity: 1
},
unSelectedStyle: {
fillOpacity: 0.4
}
}
}), _jsx(Legend, {}), _jsx(Tooltip, {})]
});
});
26 changes: 26 additions & 0 deletions packages/f2-wx/examples/test/pages/index/chart.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Chart, Interval, Axis, Legend, Tooltip } from '@antv/f2';

export default (props) => {
const { data } = props;
return (
<Chart data={data}>
<Axis field="genre" />
<Axis field="sold" />
<Interval
x="genre"
y="sold"
color="genre"
selection={{
selectedStyle: {
fillOpacity: 1,
},
unSelectedStyle: {
fillOpacity: 0.4,
},
}}
/>
<Legend />
<Tooltip />
</Chart>
);
};
Loading

0 comments on commit fbb3445

Please sign in to comment.