Skip to content

Commit 36957d2

Browse files
committed
Merge branch 'develop'
2 parents f918e59 + ab9d4cf commit 36957d2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+27379
-25384
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ root = true
33
[*]
44
charset = utf-8
55
indent_style = space
6-
indent_size = 4
6+
indent_size = 2
77
end_of_line = lf
88
insert_final_newline = true
99
trim_trailing_whitespace = true

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
.DS_Store
2-
/node_modules/
2+
node_modules

.npmignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.github
2-
/test
2+
/example
33
/node_modules
4+
/test
45
tsconfig.json

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## <small>1.0.3 (2023-08-14)</small>
2+
3+
* update: miniprogram-api-typings 3.11.0 ([9f484fc](https://github.com/xiaweiss/miniprogram-type/commit/9f484fc))
4+
* chore: 添加示例项目 ([22ba991](https://github.com/xiaweiss/miniprogram-type/commit/22ba991))
5+
* fix: #3 [api] 3.11.0 版本 WechatMiniprogram.Err 丢失了 ([a5d54b9](https://github.com/xiaweiss/miniprogram-type/commit/a5d54b9)), closes [#3](https://github.com/xiaweiss/miniprogram-type/issues/3)
6+
17
## <small>1.0.2 (2023-06-19)</small>
28

39
* fix: update readme ([57b4f0f](https://github.com/xiaweiss/miniprogram-type/commit/57b4f0f))

example/miniprogram/app.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"entryPagePath": "pages/home/index",
3+
"pages": [
4+
"pages/home/index"
5+
],
6+
"window": {
7+
"navigationBarBackgroundColor": "#fff",
8+
"navigationBarTextStyle": "black",
9+
"navigationBarTitleText": "类型示例",
10+
"backgroundColor": "#fff"
11+
},
12+
"debug": false,
13+
"resizable": true,
14+
"usingComponents": {
15+
"page": "components/page/index"
16+
},
17+
"sitemapLocation": "sitemap.json",
18+
"style": "v2",
19+
"lazyCodeLoading": "requiredComponents",
20+
"rendererOptions": {
21+
"skyline": {
22+
"defaultDisplayBlock": true
23+
}
24+
},
25+
"componentFramework": "glass-easel"
26+
}

example/miniprogram/app.scss

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
page {
2+
position: relative;
3+
box-sizing: border-box;
4+
/** 最小高度填充满视口,方便设置页面背景色 */
5+
min-height: 100vh;
6+
/** 默认字体 */
7+
font-family: system-ui, -apple-system;
8+
/** 移动端按钮按下时,去除高亮 */
9+
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
10+
/** 默认行高 */
11+
line-height: 1;
12+
}
13+
14+
/**
15+
* bug: root-portal 在 webview 模式,无法继承全局 page 的样式
16+
* @see https://github.com/xiaweiss/miniprogram-bug-report/issues/40
17+
*/
18+
view {
19+
font-family: system-ui, -apple-system;
20+
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
21+
line-height: 1;
22+
}
23+
24+
view,
25+
input {
26+
box-sizing: border-box;
27+
}
28+
29+
image {
30+
display: block;
31+
}
32+
33+
/** 分享按钮等默认样式重置,使用时需要设置 size="mini",设置 class="~app-button" */
34+
.app-button {
35+
display: block!important;
36+
padding: 0!important;
37+
/**
38+
* bug: [skyline] button 组件在 flex 元素中渲染异常
39+
* @see https://github.com/xiaweiss/miniprogram-bug-report/issues/43
40+
* hack 重置 margin 样式
41+
*/
42+
margin: 0!important;
43+
font-size: inherit;
44+
font-weight: 400;
45+
color: inherit;
46+
line-height: 1!important;
47+
}

example/miniprogram/app.ts

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
import { wxToPromise, isPC, isIOS, emitter } from './utils/index'
2+
3+
interface AppOption extends AppData {
4+
getSetting: () => void
5+
getSyetemInfo: () => void
6+
registerCommand: () => void
7+
setLaunchShowOption: (option: WechatMiniprogram.App.LaunchShowOption, type: string) => void
8+
setSetting: () => void
9+
}
10+
11+
/** 全局数据初始值 */
12+
const globalData : AppData['globalData'] = {
13+
apiCategory: 'default',
14+
authRecord: false,
15+
authWritePhotosAlbum: false,
16+
envVersion: 'release',
17+
isWeakNet: false,
18+
keyboardHeight: 0,
19+
navBarHeight: 0,
20+
safeAreaBottom: 0,
21+
scene: 0,
22+
shareTicket: '',
23+
systemInfo: undefined,
24+
uuid: '',
25+
}
26+
27+
/**
28+
* @see https://developers.weixin.qq.com/miniprogram/dev/reference/api/App.html
29+
*/
30+
App<AppOption>({
31+
globalData,
32+
async onLaunch() {
33+
/**
34+
* 限制频率的接口,必须在这里调用
35+
* @see https://developers.weixin.qq.com/miniprogram/dev/framework/performance/api-frequency.html
36+
*/
37+
this.getSyetemInfo()
38+
39+
this.getSetting()
40+
this.setSetting()
41+
},
42+
43+
/**
44+
* 注册全局的便利函数
45+
*/
46+
registerCommand () {
47+
48+
},
49+
/**
50+
* 获取系统信息
51+
*/
52+
getSyetemInfo () {
53+
const systemInfo = wx.getSystemInfoSync()
54+
this.globalData.systemInfo = systemInfo
55+
56+
// 计算底部安全区高度,mac screenHeight 比实际显示的高,这里做个修正
57+
// windows 2.26.1 开始 screenHeight 和 windowHeight 不同了,需要用 systemInfo.windowHeight - systemInfo.safeArea.bottom
58+
this.globalData.safeAreaBottom = isPC(this) ? 0 : systemInfo.screenHeight - systemInfo.safeArea.bottom
59+
60+
// 计算导航栏高度
61+
if (wx.getMenuButtonBoundingClientRect) {
62+
const rect = wx.getMenuButtonBoundingClientRect()
63+
if (rect) {
64+
const {top, bottom} = rect!
65+
const navbarHeight = isIOS(this) ? 44 : 48;
66+
const navbarPaddingTop = (bottom + top) / 2 - navbarHeight / 2
67+
this.globalData.navBarHeight = navbarHeight + navbarPaddingTop
68+
}
69+
}
70+
71+
console.log('systemInfo', this.globalData.systemInfo)
72+
},
73+
/**
74+
* 检查权限状态
75+
*/
76+
async getSetting () {
77+
const [res] = await wxToPromise(wx.getSetting)
78+
if (res) {
79+
this.globalData.authRecord = res.authSetting['scope.record']!
80+
this.globalData.authWritePhotosAlbum = res.authSetting['scope.writePhotosAlbum']!
81+
}
82+
},
83+
/**
84+
* 设置小程序配置
85+
*/
86+
async setSetting () {
87+
// 转发设置,重置分享参数
88+
wx.updateShareMenu({
89+
withShareTicket: false,
90+
isPrivateMessage: false
91+
})
92+
93+
// 弱网状态
94+
wx.onNetworkWeakChange && wx.onNetworkWeakChange((res) => {
95+
this.globalData.isWeakNet = res.weakNet
96+
})
97+
98+
// 键盘高度变化事件
99+
wx.onKeyboardHeightChange((res) => {
100+
console.log('app.ts keyboardHeightChange', res.height)
101+
this.globalData.keyboardHeight = res.height
102+
emitter.emit('keyboardHeightChange', res)
103+
})
104+
105+
// 窗口尺寸变化事件(微信 bug: mac 客户端 <= 3.7 版本不能触发)
106+
wx.onWindowResize((res) => {
107+
if (!res.size || !this.globalData.systemInfo) return
108+
109+
// 数据相同时,不触发事件
110+
if (
111+
this.globalData.systemInfo.screenHeight === res.size.screenHeight &&
112+
this.globalData.systemInfo.screenWidth === res.size.screenWidth &&
113+
this.globalData.systemInfo.windowHeight === res.size.windowHeight &&
114+
this.globalData.systemInfo.windowWidth === res.size.windowWidth
115+
) return
116+
117+
this.globalData.systemInfo.screenHeight = res.size.screenHeight
118+
this.globalData.systemInfo.screenWidth = res.size.screenWidth
119+
this.globalData.systemInfo.windowHeight = res.size.windowHeight
120+
this.globalData.systemInfo.windowWidth = res.size.windowWidth
121+
122+
// 事件触发器,去广播给页面
123+
emitter.emit('windowResize')
124+
})
125+
},
126+
/**
127+
* 设置启动参数
128+
*/
129+
setLaunchShowOption (option, type) {
130+
console.log(type, 'option', option)
131+
132+
// 重定向到首页
133+
if (option.query?.redirect === 'home') {
134+
wx.reLaunch({url: '/pages/home/index'})
135+
}
136+
137+
this.globalData.scene = option.scene
138+
console.log(type, 'scene', option.scene)
139+
140+
// @ts-ignore
141+
this.globalData.apiCategory = option.apiCategory
142+
143+
this.globalData.shareTicket = option.shareTicket || ''
144+
console.log(type, 'shareTicket', option.shareTicket)
145+
146+
}
147+
})
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"component": true
3+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
.nav-bar,
2+
.nav-bar-left,
3+
.back,
4+
.home {
5+
display: flex;
6+
flex-direction: row;
7+
}
8+
9+
.nav-bar {
10+
flex-shrink: 0;
11+
position: relative;
12+
left: 0;
13+
right: 0;
14+
top: 0;
15+
display: flex;
16+
flex-direction: row;
17+
align-items: center;
18+
background: transparent;
19+
}
20+
21+
.nav-bar-left {
22+
align-items: center;
23+
flex-shrink: 0;
24+
}
25+
26+
.back {
27+
align-items: center;
28+
height: 100%;
29+
padding-left: 16px;
30+
padding-right: 12px;
31+
cursor: pointer;
32+
}
33+
34+
.icon-back {
35+
width: 12px;
36+
height: 24px;
37+
}
38+
39+
.home {
40+
align-items: center;
41+
height: 100%;
42+
padding-left: 18px;
43+
padding-right: 12px;
44+
cursor: pointer;
45+
}
46+
47+
.icon-home {
48+
width: 20px;
49+
height: 20px;
50+
}
51+
52+
.nav-bar-title {
53+
flex: 1;
54+
display: inline-block;
55+
width: 0;
56+
font-size: 17px;
57+
font-weight: 600;
58+
letter-spacing: 0.2px;
59+
text-align: center;
60+
white-space: nowrap;
61+
overflow: hidden;
62+
text-overflow: ellipsis;
63+
}

0 commit comments

Comments
 (0)