Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaweiss committed Aug 14, 2023
2 parents f918e59 + ab9d4cf commit 36957d2
Show file tree
Hide file tree
Showing 44 changed files with 27,379 additions and 25,384 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ root = true
[*]
charset = utf-8
indent_style = space
indent_size = 4
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
.DS_Store
/node_modules/
node_modules
3 changes: 2 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.github
/test
/example
/node_modules
/test
tsconfig.json
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## <small>1.0.3 (2023-08-14)</small>

* update: miniprogram-api-typings 3.11.0 ([9f484fc](https://github.com/xiaweiss/miniprogram-type/commit/9f484fc))
* chore: 添加示例项目 ([22ba991](https://github.com/xiaweiss/miniprogram-type/commit/22ba991))
* 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)

## <small>1.0.2 (2023-06-19)</small>

* fix: update readme ([57b4f0f](https://github.com/xiaweiss/miniprogram-type/commit/57b4f0f))
Expand Down
26 changes: 26 additions & 0 deletions example/miniprogram/app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"entryPagePath": "pages/home/index",
"pages": [
"pages/home/index"
],
"window": {
"navigationBarBackgroundColor": "#fff",
"navigationBarTextStyle": "black",
"navigationBarTitleText": "类型示例",
"backgroundColor": "#fff"
},
"debug": false,
"resizable": true,
"usingComponents": {
"page": "components/page/index"
},
"sitemapLocation": "sitemap.json",
"style": "v2",
"lazyCodeLoading": "requiredComponents",
"rendererOptions": {
"skyline": {
"defaultDisplayBlock": true
}
},
"componentFramework": "glass-easel"
}
47 changes: 47 additions & 0 deletions example/miniprogram/app.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
page {
position: relative;
box-sizing: border-box;
/** 最小高度填充满视口,方便设置页面背景色 */
min-height: 100vh;
/** 默认字体 */
font-family: system-ui, -apple-system;
/** 移动端按钮按下时,去除高亮 */
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
/** 默认行高 */
line-height: 1;
}

/**
* bug: root-portal 在 webview 模式,无法继承全局 page 的样式
* @see https://github.com/xiaweiss/miniprogram-bug-report/issues/40
*/
view {
font-family: system-ui, -apple-system;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
line-height: 1;
}

view,
input {
box-sizing: border-box;
}

image {
display: block;
}

/** 分享按钮等默认样式重置,使用时需要设置 size="mini",设置 class="~app-button" */
.app-button {
display: block!important;
padding: 0!important;
/**
* bug: [skyline] button 组件在 flex 元素中渲染异常
* @see https://github.com/xiaweiss/miniprogram-bug-report/issues/43
* hack 重置 margin 样式
*/
margin: 0!important;
font-size: inherit;
font-weight: 400;
color: inherit;
line-height: 1!important;
}
147 changes: 147 additions & 0 deletions example/miniprogram/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
import { wxToPromise, isPC, isIOS, emitter } from './utils/index'

interface AppOption extends AppData {
getSetting: () => void
getSyetemInfo: () => void
registerCommand: () => void
setLaunchShowOption: (option: WechatMiniprogram.App.LaunchShowOption, type: string) => void
setSetting: () => void
}

/** 全局数据初始值 */
const globalData : AppData['globalData'] = {
apiCategory: 'default',
authRecord: false,
authWritePhotosAlbum: false,
envVersion: 'release',
isWeakNet: false,
keyboardHeight: 0,
navBarHeight: 0,
safeAreaBottom: 0,
scene: 0,
shareTicket: '',
systemInfo: undefined,
uuid: '',
}

/**
* @see https://developers.weixin.qq.com/miniprogram/dev/reference/api/App.html
*/
App<AppOption>({
globalData,
async onLaunch() {
/**
* 限制频率的接口,必须在这里调用
* @see https://developers.weixin.qq.com/miniprogram/dev/framework/performance/api-frequency.html
*/
this.getSyetemInfo()

this.getSetting()
this.setSetting()
},

/**
* 注册全局的便利函数
*/
registerCommand () {

},
/**
* 获取系统信息
*/
getSyetemInfo () {
const systemInfo = wx.getSystemInfoSync()
this.globalData.systemInfo = systemInfo

// 计算底部安全区高度,mac screenHeight 比实际显示的高,这里做个修正
// windows 2.26.1 开始 screenHeight 和 windowHeight 不同了,需要用 systemInfo.windowHeight - systemInfo.safeArea.bottom
this.globalData.safeAreaBottom = isPC(this) ? 0 : systemInfo.screenHeight - systemInfo.safeArea.bottom

// 计算导航栏高度
if (wx.getMenuButtonBoundingClientRect) {
const rect = wx.getMenuButtonBoundingClientRect()
if (rect) {
const {top, bottom} = rect!
const navbarHeight = isIOS(this) ? 44 : 48;
const navbarPaddingTop = (bottom + top) / 2 - navbarHeight / 2
this.globalData.navBarHeight = navbarHeight + navbarPaddingTop
}
}

console.log('systemInfo', this.globalData.systemInfo)
},
/**
* 检查权限状态
*/
async getSetting () {
const [res] = await wxToPromise(wx.getSetting)
if (res) {
this.globalData.authRecord = res.authSetting['scope.record']!
this.globalData.authWritePhotosAlbum = res.authSetting['scope.writePhotosAlbum']!
}
},
/**
* 设置小程序配置
*/
async setSetting () {
// 转发设置,重置分享参数
wx.updateShareMenu({
withShareTicket: false,
isPrivateMessage: false
})

// 弱网状态
wx.onNetworkWeakChange && wx.onNetworkWeakChange((res) => {
this.globalData.isWeakNet = res.weakNet
})

// 键盘高度变化事件
wx.onKeyboardHeightChange((res) => {
console.log('app.ts keyboardHeightChange', res.height)
this.globalData.keyboardHeight = res.height
emitter.emit('keyboardHeightChange', res)
})

// 窗口尺寸变化事件(微信 bug: mac 客户端 <= 3.7 版本不能触发)
wx.onWindowResize((res) => {
if (!res.size || !this.globalData.systemInfo) return

// 数据相同时,不触发事件
if (
this.globalData.systemInfo.screenHeight === res.size.screenHeight &&
this.globalData.systemInfo.screenWidth === res.size.screenWidth &&
this.globalData.systemInfo.windowHeight === res.size.windowHeight &&
this.globalData.systemInfo.windowWidth === res.size.windowWidth
) return

this.globalData.systemInfo.screenHeight = res.size.screenHeight
this.globalData.systemInfo.screenWidth = res.size.screenWidth
this.globalData.systemInfo.windowHeight = res.size.windowHeight
this.globalData.systemInfo.windowWidth = res.size.windowWidth

// 事件触发器,去广播给页面
emitter.emit('windowResize')
})
},
/**
* 设置启动参数
*/
setLaunchShowOption (option, type) {
console.log(type, 'option', option)

// 重定向到首页
if (option.query?.redirect === 'home') {
wx.reLaunch({url: '/pages/home/index'})
}

this.globalData.scene = option.scene
console.log(type, 'scene', option.scene)

// @ts-ignore
this.globalData.apiCategory = option.apiCategory

this.globalData.shareTicket = option.shareTicket || ''
console.log(type, 'shareTicket', option.shareTicket)

}
})
3 changes: 3 additions & 0 deletions example/miniprogram/components/nav-bar/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"component": true
}
63 changes: 63 additions & 0 deletions example/miniprogram/components/nav-bar/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
.nav-bar,
.nav-bar-left,
.back,
.home {
display: flex;
flex-direction: row;
}

.nav-bar {
flex-shrink: 0;
position: relative;
left: 0;
right: 0;
top: 0;
display: flex;
flex-direction: row;
align-items: center;
background: transparent;
}

.nav-bar-left {
align-items: center;
flex-shrink: 0;
}

.back {
align-items: center;
height: 100%;
padding-left: 16px;
padding-right: 12px;
cursor: pointer;
}

.icon-back {
width: 12px;
height: 24px;
}

.home {
align-items: center;
height: 100%;
padding-left: 18px;
padding-right: 12px;
cursor: pointer;
}

.icon-home {
width: 20px;
height: 20px;
}

.nav-bar-title {
flex: 1;
display: inline-block;
width: 0;
font-size: 17px;
font-weight: 600;
letter-spacing: 0.2px;
text-align: center;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
Loading

0 comments on commit 36957d2

Please sign in to comment.