-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
44 changed files
with
27,379 additions
and
25,384 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
.DS_Store | ||
/node_modules/ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
.github | ||
/test | ||
/example | ||
/node_modules | ||
/test | ||
tsconfig.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"component": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
Oops, something went wrong.