├── .eslintignore ├── .eslintrc.js ├── .gitignore ├── .prettierignore ├── .prettierrc ├── .wechatide └── fileCache.cfg ├── CLOUD_README.md ├── README.md ├── cloudfunction ├── getAppletCode │ ├── config.json │ ├── index.js │ └── package.json ├── getSignature │ ├── index.js │ └── package.json ├── getUnionID │ ├── index.js │ └── package.json ├── notificationImg │ ├── config.json │ ├── index.js │ └── package.json ├── notificationText │ ├── config.json │ ├── index.js │ └── package.json ├── openapi │ ├── config.json │ ├── index.js │ └── package.json ├── programMessage │ ├── config.json │ ├── index.js │ └── package.json ├── pushMessage │ ├── config.json │ ├── index.js │ └── package.json └── quickstartFunctions │ ├── addRecord │ └── index.js │ ├── clearCollection │ └── index.js │ ├── config.json │ ├── createCollection │ └── index.js │ ├── fetchActivityList │ └── index.js │ ├── fetchGoodsList │ └── index.js │ ├── genMpQrcode │ └── index.js │ ├── getGroupEnterInfo │ └── index.js │ ├── getMiniProgramCode │ └── index.js │ ├── getOpenId │ └── index.js │ ├── index.js │ ├── package.json │ ├── selectRecord │ └── index.js │ ├── signIn │ └── index.js │ └── updateRecord │ └── index.js ├── jsserver └── checkInteractiveData.js ├── minicode ├── getUserInfo │ ├── .eslintignore │ ├── .eslintrc.js │ ├── .prettierrc │ ├── README.md │ ├── minigame │ │ ├── auth.js │ │ ├── auth.ts │ │ ├── common │ │ │ ├── const.js │ │ │ ├── const.ts │ │ │ ├── render.js │ │ │ ├── render.ts │ │ │ ├── scene.js │ │ │ ├── scene.ts │ │ │ ├── utils.js │ │ │ └── utils.ts │ │ ├── game.js │ │ ├── game.json │ │ ├── game.ts │ │ ├── libs │ │ │ ├── engine.d.ts │ │ │ ├── engine.js │ │ │ ├── richtext.d.ts │ │ │ ├── richtext.js │ │ │ ├── tinyemitter.d.ts │ │ │ └── tinyemitter.js │ │ ├── project.config.json │ │ └── project.private.config.json │ ├── package-lock.json │ ├── package.json │ └── tsconfig.json └── requestSubscribeSystemMessage │ ├── .eslintignore │ ├── .eslintrc.js │ ├── .prettierrc │ ├── README.md │ ├── minigame │ ├── game │ │ ├── common │ │ │ ├── const.js │ │ │ ├── const.ts │ │ │ ├── render.js │ │ │ ├── render.ts │ │ │ ├── scene.js │ │ │ ├── scene.ts │ │ │ ├── utils.js │ │ │ └── utils.ts │ │ ├── game.js │ │ ├── game.json │ │ ├── game.ts │ │ ├── libs │ │ │ ├── engine.d.ts │ │ │ ├── engine.js │ │ │ ├── richtext.d.ts │ │ │ ├── richtext.js │ │ │ ├── tinyemitter.d.ts │ │ │ └── tinyemitter.js │ │ ├── message.js │ │ ├── message.ts │ │ └── openDataContext │ │ │ ├── friend_interactive.js │ │ │ ├── friend_interactive.ts │ │ │ ├── index.js │ │ │ ├── index.ts │ │ │ ├── libs │ │ │ ├── engine.d.ts │ │ │ ├── engine.js │ │ │ ├── richtext.d.ts │ │ │ ├── richtext.js │ │ │ ├── tinyemitter.d.ts │ │ │ └── tinyemitter.js │ │ │ ├── type.js │ │ │ └── type.ts │ ├── jsserver │ │ ├── checkInteractiveData.js │ │ └── checkInteractiveData.ts │ ├── project.config.json │ └── project.private.config.json │ ├── package-lock.json │ ├── package.json │ └── tsconfig.json ├── miniprogram ├── TencentSans-W7.subset.ttf ├── game.js ├── game.json ├── game.ts ├── images │ ├── AD.png │ ├── APIicon.png │ ├── Group 3.png │ ├── abilityOpen.png │ ├── chatTool.png │ ├── circleFriends.png │ ├── contact.png │ ├── customerService.png │ ├── facility.png │ ├── ic-line-done.png │ ├── ic-line-iconsd-share.png │ ├── interface.png │ ├── logo.png │ ├── media.png │ ├── miniGame.png │ ├── network.png │ ├── off.png │ ├── official.png │ ├── on.png │ ├── pause.png │ ├── pitch_on.png │ ├── play.png │ ├── recommend.png │ ├── record.png │ ├── rendering.png │ ├── right.png │ ├── right_arrow.png │ ├── right_arrow_black.png │ ├── share.png │ ├── star.png │ ├── stop.png │ ├── storage-fileSystem.png │ ├── trash.png │ ├── visionkit-ability.png │ ├── weapp.jpg │ └── worker.png ├── js │ ├── api │ │ ├── AD │ │ │ ├── createBannerAd │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ ├── createGridAd │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ ├── createInterstitialAd │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ └── createRewardedVideoAd │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ ├── APIentry │ │ │ └── index.js │ │ ├── AR │ │ │ ├── common │ │ │ │ ├── behavior.js │ │ │ │ ├── detectBoxBehavior.js │ │ │ │ ├── renderComponent.js │ │ │ │ ├── view.js │ │ │ │ └── yuvBehavior.js │ │ │ ├── face-detect │ │ │ │ └── index.js │ │ │ ├── loaders │ │ │ │ ├── gltf-clone.js │ │ │ │ └── gltf-loader.js │ │ │ ├── plane-ar │ │ │ │ ├── behavior.js │ │ │ │ ├── index.js │ │ │ │ ├── plane-ar.js │ │ │ │ ├── view.js │ │ │ │ └── yuvBehavior.js │ │ │ ├── threejs-miniprogram │ │ │ │ └── index.js │ │ │ ├── visionkit-basic-v2 │ │ │ │ ├── behavior.js │ │ │ │ ├── index.js │ │ │ │ ├── view.js │ │ │ │ ├── visionkit-basic-v2.js │ │ │ │ └── yuvBehavior.js │ │ │ └── visionkit-basic │ │ │ │ ├── behavior.js │ │ │ │ ├── index.js │ │ │ │ ├── view.js │ │ │ │ ├── visionkit-basic.js │ │ │ │ └── yuvBehavior.js │ │ ├── abilityOpen │ │ │ ├── UnionID │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ ├── VoIPChat │ │ │ │ ├── functionPool.js │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ ├── appletCode │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ ├── createGameClubButton │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ ├── customerService │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ ├── directedSharing │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ ├── getGameRecorder │ │ │ │ ├── bgm.mp3 │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ ├── getUserInfo │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ ├── login │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ ├── matchedPattern │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ ├── onShareAppMessage │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ ├── openDataContext │ │ │ │ ├── ShareCanvas.js │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ ├── relationalChaininteractiveData │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ ├── requestSubscribeMessage │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ ├── requestSubscribeSystemMessage │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ ├── setting │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ ├── shareAppMessage │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ ├── shareTimeLine │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ └── startHandoff │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ ├── chatTool │ │ │ └── groupTask │ │ │ │ ├── const.js │ │ │ │ ├── const.ts │ │ │ │ ├── createGroupTask │ │ │ │ ├── index.js │ │ │ │ ├── index.ts │ │ │ │ ├── view.js │ │ │ │ └── view.ts │ │ │ │ ├── groupTaskDetail │ │ │ │ ├── ShareCanvas.js │ │ │ │ ├── ShareCanvas.ts │ │ │ │ ├── drawProgress.js │ │ │ │ ├── drawProgress.ts │ │ │ │ ├── index.js │ │ │ │ ├── index.ts │ │ │ │ ├── view.js │ │ │ │ └── view.ts │ │ │ │ ├── index.js │ │ │ │ ├── index.ts │ │ │ │ ├── types.js │ │ │ │ ├── types.ts │ │ │ │ ├── util.js │ │ │ │ ├── util.ts │ │ │ │ ├── view.js │ │ │ │ └── view.ts │ │ ├── facility │ │ │ ├── accelerometerChange │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ ├── clipboardData │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ ├── compassChange │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ ├── deviceMotionChange │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ ├── deviceOrientationChange │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ ├── getBatteryInfo │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ ├── getLocation │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ ├── getNetworkType │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ ├── getUpdateManager │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ ├── gyroscopeChange │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ ├── onNetworkStatusChange │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ ├── screenBrightness │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ ├── setKeepScreenOn │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ └── vibrate │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ ├── game.js │ │ ├── interface │ │ │ ├── showActionSheet │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ ├── showModal │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ └── showToast │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ ├── media │ │ │ ├── camera │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ ├── video │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ ├── voice │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ └── voiceFrequency │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ ├── network │ │ │ ├── apiList.js │ │ │ ├── downloadFile │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ ├── request │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ ├── uploadFile │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ └── webSocket │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ ├── recommend │ │ │ ├── createGameBanner │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ ├── createGameIcon │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ └── createGamePortal │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ ├── rendering │ │ │ ├── createImage │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ ├── loadFont │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ ├── setPreferredFramesPerSecond │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ ├── toDataURL │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ └── toTempFilePath │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ ├── router.js │ │ ├── storage-fileSystem │ │ │ ├── access │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ ├── dir │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ ├── getFileInfo │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ ├── operationFile │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ ├── readdir │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ ├── rename │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ ├── saveFile │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ ├── savedFile │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ ├── stat │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ ├── storage │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ │ └── unzip │ │ │ │ ├── index.js │ │ │ │ └── view.js │ │ └── worker │ │ │ ├── index.js │ │ │ └── view.js │ ├── errMsg │ │ └── index.js │ └── libs │ │ ├── Scroller │ │ └── index.js │ │ ├── compareVersion.js │ │ ├── component │ │ ├── box.js │ │ ├── button.js │ │ ├── circle.js │ │ ├── goBackBtn.js │ │ ├── img.js │ │ ├── index.js │ │ ├── line.js │ │ ├── linearGradientBox.js │ │ ├── scroll.js │ │ ├── text.js │ │ ├── textarea.js │ │ └── texture.js │ │ ├── dateFormat.js │ │ ├── pixi.min.js │ │ ├── pixiScroll.js │ │ ├── pmgressBar.js │ │ ├── share.js │ │ ├── show.js │ │ ├── template │ │ └── fixed.js │ │ └── weapp-adapter.js ├── sub │ ├── PCHandoff.js │ ├── data.js │ ├── data │ │ ├── index.js │ │ └── index.ts │ ├── img │ │ ├── loading.png │ │ └── refresh.png │ ├── index.js │ ├── index.ts │ ├── loading.js │ ├── loading.ts │ ├── pushMessage.js │ └── render │ │ ├── style.js │ │ ├── styles │ │ ├── groupTaskFriendList.js │ │ ├── groupTaskFriendList.ts │ │ ├── tips.js │ │ └── tips.ts │ │ ├── template.js │ │ ├── tplfn.js │ │ └── tpls │ │ ├── groupTaskFriendList.js │ │ ├── groupTaskFriendList.ts │ │ ├── tips.js │ │ └── tips.ts ├── test.zip └── workers │ └── index.js ├── package.json ├── project.config.json ├── readmeImages ├── 15656998217946.png ├── 1565703421184.png ├── 15657051222936.png ├── 15657051644791.png ├── 15657830373446.png ├── 15657831706742.png ├── 15657834069152.png ├── 15657835833394.png ├── 15657837079883.png ├── 15657839753823.png ├── 15657842591339.png ├── QR code.jpg └── samplePlate.png └── tsconfig.json /.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | libs 4 | *.js -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | env: { 3 | browser: true, 4 | es6: true, 5 | }, 6 | extends: ['eslint:recommended', 'plugin:prettier/recommended'], 7 | globals: { 8 | Atomics: 'readonly', 9 | SharedArrayBuffer: 'readonly', 10 | wx: 'readonly', 11 | canvas: 'readonly', 12 | require: 'readonly', 13 | module: 'readonly', 14 | worker: 'readonly', 15 | exports: 'readonly', 16 | GameGlobal: 'readonly', 17 | requirePlugin: 'readonly', 18 | }, 19 | parserOptions: { 20 | ecmaVersion: 2018, 21 | sourceType: 'module', 22 | }, 23 | rules: { 24 | 'prettier/prettier': 'error', // 确保Prettier的规则被ESLint检查 25 | }, 26 | }; 27 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .vscode/c_cpp_properties.json 3 | node_modules/ 4 | package-lock.json -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | *.js -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "tabWidth": 2, 3 | "useTabs": false, 4 | "singleQuote": true, 5 | "trailingComma": "es5", 6 | "semi": true 7 | } 8 | -------------------------------------------------------------------------------- /CLOUD_README.md: -------------------------------------------------------------------------------- 1 | ## 微信小游戏示例的云开发部署 2 | 1. 导入后点击“云开发”,打开云开发控制台点击“创建”,接着填写任意的环境名称,环境ID会根据填写的名称随机生成,然后确认即可。 3 | 4 | 5 | 6 |
7 | 2. 云开发部署完成后,在开发者工具上面右击“cloudfunction”文件夹打开菜单列表,确认当前环境为之前创建的环境名称 8 | 9 | 10 |
11 | 3. 在开发者工具展开“cloudfunction”文件夹,然后右击子文件夹打开菜单列表,点击“上传并部署 : 云端安装依赖(不上传node_modules)”,其余的子文件夹重复以上操作即可。 12 | 13 |
14 | 4. 在云开发控制台找到“设置”并点击,可以看到一个tabBar,这个tabBar是默认选中环境设置的,在环境设置里找到环境ID并且复制 15 | 16 | 然后在开发者工具里全局搜索 wx.cloud.init,接着双击搜索得到的结果 下一步把 `wx.cloud.init({ env: 'example-69d3b' })` 替换成 `wx.cloud.init({ env: '粘贴被你复制的环境ID' })` 即可 17 |
18 | 5. 把tabBar切换到全局设置,点击全局设置下的“添加消息”推送进行配置(注意:这里必须按照下面给的图进行配置,配置完后点击确认即可) 19 | 20 | 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 微信小游戏示例 2 | 3 | 微信小游戏示例源码,欢迎扫描以下小程序码体验。 4 | 5 | > 提示:请使用微信开发者工具或微信客户端 6.7.2 及以上版本运行。 6 | 7 | 8 |
9 | 10 | ## 导入项目与配置 11 | 12 | 1. 克隆微信小游戏示例源码 13 | ``` 14 | git clone https://github.com/wechat-miniprogram/minigame-demo.git 15 | ``` 16 |
17 | 18 | 2. 进行导入,填写开发者自己的小游戏 AppID(注意,因涉及到云开发相关功能,不能使用测试AppID) 19 | 20 |
21 | 22 | 3. 此示例demo使用了小程序云开发,所依赖的云开发环境搭建请参考 [云开发示例说明](./CLOUD_README.md)。 23 | 24 | ## 目录结构 25 | ``` 26 | . 27 | ├── cloudfunction // 云函数目录 28 | ├── jsserver // 数据安全性校验(关系链互动) 29 | ├── miniprogram // 运行小游戏示例目录 30 | │ ├── images // icon目录 31 | │ ├── js 32 | │ │ ├── api // API示例目录 33 | │ │ │ ├── abilityOpen // 开放能力 34 | │ │ │ ├── interface // 界面 35 | │ │ │ ├── rendering // 渲染 36 | │ │ │ ├── facility // 设备 37 | │ │ │ ├── network // 网络 38 | │ │ │ ├── media // 媒体 39 | │ │ │ ├── storage-fileSystem // 数据与文件系统 40 | │ │ │ ├── worker // 多线程 41 | │ │ │ ├── AD // 广告组件 42 | │ │ │ └── recommend // 推荐组件 43 | │ │ ├── errMsg // 错误提示目录 44 | │ │ └── libs // PIXI.js 45 | │ ├── workers // 多线程文件目录 46 | │ ├── game.js 47 | │ ├── game.json 48 | │ ├── test.zip 49 | │ └── TencentSans-W7.subset.ttf 50 | ├── readmeImages 51 | ├── .eslintrc.js 52 | ├── CLOUD_REAMDE.md 53 | ├── project.config.json 54 | └── README.md 55 | ``` 56 | ## 注意 57 | 58 | 1. 目录里面的所有view.js仅用于UI绘制,开发者不需要关心。 59 | 2. 如需正常运行网络相关功能,请开MP配置合法域名或打开“调试模式”。 60 | 3. 使用手机预览时请在“详情”把“上传时进行代码保护”给剔除掉。 61 | 62 | ## 使用 63 | 64 | 使用[微信开发者工具](https://developers.weixin.qq.com/miniprogram/dev/devtools/download.html)打开该示例代码。 65 | 66 | 67 | ## 截图 68 | 69 | 70 | -------------------------------------------------------------------------------- /cloudfunction/getAppletCode/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "permissions": { 3 | "openapi": [ 4 | "wxacode.getUnlimited" 5 | ] 6 | } 7 | } -------------------------------------------------------------------------------- /cloudfunction/getAppletCode/index.js: -------------------------------------------------------------------------------- 1 | // 云函数入口文件 2 | const cloud = require('wx-server-sdk'); 3 | 4 | cloud.init(); 5 | 6 | // 云函数入口函数 7 | exports.main = async () => { 8 | try { 9 | // 此处返回 Base64 图片仅作为演示用,在实际开发中, 10 | // 应上传图片至云文件存储,然后在小程序中通过云文件 ID 使用 11 | const result = await cloud.openapi.wxacode.getUnlimited({ scene: 'a=1' }); 12 | let base64 = `data:${result.contentType};base64,${result.buffer.toString('base64')}`; 13 | return { 14 | errMsg: result.errMsg, 15 | errCode: result.errCode, 16 | base64 17 | }; 18 | } catch (err) { 19 | console.log(err); 20 | return err; 21 | } 22 | }; 23 | -------------------------------------------------------------------------------- /cloudfunction/getAppletCode/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "getAppletCode", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "wx-server-sdk": "latest" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /cloudfunction/getSignature/index.js: -------------------------------------------------------------------------------- 1 | // 云函数入口文件 2 | const cloud = require('wx-server-sdk'); 3 | 4 | cloud.init(); 5 | 6 | // 云函数入口函数 7 | exports.main = async (event) => { 8 | const { groupId } = event; 9 | const timestamp = Date.now(), 10 | nonceStr = Math.random() 11 | .toString(36) 12 | .substr(2); 13 | 14 | const result = await cloud.getVoIPSign({ 15 | groupId, 16 | timestamp, 17 | nonce: nonceStr 18 | }); 19 | 20 | return { 21 | signature: result.signature, 22 | nonceStr, 23 | timeStamp: timestamp, 24 | groupId 25 | }; 26 | }; 27 | -------------------------------------------------------------------------------- /cloudfunction/getSignature/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "getUnionID", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "wx-server-sdk": "latest" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /cloudfunction/getUnionID/index.js: -------------------------------------------------------------------------------- 1 | // 云函数入口文件 2 | const cloud = require('wx-server-sdk'); 3 | 4 | cloud.init(); 5 | 6 | // 云函数入口函数 7 | exports.main = async () => { 8 | const wxContext = cloud.getWXContext(); 9 | 10 | return { 11 | openid: wxContext.OPENID, 12 | appid: wxContext.APPID, 13 | unionid: wxContext.UNIONID 14 | }; 15 | }; 16 | -------------------------------------------------------------------------------- /cloudfunction/getUnionID/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "getUnionID", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "wx-server-sdk": "latest" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /cloudfunction/notificationImg/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "permissions": { 3 | "openapi": [ 4 | "customerServiceMessage.send" 5 | ] 6 | } 7 | } -------------------------------------------------------------------------------- /cloudfunction/notificationImg/index.js: -------------------------------------------------------------------------------- 1 | // 云函数入口文件 2 | const cloud = require('wx-server-sdk'); 3 | 4 | cloud.init(); 5 | 6 | // 云函数入口函数 7 | exports.main = async () => { 8 | const wxContext = cloud.getWXContext(); 9 | 10 | await cloud.openapi.customerServiceMessage.send({ 11 | touser: wxContext.OPENID, 12 | msgtype: 'text', 13 | text: { 14 | content: '收到你发来的图片' 15 | } 16 | }); 17 | 18 | return 'success'; 19 | }; 20 | -------------------------------------------------------------------------------- /cloudfunction/notificationImg/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "notification", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "wx-server-sdk": "latest" 13 | } 14 | } -------------------------------------------------------------------------------- /cloudfunction/notificationText/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "permissions": { 3 | "openapi": [ 4 | "customerServiceMessage.send" 5 | ] 6 | } 7 | } -------------------------------------------------------------------------------- /cloudfunction/notificationText/index.js: -------------------------------------------------------------------------------- 1 | // 云函数入口文件 2 | const cloud = require('wx-server-sdk'); 3 | 4 | cloud.init(); 5 | 6 | // 云函数入口函数 7 | exports.main = async () => { 8 | const wxContext = cloud.getWXContext(); 9 | 10 | await cloud.openapi.customerServiceMessage.send({ 11 | touser: wxContext.OPENID, 12 | msgtype: 'text', 13 | text: { 14 | content: '收到' 15 | } 16 | }); 17 | 18 | return 'success'; 19 | }; 20 | -------------------------------------------------------------------------------- /cloudfunction/notificationText/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "notification", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "wx-server-sdk": "latest" 13 | } 14 | } -------------------------------------------------------------------------------- /cloudfunction/openapi/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "permissions": { 3 | "openapi": [ 4 | "wxacode.getUnlimited", 5 | "templateMessage.send", 6 | "templateMessage.addTemplate", 7 | "templateMessage.deleteTemplate", 8 | "templateMessage.getTemplateList", 9 | "templateMessage.getTemplateLibraryById", 10 | "templateMessage.getTemplateLibraryList", 11 | "subscribeMessage.send", 12 | "updatableMessage.createActivityId", 13 | "chattoolmsg.send" 14 | ] 15 | } 16 | } -------------------------------------------------------------------------------- /cloudfunction/openapi/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "openapi", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "wx-server-sdk": "latest" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /cloudfunction/programMessage/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "permissions": { 3 | "openapi": ["miniprogramMessage.send"] 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /cloudfunction/programMessage/index.js: -------------------------------------------------------------------------------- 1 | // 云函数入口文件 2 | const cloud = require('wx-server-sdk'); 3 | 4 | cloud.init(); 5 | 6 | // 云函数入口函数 7 | exports.main = async (event, context) => { 8 | const wxContext = cloud.getWXContext(); 9 | 10 | try { 11 | if (event.type === "send"){ 12 | const result = await cloud.openapi.miniprogramMessage.send({ 13 | msg_type: event.msg_type, 14 | content: '体验一下小游戏示例的发送小程序消息功能!', 15 | page_path: event.page_path, 16 | openid: wxContext.OPENID, 17 | }); 18 | return result; 19 | } 20 | 21 | } catch (err) { 22 | return err; 23 | } 24 | }; 25 | -------------------------------------------------------------------------------- /cloudfunction/programMessage/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "programMessage", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "wx-server-sdk": "~2.1.2" 13 | } 14 | } -------------------------------------------------------------------------------- /cloudfunction/pushMessage/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "permissions": { 3 | "openapi": [ 4 | "templateMessage.send" 5 | ] 6 | } 7 | } -------------------------------------------------------------------------------- /cloudfunction/pushMessage/index.js: -------------------------------------------------------------------------------- 1 | // 云函数入口文件 2 | const cloud = require('wx-server-sdk'); 3 | 4 | cloud.init(); 5 | 6 | // 云函数入口函数 7 | exports.main = async event => { 8 | try { 9 | const result = await cloud.openapi.subscribeMessage.send({ 10 | touser: cloud.getWXContext().OPENID, // 通过 getWXContext 获取 OPENID 11 | page: event.page, 12 | data: { 13 | time1: { 14 | value: '2020年1月9日' 15 | }, 16 | thing2: { 17 | value: '体验订阅消息推送' 18 | } 19 | }, 20 | templateId: 'wAniOv_NUi6TXiQWX74_1LD5E4_6EfqvaeSxUxhqllg' 21 | }); 22 | 23 | return result; 24 | } catch (err) { 25 | return err; 26 | } 27 | }; 28 | -------------------------------------------------------------------------------- /cloudfunction/pushMessage/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "getPushMessage", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "wx-server-sdk": "latest" 13 | } 14 | } -------------------------------------------------------------------------------- /cloudfunction/quickstartFunctions/addRecord/index.js: -------------------------------------------------------------------------------- 1 | const cloud = require('wx-server-sdk'); 2 | 3 | cloud.init({ 4 | env: cloud.DYNAMIC_CURRENT_ENV 5 | }); 6 | const db = cloud.database(); 7 | 8 | // 修改数据库信息云函数入口函数 9 | exports.main = async (event, context) => { 10 | try { 11 | const wxContext = cloud.getWXContext(); 12 | await db.collection('activity').add({ 13 | data: { 14 | creator: wxContext.OPENID, 15 | activityId: event.activityId, 16 | roomid: event.roomid, 17 | chatType: event.chatType, 18 | // title: event.title, 19 | // coverImage: event.coverImage, 20 | // startTime: event.startTime, 21 | // endTime: event.endTime, 22 | participant: event.participant, 23 | signIn: event.signIn, 24 | // targetState: event.targetState, 25 | isUsingSpecify: event.isUsingSpecify, 26 | isFinished: event.isFinished, 27 | createTime: Date.now(), 28 | taskTitle: event.taskTitle, 29 | } 30 | }) 31 | return { 32 | success: true, 33 | }; 34 | } catch (e) { 35 | return { 36 | success: false, 37 | errMsg: e 38 | }; 39 | } 40 | }; 41 | -------------------------------------------------------------------------------- /cloudfunction/quickstartFunctions/clearCollection/index.js: -------------------------------------------------------------------------------- 1 | const cloud = require('wx-server-sdk'); 2 | 3 | cloud.init({ 4 | env: cloud.DYNAMIC_CURRENT_ENV 5 | }); 6 | const db = cloud.database(); 7 | 8 | // 修改数据库信息云函数入口函数 9 | exports.main = async (event, context) => { 10 | const _ = db.command 11 | 12 | try { 13 | return await db.collection('activity').where({ 14 | createTime: _.gt(0) 15 | }).remove() 16 | } catch(e) { 17 | console.error(e) 18 | } 19 | }; 20 | -------------------------------------------------------------------------------- /cloudfunction/quickstartFunctions/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "permissions": { 3 | "openapi": [ 4 | "wxacode.get" 5 | ] 6 | } 7 | } -------------------------------------------------------------------------------- /cloudfunction/quickstartFunctions/createCollection/index.js: -------------------------------------------------------------------------------- 1 | const cloud = require('wx-server-sdk'); 2 | 3 | cloud.init({ 4 | env: cloud.DYNAMIC_CURRENT_ENV 5 | }); 6 | 7 | const db = cloud.database(); 8 | 9 | // 创建集合云函数入口函数 10 | exports.main = async (event, context) => { 11 | try { 12 | // 创建集合 13 | await db.createCollection('activity'); 14 | return { 15 | success: true 16 | }; 17 | } catch (e) { 18 | // 这里catch到的是该collection已经存在,从业务逻辑上来说是运行成功的,所以catch返回success给前端,避免工具在前端抛出异常 19 | return { 20 | success: true, 21 | data: 'create collection success' 22 | }; 23 | } 24 | }; 25 | -------------------------------------------------------------------------------- /cloudfunction/quickstartFunctions/fetchActivityList/index.js: -------------------------------------------------------------------------------- 1 | const cloud = require('wx-server-sdk'); 2 | 3 | cloud.init({ 4 | env: cloud.DYNAMIC_CURRENT_ENV 5 | }); 6 | const db = cloud.database(); 7 | 8 | // 查询数据库集合云函数入口函数 9 | exports.main = async (event, context) => { 10 | // 返回数据库查询结果 11 | try { 12 | const wxContext = cloud.getWXContext(); 13 | const resp = await db.collection('activity').where({ 14 | creator: wxContext.OPENID 15 | }).get(); 16 | 17 | return { 18 | success: true, 19 | dataList: resp.data, 20 | } 21 | } catch (error) { 22 | return { 23 | success: false, 24 | errMsg: error 25 | } 26 | } 27 | }; 28 | -------------------------------------------------------------------------------- /cloudfunction/quickstartFunctions/fetchGoodsList/index.js: -------------------------------------------------------------------------------- 1 | const cloud = require('wx-server-sdk'); 2 | cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV }); 3 | exports.main = async (event, context) => { 4 | return { 5 | dataList: [ 6 | { _id: '1', title: '微信气泡徽章', price: 1800 }, 7 | { _id: '2', title: '微信地球鼠标垫', price: 5800 }, 8 | { _id: '3', title: '微信黄脸大贴纸', price: 500 } 9 | ], 10 | } 11 | }; 12 | 13 | // const cloud = require('wx-server-sdk'); 14 | // cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV }); 15 | 16 | // const db = cloud.database(); 17 | 18 | // exports.main = async (event, context) => { 19 | // const result = await db.collection('goods') 20 | // .skip(0) 21 | // .limit(10) 22 | // .get(); 23 | // return { 24 | // dataList: result?.data, 25 | // }; 26 | // }; 27 | -------------------------------------------------------------------------------- /cloudfunction/quickstartFunctions/genMpQrcode/index.js: -------------------------------------------------------------------------------- 1 | const cloud = require('wx-server-sdk'); 2 | cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV }); 3 | 4 | exports.main = async (event, context) => { 5 | const pagePath = event.pagePath; 6 | // 获取小程序二维码的buffer 7 | const resp = await cloud.openapi.wxacode.get({ 8 | path: pagePath, 9 | }); 10 | const { buffer } = resp; 11 | // 将图片上传云存储空间 12 | const upload = await cloud.uploadFile({ 13 | cloudPath: String(pagePath).replace(/\//g, '_') + '.png', 14 | fileContent: buffer 15 | }); 16 | return upload.fileID; 17 | }; 18 | -------------------------------------------------------------------------------- /cloudfunction/quickstartFunctions/getGroupEnterInfo/index.js: -------------------------------------------------------------------------------- 1 | const cloud = require('wx-server-sdk'); 2 | 3 | cloud.init({ 4 | env: cloud.DYNAMIC_CURRENT_ENV 5 | }); 6 | 7 | exports.main = async (event, context) => { 8 | const wxContext = cloud.getWXContext(); 9 | 10 | return { 11 | groupInfo: event.groupInfo, 12 | openid: wxContext.OPENID, 13 | } 14 | }; 15 | -------------------------------------------------------------------------------- /cloudfunction/quickstartFunctions/getMiniProgramCode/index.js: -------------------------------------------------------------------------------- 1 | const cloud = require('wx-server-sdk'); 2 | 3 | cloud.init({ 4 | env: cloud.DYNAMIC_CURRENT_ENV 5 | }); 6 | 7 | // 获取小程序二维码云函数入口函数 8 | exports.main = async (event, context) => { 9 | // 获取小程序二维码的buffer 10 | const resp = await cloud.openapi.wxacode.get({ 11 | path: 'pages/index/index' 12 | }); 13 | const { buffer } = resp; 14 | // 将图片上传云存储空间 15 | const upload = await cloud.uploadFile({ 16 | cloudPath: 'code.png', 17 | fileContent: buffer 18 | }); 19 | return upload.fileID; 20 | }; 21 | -------------------------------------------------------------------------------- /cloudfunction/quickstartFunctions/getOpenId/index.js: -------------------------------------------------------------------------------- 1 | const cloud = require('wx-server-sdk'); 2 | 3 | cloud.init({ 4 | env: cloud.DYNAMIC_CURRENT_ENV 5 | }); 6 | 7 | // 获取openId云函数入口函数 8 | exports.main = async (event, context) => { 9 | // 获取基础信息 10 | const wxContext = cloud.getWXContext(); 11 | 12 | return { 13 | openid: wxContext.OPENID, 14 | appid: wxContext.APPID, 15 | unionid: wxContext.UNIONID, 16 | }; 17 | }; 18 | -------------------------------------------------------------------------------- /cloudfunction/quickstartFunctions/index.js: -------------------------------------------------------------------------------- 1 | const getOpenId = require('./getOpenId/index'); 2 | const getMiniProgramCode = require('./getMiniProgramCode/index'); 3 | const createCollection = require('./createCollection/index'); 4 | const fetchGoodsList = require('./fetchGoodsList/index'); 5 | const genMpQrcode = require('./genMpQrcode/index'); 6 | const getGroupEnterInfo = require('./getGroupEnterInfo/index') 7 | const addRecord = require('./addRecord') 8 | const selectRecord = require('./selectRecord/index'); 9 | const signIn = require('./signIn/index'); 10 | const fetchActivityList = require('./fetchActivityList') 11 | const clearCollection = require('./clearCollection/index') 12 | const updateRecord = require('./updateRecord/index') 13 | 14 | // 云函数入口函数 15 | exports.main = async (event, context) => { 16 | switch (event.type) { 17 | case 'getOpenId': 18 | return await getOpenId.main(event, context); 19 | case 'getMiniProgramCode': 20 | return await getMiniProgramCode.main(event, context); 21 | case 'createCollection': 22 | return await createCollection.main(event, context); 23 | case 'updateRecord': 24 | return await updateRecord.main(event, context); 25 | case 'fetchGoodsList': 26 | return await fetchGoodsList.main(event, context); 27 | case 'genMpQrcode': 28 | return await genMpQrcode.main(event, context); 29 | case 'getGroupEnterInfo': 30 | return await getGroupEnterInfo.main(event, context); 31 | case 'addRecord': 32 | return await addRecord.main(event, context) 33 | case 'fetchActivityList': 34 | return await fetchActivityList.main(event, context) 35 | case 'selectRecord': 36 | return await selectRecord.main(event, context); 37 | case 'signIn': 38 | return await signIn.main(event, context) 39 | case 'clearCollection': 40 | return await clearCollection.main(event, context) 41 | case 'updateRecord': 42 | return await updateRecord.main(event, context) 43 | } 44 | }; 45 | 46 | -------------------------------------------------------------------------------- /cloudfunction/quickstartFunctions/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "quickstartFunctions", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "wx-server-sdk": "~2.4.0" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /cloudfunction/quickstartFunctions/selectRecord/index.js: -------------------------------------------------------------------------------- 1 | const cloud = require('wx-server-sdk'); 2 | 3 | cloud.init({ 4 | env: cloud.DYNAMIC_CURRENT_ENV 5 | }); 6 | const db = cloud.database(); 7 | 8 | // 查询数据库集合云函数入口函数 9 | exports.main = async (event, context) => { 10 | // 返回数据库查询结果 11 | try { 12 | const resp = await db.collection('activity').where({ 13 | activityId: event.activityId 14 | }).get(); 15 | 16 | if (resp.data.length) { 17 | return { 18 | success: true, 19 | activityInfo: resp.data[0], 20 | } 21 | } else { 22 | return { 23 | success: false, 24 | errMsg: '未找到活动' 25 | } 26 | } 27 | 28 | } catch (error) { 29 | return { 30 | success: false, 31 | errMsg: error 32 | } 33 | } 34 | }; 35 | -------------------------------------------------------------------------------- /cloudfunction/quickstartFunctions/signIn/index.js: -------------------------------------------------------------------------------- 1 | const cloud = require('wx-server-sdk'); 2 | 3 | cloud.init({ 4 | env: cloud.DYNAMIC_CURRENT_ENV 5 | }); 6 | const db = cloud.database(); 7 | 8 | // 查询数据库集合云函数入口函数 9 | exports.main = async (event, context) => { 10 | // 返回数据库查询结果 11 | const { groupOpenID, roomid, activityId } = event 12 | 13 | const resp = await db.collection('activity').where({ 14 | activityId 15 | }).get(); 16 | 17 | if (!resp.data || !resp.data.length) { 18 | return { 19 | success: false, 20 | errMsg: '未找到对应活动' 21 | } 22 | } 23 | 24 | const activityInfo = resp.data[0] 25 | 26 | if (activityInfo.roomid !== roomid) { 27 | return { 28 | success: false, 29 | errMsg: '非活动绑定群用户' 30 | } 31 | } 32 | 33 | const _ = db.command 34 | 35 | const updateResp = await db.collection('activity').doc(activityInfo._id).update({ 36 | data: { 37 | signIn: _.push(groupOpenID) 38 | } 39 | }) 40 | 41 | return { 42 | success: true, 43 | } 44 | }; 45 | -------------------------------------------------------------------------------- /cloudfunction/quickstartFunctions/updateRecord/index.js: -------------------------------------------------------------------------------- 1 | const cloud = require('wx-server-sdk'); 2 | 3 | cloud.init({ 4 | env: cloud.DYNAMIC_CURRENT_ENV 5 | }); 6 | const db = cloud.database(); 7 | 8 | // 查询数据库集合云函数入口函数 9 | exports.main = async (event, context) => { 10 | // 返回数据库查询结果 11 | const { targetState, activityId } = event 12 | 13 | const resp = await db.collection('activity').where({ 14 | activityId 15 | }).get(); 16 | 17 | if (!resp.data || !resp.data.length) { 18 | return { 19 | success: false, 20 | errMsg: '未找到对应活动' 21 | } 22 | } 23 | 24 | const activityInfo = resp.data[0] 25 | 26 | const _ = db.command 27 | 28 | const updateResp = await db.collection('activity').doc(activityInfo._id).update({ 29 | data: { 30 | targetState, 31 | } 32 | }) 33 | 34 | return { 35 | success: true, 36 | } 37 | }; 38 | -------------------------------------------------------------------------------- /minicode/getUserInfo/.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist -------------------------------------------------------------------------------- /minicode/getUserInfo/.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true, 3 | "trailingComma": "all" 4 | } -------------------------------------------------------------------------------- /minicode/getUserInfo/README.md: -------------------------------------------------------------------------------- 1 | ## 小游戏代码片段 2 | 3 | ### 配置环境 4 | `npm install` 5 | 6 | ### 开发阶段 7 | `npm run watch` 8 | 9 | ### 发布阶段 10 | 1. 左上角菜单栏-项目-新建代码片段(拷贝当前项目) 11 | 2. 分享-生成分享链接 -------------------------------------------------------------------------------- /minicode/getUserInfo/minigame/common/const.js: -------------------------------------------------------------------------------- 1 | export var Platform; 2 | (function (Platform) { 3 | Platform["devtools"] = "devtools"; 4 | Platform["android"] = "android"; 5 | Platform["ios"] = "ios"; 6 | Platform["windows"] = "windows"; 7 | Platform["mac"] = "mac"; 8 | })(Platform || (Platform = {})); 9 | export var DeviceOrientation; 10 | (function (DeviceOrientation) { 11 | DeviceOrientation["portrait"] = "portrait"; 12 | DeviceOrientation["landscape"] = "landscape"; 13 | DeviceOrientation["landscapeLeft"] = "landscapeLeft"; 14 | DeviceOrientation["landscapeRight"] = "landscapeRight"; 15 | })(DeviceOrientation || (DeviceOrientation = {})); 16 | export var EnvType; 17 | (function (EnvType) { 18 | EnvType["DEVELOP"] = "develop"; 19 | EnvType["TRIAL"] = "trial"; 20 | EnvType["RELEASE"] = "release"; 21 | })(EnvType || (EnvType = {})); 22 | export var AppStateType; 23 | (function (AppStateType) { 24 | AppStateType[AppStateType["release"] = 1] = "release"; 25 | AppStateType[AppStateType["develop"] = 2] = "develop"; 26 | AppStateType[AppStateType["trial"] = 3] = "trial"; 27 | })(AppStateType || (AppStateType = {})); 28 | -------------------------------------------------------------------------------- /minicode/getUserInfo/minigame/common/const.ts: -------------------------------------------------------------------------------- 1 | export enum Platform { 2 | devtools = 'devtools', 3 | android = 'android', 4 | ios = 'ios', 5 | windows = 'windows', 6 | mac = 'mac', 7 | } 8 | 9 | export enum DeviceOrientation { 10 | portrait = 'portrait', 11 | landscape = 'landscape', 12 | landscapeLeft = 'landscapeLeft', 13 | landscapeRight = 'landscapeRight', 14 | } 15 | 16 | export enum EnvType { 17 | DEVELOP = 'develop', 18 | TRIAL = 'trial', 19 | RELEASE = 'release', 20 | } 21 | 22 | export enum AppStateType { 23 | release = 1, 24 | develop = 2, 25 | trial = 3, 26 | } 27 | -------------------------------------------------------------------------------- /minicode/getUserInfo/minigame/common/scene.js: -------------------------------------------------------------------------------- 1 | import { TinyEmitter } from '../libs/tinyemitter'; 2 | class Scene extends TinyEmitter { 3 | _scenes = []; 4 | _currentIndex = 0; 5 | init(data) { 6 | this._scenes = data; 7 | this.emit('sceneChanged'); 8 | this.currentScene.exposed?.(); 9 | } 10 | get currentIndex() { 11 | return this._currentIndex; 12 | } 13 | get currentScene() { 14 | return this._scenes[this._currentIndex]; 15 | } 16 | nextScene() { 17 | this.currentScene.destroyed?.(); 18 | this._currentIndex += 1; 19 | if (this._currentIndex > this._scenes.length - 1) { 20 | this._currentIndex = 0; 21 | } 22 | this.emit('sceneChanged'); 23 | } 24 | preScene() { 25 | this.currentScene.destroyed?.(); 26 | this._currentIndex -= 1; 27 | if (this._currentIndex < 0) { 28 | this._currentIndex = this._scenes.length - 1; 29 | } 30 | this.emit('sceneChanged'); 31 | } 32 | } 33 | export const scene = new Scene(); 34 | -------------------------------------------------------------------------------- /minicode/getUserInfo/minigame/common/scene.ts: -------------------------------------------------------------------------------- 1 | import { TinyEmitter } from '../libs/tinyemitter'; 2 | 3 | interface SceneData { 4 | title: string; 5 | explanation?: string; 6 | buttons?: { name: string; callback: () => void }[]; 7 | exposed?: () => void; 8 | destroyed?: () => void; 9 | } 10 | 11 | class Scene extends TinyEmitter { 12 | private _scenes = [] as SceneData[]; 13 | 14 | private _currentIndex = 0; 15 | 16 | init(data: SceneData[]) { 17 | this._scenes = data; 18 | this.emit('sceneChanged'); 19 | this.currentScene.exposed?.(); 20 | } 21 | 22 | get currentIndex() { 23 | return this._currentIndex; 24 | } 25 | 26 | get currentScene() { 27 | return this._scenes[this._currentIndex]; 28 | } 29 | 30 | nextScene() { 31 | this.currentScene.destroyed?.(); 32 | this._currentIndex += 1; 33 | if (this._currentIndex > this._scenes.length - 1) { 34 | this._currentIndex = 0; 35 | } 36 | this.emit('sceneChanged'); 37 | } 38 | 39 | preScene() { 40 | this.currentScene.destroyed?.(); 41 | this._currentIndex -= 1; 42 | if (this._currentIndex < 0) { 43 | this._currentIndex = this._scenes.length - 1; 44 | } 45 | this.emit('sceneChanged'); 46 | } 47 | } 48 | 49 | export const scene = new Scene(); 50 | -------------------------------------------------------------------------------- /minicode/getUserInfo/minigame/common/utils.js: -------------------------------------------------------------------------------- 1 | import { DeviceOrientation } from './const'; 2 | /** 3 | * 暂存安全区域坐标 4 | */ 5 | let cacheSafeArea = null; 6 | /** 7 | * 获取小游戏真实的安全绘制坐标 8 | */ 9 | export function getSafeArea(systemInfo, useCache = false) { 10 | if (useCache && cacheSafeArea) { 11 | return cacheSafeArea; 12 | } 13 | let { safeArea } = systemInfo; 14 | const { deviceOrientation, screenWidth, screenHeight } = systemInfo; 15 | // 此处有一个坑,部分安卓不一定返回safeArea 16 | if (!safeArea) { 17 | safeArea = { 18 | top: 0, 19 | left: 0, 20 | right: screenWidth || 0, 21 | bottom: screenHeight || 0, 22 | width: screenWidth || 0, 23 | height: screenHeight || 0, 24 | }; 25 | } 26 | let { left, top, right, bottom, width, height } = safeArea; 27 | // 此处又是一个坑,虽然实际为横屏,但是返回的deviceOrientation为竖屏时,返回的safeArea依然是竖屏状态下的,left和top需调换 28 | if (screenWidth && screenHeight && screenWidth > screenHeight) { 29 | if (deviceOrientation === DeviceOrientation.portrait || width < height) { 30 | left = safeArea.top; 31 | top = safeArea.left; 32 | right = safeArea.bottom; 33 | bottom = safeArea.right; 34 | width = safeArea.height; 35 | height = safeArea.width; 36 | } 37 | else if (width === screenHeight && width > height) { 38 | // 此处又是一个坑,HUAWEI P20在横屏小游戏开播时,获取的safeArea宽度是360,高度是331,导致根本进不去上面其他机型的兼容判断逻辑,所以又新增一个兼容逻辑 39 | top = 0; 40 | left = 0; 41 | right = screenWidth; 42 | bottom = screenHeight; 43 | width = screenWidth; 44 | height = screenHeight; 45 | } 46 | } 47 | cacheSafeArea = { 48 | left, 49 | top, 50 | right, 51 | bottom, 52 | width, 53 | height, 54 | }; 55 | return cacheSafeArea; 56 | } 57 | -------------------------------------------------------------------------------- /minicode/getUserInfo/minigame/common/utils.ts: -------------------------------------------------------------------------------- 1 | import { DeviceOrientation } from './const'; 2 | /** 3 | * 暂存安全区域坐标 4 | */ 5 | let cacheSafeArea: WechatMinigame.SafeArea | null = null; 6 | /** 7 | * 获取小游戏真实的安全绘制坐标 8 | */ 9 | export function getSafeArea( 10 | systemInfo: WechatMinigame.SystemInfo, 11 | useCache = false, 12 | ): WechatMinigame.SafeArea { 13 | if (useCache && cacheSafeArea) { 14 | return cacheSafeArea; 15 | } 16 | let { safeArea } = systemInfo; 17 | const { deviceOrientation, screenWidth, screenHeight } = systemInfo; 18 | // 此处有一个坑,部分安卓不一定返回safeArea 19 | if (!safeArea) { 20 | safeArea = { 21 | top: 0, 22 | left: 0, 23 | right: screenWidth || 0, 24 | bottom: screenHeight || 0, 25 | width: screenWidth || 0, 26 | height: screenHeight || 0, 27 | }; 28 | } 29 | let { left, top, right, bottom, width, height } = safeArea; 30 | // 此处又是一个坑,虽然实际为横屏,但是返回的deviceOrientation为竖屏时,返回的safeArea依然是竖屏状态下的,left和top需调换 31 | if (screenWidth && screenHeight && screenWidth > screenHeight) { 32 | if (deviceOrientation === DeviceOrientation.portrait || width < height) { 33 | left = safeArea.top; 34 | top = safeArea.left; 35 | right = safeArea.bottom; 36 | bottom = safeArea.right; 37 | width = safeArea.height; 38 | height = safeArea.width; 39 | } else if (width === screenHeight && width > height) { 40 | // 此处又是一个坑,HUAWEI P20在横屏小游戏开播时,获取的safeArea宽度是360,高度是331,导致根本进不去上面其他机型的兼容判断逻辑,所以又新增一个兼容逻辑 41 | top = 0; 42 | left = 0; 43 | right = screenWidth; 44 | bottom = screenHeight; 45 | width = screenWidth; 46 | height = screenHeight; 47 | } 48 | } 49 | cacheSafeArea = { 50 | left, 51 | top, 52 | right, 53 | bottom, 54 | width, 55 | height, 56 | }; 57 | return cacheSafeArea; 58 | } 59 | -------------------------------------------------------------------------------- /minicode/getUserInfo/minigame/game.json: -------------------------------------------------------------------------------- 1 | { 2 | "deviceOrientation": "portrait", 3 | "iOSHighPerformance": true 4 | } 5 | -------------------------------------------------------------------------------- /minicode/getUserInfo/minigame/libs/richtext.d.ts: -------------------------------------------------------------------------------- 1 | import { Layout, Element } from './engine'; 2 | interface JsonNode { 3 | index: string; 4 | node: string; 5 | parent?: JsonNode; 6 | tag?: string; 7 | tagType?: string; 8 | nodes?: JsonNode[]; 9 | styleStr?: string; 10 | styleObj?: Record; 11 | text?: string; 12 | } 13 | interface IDC { 14 | filleStyle: string | null; 15 | fontStyle: string | null; 16 | fontWeight: string | null; 17 | fontSize: number | null; 18 | textAlign: CanvasTextAlign | null; 19 | text: string; 20 | x: number; 21 | y: number; 22 | } 23 | /** 24 | * @description 获取字符宽度 25 | * @param char 26 | * @param fontSize 27 | */ 28 | export declare const getCharWidth: (char: string, fontSize: number) => number; 29 | type RichTextOptions = { 30 | style?: object; 31 | idName?: string; 32 | className?: string; 33 | dataset: Record; 34 | }; 35 | export declare class RichText extends Element { 36 | private innerText; 37 | private jsonData; 38 | private dcs; 39 | fontSize?: number; 40 | textBaseline: CanvasTextBaseline; 41 | font: string; 42 | textAlign: CanvasTextAlign; 43 | fillStyle: string; 44 | constructor(opts: RichTextOptions); 45 | set text(value: string); 46 | get text(): string; 47 | setStyleForDc(currDc: IDC, styleObj: Record): void; 48 | buildDrawCallFromJsonData(jsonData: JsonNode): void; 49 | repaint(): void; 50 | destroySelf(): void; 51 | insert(ctx: CanvasRenderingContext2D, needRender: boolean): void; 52 | toCanvasData(): void; 53 | render(): void; 54 | } 55 | declare function install(layout: Layout): typeof RichText; 56 | declare const _default: { 57 | install: typeof install; 58 | name: string; 59 | }; 60 | export default _default; 61 | -------------------------------------------------------------------------------- /minicode/getUserInfo/minigame/libs/tinyemitter.d.ts: -------------------------------------------------------------------------------- 1 | export declare class TinyEmitter { 2 | on(event: string, callback: Function, ctx?: any): this; 3 | once(event: string, callback: Function, ctx?: any): this; 4 | emit(event: string, ...args: any[]): this; 5 | off(event: string, callback?: Function): this; 6 | } 7 | -------------------------------------------------------------------------------- /minicode/getUserInfo/minigame/project.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "项目配置文件。", 3 | "setting": { 4 | "urlCheck": true, 5 | "es6": true, 6 | "postcss": true, 7 | "minified": true, 8 | "babelSetting": { 9 | "ignore": [], 10 | "disablePlugins": [], 11 | "outputPath": "" 12 | } 13 | }, 14 | "compileType": "game", 15 | "libVersion": "3.3.4", 16 | "appid": "wxf616b60467bcfcaf", 17 | "projectname": "quickstart", 18 | "condition": {}, 19 | "packOptions": { 20 | "ignore": [], 21 | "include": [] 22 | }, 23 | "editorSetting": { 24 | "tabIndent": "insertSpaces", 25 | "tabSize": 2 26 | } 27 | } -------------------------------------------------------------------------------- /minicode/getUserInfo/minigame/project.private.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html", 3 | "projectname": "getUserInfo", 4 | "libVersion": "3.4.4" 5 | } -------------------------------------------------------------------------------- /minicode/getUserInfo/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "scripts": { 3 | "build": "tsc", 4 | "watch": "tsc -w", 5 | "lint": "eslint \"**/*.ts\" --fix" 6 | }, 7 | "devDependencies": { 8 | "@typescript-eslint/eslint-plugin": "^7.4.0", 9 | "eslint": "^8.57.0", 10 | "eslint-config-prettier": "^9.1.0", 11 | "eslint-plugin-prettier": "^5.1.3", 12 | "minigame-api-typings": "^3.8.4", 13 | "prettier": "^3.2.5", 14 | "typescript": "^5.4.2" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /minicode/getUserInfo/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "esnext", // 目标 ECMAScript 版本 4 | "module": "esnext", // 使用 CommonJS 模块 5 | "allowJs": false, // 允许编译 JavaScript 文件(方便逐步迁移) 6 | "checkJs": false, // 设置为 true 可检查并报告纯 JavaScript 文件中的错误 7 | "declaration": false, // 生成 ".d.ts" 声明文件 8 | "sourceMap": false, // 生成源映射以便调试 9 | "strict": true, // 启用所有严格类型检查选项 10 | "esModuleInterop": true, // 启用 ES6 模块与 CommonJS 模块的交互 11 | "moduleResolution": "node", 12 | "forceConsistentCasingInFileNames": true, // 禁止对同一文件使用不同的大小写引用 13 | "typeRoots": ["./node_modules/@types", "./node_modules/minigame-api-typings/types"], 14 | "skipLibCheck": true, 15 | }, 16 | "include": [ 17 | "minigame", 18 | ], 19 | "exclude": ["*.js"] 20 | } -------------------------------------------------------------------------------- /minicode/requestSubscribeSystemMessage/.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist -------------------------------------------------------------------------------- /minicode/requestSubscribeSystemMessage/.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true, 3 | "trailingComma": "all" 4 | } -------------------------------------------------------------------------------- /minicode/requestSubscribeSystemMessage/README.md: -------------------------------------------------------------------------------- 1 | ## 小游戏代码片段 2 | 3 | ### 配置环境 4 | `npm install` 5 | 6 | ### 开发阶段 7 | `npm run watch` 8 | 9 | ### 发布阶段 10 | 1. 左上角菜单栏-项目-新建代码片段(拷贝当前项目) 11 | 2. 分享-生成分享链接 -------------------------------------------------------------------------------- /minicode/requestSubscribeSystemMessage/minigame/game/common/const.js: -------------------------------------------------------------------------------- 1 | export var Platform; 2 | (function (Platform) { 3 | Platform["devtools"] = "devtools"; 4 | Platform["android"] = "android"; 5 | Platform["ios"] = "ios"; 6 | Platform["windows"] = "windows"; 7 | Platform["mac"] = "mac"; 8 | })(Platform || (Platform = {})); 9 | export var DeviceOrientation; 10 | (function (DeviceOrientation) { 11 | DeviceOrientation["portrait"] = "portrait"; 12 | DeviceOrientation["landscape"] = "landscape"; 13 | DeviceOrientation["landscapeLeft"] = "landscapeLeft"; 14 | DeviceOrientation["landscapeRight"] = "landscapeRight"; 15 | })(DeviceOrientation || (DeviceOrientation = {})); 16 | export var EnvType; 17 | (function (EnvType) { 18 | EnvType["DEVELOP"] = "develop"; 19 | EnvType["TRIAL"] = "trial"; 20 | EnvType["RELEASE"] = "release"; 21 | })(EnvType || (EnvType = {})); 22 | export var AppStateType; 23 | (function (AppStateType) { 24 | AppStateType[AppStateType["release"] = 1] = "release"; 25 | AppStateType[AppStateType["develop"] = 2] = "develop"; 26 | AppStateType[AppStateType["trial"] = 3] = "trial"; 27 | })(AppStateType || (AppStateType = {})); 28 | -------------------------------------------------------------------------------- /minicode/requestSubscribeSystemMessage/minigame/game/common/const.ts: -------------------------------------------------------------------------------- 1 | export enum Platform { 2 | devtools = 'devtools', 3 | android = 'android', 4 | ios = 'ios', 5 | windows = 'windows', 6 | mac = 'mac', 7 | } 8 | 9 | export enum DeviceOrientation { 10 | portrait = 'portrait', 11 | landscape = 'landscape', 12 | landscapeLeft = 'landscapeLeft', 13 | landscapeRight = 'landscapeRight', 14 | } 15 | 16 | export enum EnvType { 17 | DEVELOP = 'develop', 18 | TRIAL = 'trial', 19 | RELEASE = 'release', 20 | } 21 | 22 | export enum AppStateType { 23 | release = 1, 24 | develop = 2, 25 | trial = 3, 26 | } 27 | -------------------------------------------------------------------------------- /minicode/requestSubscribeSystemMessage/minigame/game/common/scene.js: -------------------------------------------------------------------------------- 1 | import { TinyEmitter } from '../libs/tinyemitter'; 2 | class Scene extends TinyEmitter { 3 | _scenes = []; 4 | _currentIndex = 0; 5 | init(data) { 6 | this._scenes = data; 7 | this.emit('sceneChanged'); 8 | this.currentScene.exposed?.(); 9 | } 10 | get currentIndex() { 11 | return this._currentIndex; 12 | } 13 | get currentScene() { 14 | return this._scenes[this._currentIndex]; 15 | } 16 | nextScene() { 17 | this.currentScene.destroyed?.(); 18 | this._currentIndex += 1; 19 | if (this._currentIndex > this._scenes.length - 1) { 20 | this._currentIndex = 0; 21 | } 22 | this.emit('sceneChanged'); 23 | } 24 | preScene() { 25 | this.currentScene.destroyed?.(); 26 | this._currentIndex -= 1; 27 | if (this._currentIndex < 0) { 28 | this._currentIndex = this._scenes.length - 1; 29 | } 30 | this.emit('sceneChanged'); 31 | } 32 | } 33 | export const scene = new Scene(); 34 | -------------------------------------------------------------------------------- /minicode/requestSubscribeSystemMessage/minigame/game/common/scene.ts: -------------------------------------------------------------------------------- 1 | import { TinyEmitter } from '../libs/tinyemitter'; 2 | 3 | interface SceneData { 4 | title: string; 5 | explanation?: string; 6 | buttons?: { name: string; callback: () => void }[]; 7 | exposed?: () => void; 8 | destroyed?: () => void; 9 | } 10 | 11 | class Scene extends TinyEmitter { 12 | private _scenes = [] as SceneData[]; 13 | 14 | private _currentIndex = 0; 15 | 16 | init(data: SceneData[]) { 17 | this._scenes = data; 18 | this.emit('sceneChanged'); 19 | this.currentScene.exposed?.(); 20 | } 21 | 22 | get currentIndex() { 23 | return this._currentIndex; 24 | } 25 | 26 | get currentScene() { 27 | return this._scenes[this._currentIndex]; 28 | } 29 | 30 | nextScene() { 31 | this.currentScene.destroyed?.(); 32 | this._currentIndex += 1; 33 | if (this._currentIndex > this._scenes.length - 1) { 34 | this._currentIndex = 0; 35 | } 36 | this.emit('sceneChanged'); 37 | } 38 | 39 | preScene() { 40 | this.currentScene.destroyed?.(); 41 | this._currentIndex -= 1; 42 | if (this._currentIndex < 0) { 43 | this._currentIndex = this._scenes.length - 1; 44 | } 45 | this.emit('sceneChanged'); 46 | } 47 | } 48 | 49 | export const scene = new Scene(); 50 | -------------------------------------------------------------------------------- /minicode/requestSubscribeSystemMessage/minigame/game/common/utils.js: -------------------------------------------------------------------------------- 1 | import { DeviceOrientation } from './const'; 2 | /** 3 | * 暂存安全区域坐标 4 | */ 5 | let cacheSafeArea = null; 6 | /** 7 | * 获取小游戏真实的安全绘制坐标 8 | */ 9 | export function getSafeArea(systemInfo, useCache = false) { 10 | if (useCache && cacheSafeArea) { 11 | return cacheSafeArea; 12 | } 13 | let { safeArea } = systemInfo; 14 | const { deviceOrientation, screenWidth, screenHeight } = systemInfo; 15 | // 此处有一个坑,部分安卓不一定返回safeArea 16 | if (!safeArea) { 17 | safeArea = { 18 | top: 0, 19 | left: 0, 20 | right: screenWidth || 0, 21 | bottom: screenHeight || 0, 22 | width: screenWidth || 0, 23 | height: screenHeight || 0, 24 | }; 25 | } 26 | let { left, top, right, bottom, width, height } = safeArea; 27 | // 此处又是一个坑,虽然实际为横屏,但是返回的deviceOrientation为竖屏时,返回的safeArea依然是竖屏状态下的,left和top需调换 28 | if (screenWidth && screenHeight && screenWidth > screenHeight) { 29 | if (deviceOrientation === DeviceOrientation.portrait || width < height) { 30 | left = safeArea.top; 31 | top = safeArea.left; 32 | right = safeArea.bottom; 33 | bottom = safeArea.right; 34 | width = safeArea.height; 35 | height = safeArea.width; 36 | } 37 | else if (width === screenHeight && width > height) { 38 | // 此处又是一个坑,HUAWEI P20在横屏小游戏开播时,获取的safeArea宽度是360,高度是331,导致根本进不去上面其他机型的兼容判断逻辑,所以又新增一个兼容逻辑 39 | top = 0; 40 | left = 0; 41 | right = screenWidth; 42 | bottom = screenHeight; 43 | width = screenWidth; 44 | height = screenHeight; 45 | } 46 | } 47 | cacheSafeArea = { 48 | left, 49 | top, 50 | right, 51 | bottom, 52 | width, 53 | height, 54 | }; 55 | return cacheSafeArea; 56 | } 57 | -------------------------------------------------------------------------------- /minicode/requestSubscribeSystemMessage/minigame/game/common/utils.ts: -------------------------------------------------------------------------------- 1 | import { DeviceOrientation } from './const'; 2 | /** 3 | * 暂存安全区域坐标 4 | */ 5 | let cacheSafeArea: WechatMinigame.SafeArea | null = null; 6 | /** 7 | * 获取小游戏真实的安全绘制坐标 8 | */ 9 | export function getSafeArea( 10 | systemInfo: WechatMinigame.SystemInfo, 11 | useCache = false, 12 | ): WechatMinigame.SafeArea { 13 | if (useCache && cacheSafeArea) { 14 | return cacheSafeArea; 15 | } 16 | let { safeArea } = systemInfo; 17 | const { deviceOrientation, screenWidth, screenHeight } = systemInfo; 18 | // 此处有一个坑,部分安卓不一定返回safeArea 19 | if (!safeArea) { 20 | safeArea = { 21 | top: 0, 22 | left: 0, 23 | right: screenWidth || 0, 24 | bottom: screenHeight || 0, 25 | width: screenWidth || 0, 26 | height: screenHeight || 0, 27 | }; 28 | } 29 | let { left, top, right, bottom, width, height } = safeArea; 30 | // 此处又是一个坑,虽然实际为横屏,但是返回的deviceOrientation为竖屏时,返回的safeArea依然是竖屏状态下的,left和top需调换 31 | if (screenWidth && screenHeight && screenWidth > screenHeight) { 32 | if (deviceOrientation === DeviceOrientation.portrait || width < height) { 33 | left = safeArea.top; 34 | top = safeArea.left; 35 | right = safeArea.bottom; 36 | bottom = safeArea.right; 37 | width = safeArea.height; 38 | height = safeArea.width; 39 | } else if (width === screenHeight && width > height) { 40 | // 此处又是一个坑,HUAWEI P20在横屏小游戏开播时,获取的safeArea宽度是360,高度是331,导致根本进不去上面其他机型的兼容判断逻辑,所以又新增一个兼容逻辑 41 | top = 0; 42 | left = 0; 43 | right = screenWidth; 44 | bottom = screenHeight; 45 | width = screenWidth; 46 | height = screenHeight; 47 | } 48 | } 49 | cacheSafeArea = { 50 | left, 51 | top, 52 | right, 53 | bottom, 54 | width, 55 | height, 56 | }; 57 | return cacheSafeArea; 58 | } 59 | -------------------------------------------------------------------------------- /minicode/requestSubscribeSystemMessage/minigame/game/game.json: -------------------------------------------------------------------------------- 1 | { 2 | "deviceOrientation": "portrait", 3 | "iOSHighPerformance": true, 4 | "openDataContext": "openDataContext", 5 | "modifyFriendInteractiveStorageTemplates": [ 6 | { 7 | "key": "1", 8 | "action": "赠送", 9 | "object": "金币", 10 | "ratio": 10 11 | } 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /minicode/requestSubscribeSystemMessage/minigame/game/libs/richtext.d.ts: -------------------------------------------------------------------------------- 1 | import { Layout, Element } from './engine'; 2 | interface JsonNode { 3 | index: string; 4 | node: string; 5 | parent?: JsonNode; 6 | tag?: string; 7 | tagType?: string; 8 | nodes?: JsonNode[]; 9 | styleStr?: string; 10 | styleObj?: Record; 11 | text?: string; 12 | } 13 | interface IDC { 14 | filleStyle: string | null; 15 | fontStyle: string | null; 16 | fontWeight: string | null; 17 | fontSize: number | null; 18 | textAlign: CanvasTextAlign | null; 19 | text: string; 20 | x: number; 21 | y: number; 22 | } 23 | /** 24 | * @description 获取字符宽度 25 | * @param char 26 | * @param fontSize 27 | */ 28 | export declare const getCharWidth: (char: string, fontSize: number) => number; 29 | type RichTextOptions = { 30 | style?: object; 31 | idName?: string; 32 | className?: string; 33 | dataset: Record; 34 | }; 35 | export declare class RichText extends Element { 36 | private innerText; 37 | private jsonData; 38 | private dcs; 39 | fontSize?: number; 40 | textBaseline: CanvasTextBaseline; 41 | font: string; 42 | textAlign: CanvasTextAlign; 43 | fillStyle: string; 44 | constructor(opts: RichTextOptions); 45 | set text(value: string); 46 | get text(): string; 47 | setStyleForDc(currDc: IDC, styleObj: Record): void; 48 | buildDrawCallFromJsonData(jsonData: JsonNode): void; 49 | repaint(): void; 50 | destroySelf(): void; 51 | insert(ctx: CanvasRenderingContext2D, needRender: boolean): void; 52 | toCanvasData(): void; 53 | render(): void; 54 | } 55 | declare function install(layout: Layout): typeof RichText; 56 | declare const _default: { 57 | install: typeof install; 58 | name: string; 59 | }; 60 | export default _default; 61 | -------------------------------------------------------------------------------- /minicode/requestSubscribeSystemMessage/minigame/game/libs/tinyemitter.d.ts: -------------------------------------------------------------------------------- 1 | export declare class TinyEmitter { 2 | on(event: string, callback: Function, ctx?: any): this; 3 | once(event: string, callback: Function, ctx?: any): this; 4 | emit(event: string, ...args: any[]): this; 5 | off(event: string, callback?: Function): this; 6 | } 7 | -------------------------------------------------------------------------------- /minicode/requestSubscribeSystemMessage/minigame/game/openDataContext/index.js: -------------------------------------------------------------------------------- 1 | import { getInteractUI } from './friend_interactive'; 2 | wx.onMessage((res) => { 3 | if (res.command === 'renderFriend') { 4 | setData(100); 5 | getDataAndDraw(false, res.box); 6 | } 7 | // else { 8 | // setData(res.score); 9 | // getDataAndDraw(true, res.box); 10 | // } 11 | }); 12 | function setData(score) { 13 | wx.setUserCloudStorage({ 14 | KVDataList: [ 15 | { 16 | key: 'score', 17 | value: JSON.stringify(score), 18 | }, 19 | ], 20 | success: (res) => { 21 | console.log('setData => ', res); 22 | }, 23 | fail: (res) => { 24 | console.log('setData => ', res); 25 | }, 26 | }); 27 | } 28 | function getDataAndDraw(flag, box) { 29 | wx.getFriendCloudStorage({ 30 | keyList: ['score'], 31 | success: (res) => { 32 | console.log('getData => ', res); 33 | if (!flag) { 34 | getInteractUI(res.data, box); 35 | } 36 | }, 37 | fail: (res) => { 38 | console.log('getData => ', res); 39 | }, 40 | }); 41 | } 42 | -------------------------------------------------------------------------------- /minicode/requestSubscribeSystemMessage/minigame/game/openDataContext/index.ts: -------------------------------------------------------------------------------- 1 | import { getInteractUI } from './friend_interactive'; 2 | import { Box } from './type'; 3 | 4 | wx.onMessage((res) => { 5 | if (res.command === 'renderFriend') { 6 | setData(100); 7 | getDataAndDraw(false, res.box); 8 | } 9 | // else { 10 | // setData(res.score); 11 | // getDataAndDraw(true, res.box); 12 | // } 13 | }); 14 | 15 | function setData(score: number) { 16 | wx.setUserCloudStorage({ 17 | KVDataList: [ 18 | { 19 | key: 'score', 20 | value: JSON.stringify(score), 21 | }, 22 | ], 23 | success: (res) => { 24 | console.log('setData => ', res); 25 | }, 26 | fail: (res) => { 27 | console.log('setData => ', res); 28 | }, 29 | }); 30 | } 31 | 32 | function getDataAndDraw(flag: boolean, box: Box) { 33 | wx.getFriendCloudStorage({ 34 | keyList: ['score'], 35 | success: (res) => { 36 | console.log('getData => ', res); 37 | if (!flag) { 38 | getInteractUI(res.data, box); 39 | } 40 | }, 41 | fail: (res) => { 42 | console.log('getData => ', res); 43 | }, 44 | }); 45 | } 46 | -------------------------------------------------------------------------------- /minicode/requestSubscribeSystemMessage/minigame/game/openDataContext/libs/richtext.d.ts: -------------------------------------------------------------------------------- 1 | import { Layout, Element } from './engine'; 2 | interface JsonNode { 3 | index: string; 4 | node: string; 5 | parent?: JsonNode; 6 | tag?: string; 7 | tagType?: string; 8 | nodes?: JsonNode[]; 9 | styleStr?: string; 10 | styleObj?: Record; 11 | text?: string; 12 | } 13 | interface IDC { 14 | filleStyle: string | null; 15 | fontStyle: string | null; 16 | fontWeight: string | null; 17 | fontSize: number | null; 18 | textAlign: CanvasTextAlign | null; 19 | text: string; 20 | x: number; 21 | y: number; 22 | } 23 | /** 24 | * @description 获取字符宽度 25 | * @param char 26 | * @param fontSize 27 | */ 28 | export declare const getCharWidth: (char: string, fontSize: number) => number; 29 | type RichTextOptions = { 30 | style?: object; 31 | idName?: string; 32 | className?: string; 33 | dataset: Record; 34 | }; 35 | export declare class RichText extends Element { 36 | private innerText; 37 | private jsonData; 38 | private dcs; 39 | fontSize?: number; 40 | textBaseline: CanvasTextBaseline; 41 | font: string; 42 | textAlign: CanvasTextAlign; 43 | fillStyle: string; 44 | constructor(opts: RichTextOptions); 45 | set text(value: string); 46 | get text(): string; 47 | setStyleForDc(currDc: IDC, styleObj: Record): void; 48 | buildDrawCallFromJsonData(jsonData: JsonNode): void; 49 | repaint(): void; 50 | destroySelf(): void; 51 | insert(ctx: CanvasRenderingContext2D, needRender: boolean): void; 52 | toCanvasData(): void; 53 | render(): void; 54 | } 55 | declare function install(layout: Layout): typeof RichText; 56 | declare const _default: { 57 | install: typeof install; 58 | name: string; 59 | }; 60 | export default _default; 61 | -------------------------------------------------------------------------------- /minicode/requestSubscribeSystemMessage/minigame/game/openDataContext/libs/tinyemitter.d.ts: -------------------------------------------------------------------------------- 1 | export declare class TinyEmitter { 2 | on(event: string, callback: Function, ctx?: any): this; 3 | once(event: string, callback: Function, ctx?: any): this; 4 | emit(event: string, ...args: any[]): this; 5 | off(event: string, callback?: Function): this; 6 | } 7 | -------------------------------------------------------------------------------- /minicode/requestSubscribeSystemMessage/minigame/game/openDataContext/type.js: -------------------------------------------------------------------------------- 1 | export {}; 2 | -------------------------------------------------------------------------------- /minicode/requestSubscribeSystemMessage/minigame/game/openDataContext/type.ts: -------------------------------------------------------------------------------- 1 | interface UserData { 2 | avatarUrl: string; 3 | nickname: string; 4 | openid: string; 5 | } 6 | 7 | interface Box { 8 | x: number; 9 | y: number; 10 | width: number; 11 | height: number; 12 | } 13 | 14 | export { UserData, Box }; 15 | -------------------------------------------------------------------------------- /minicode/requestSubscribeSystemMessage/minigame/jsserver/checkInteractiveData.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // 简单的jsserver代码 3 | exports.main = function (req) { 4 | console.log(req); 5 | const ok = check(); // 游戏侧自行实现校验修改逻辑 6 | if (ok) { 7 | // 验证通过 8 | return JSON.stringify({ ret: true }); 9 | } 10 | else { 11 | // 验证不通过 12 | return JSON.stringify({ ret: false }); 13 | } 14 | }; 15 | function check() { 16 | return true; 17 | } 18 | -------------------------------------------------------------------------------- /minicode/requestSubscribeSystemMessage/minigame/jsserver/checkInteractiveData.ts: -------------------------------------------------------------------------------- 1 | // 简单的jsserver代码 2 | exports.main = function (req: unknown) { 3 | console.log(req); 4 | const ok = check(); // 游戏侧自行实现校验修改逻辑 5 | if (ok) { 6 | // 验证通过 7 | return JSON.stringify({ ret: true }); 8 | } else { 9 | // 验证不通过 10 | return JSON.stringify({ ret: false }); 11 | } 12 | }; 13 | 14 | function check() { 15 | return true; 16 | } 17 | -------------------------------------------------------------------------------- /minicode/requestSubscribeSystemMessage/minigame/project.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "项目配置文件。", 3 | "setting": { 4 | "urlCheck": true, 5 | "es6": true, 6 | "postcss": true, 7 | "minified": true, 8 | "babelSetting": { 9 | "ignore": [], 10 | "disablePlugins": [], 11 | "outputPath": "" 12 | }, 13 | "enhance": true 14 | }, 15 | "miniprogramRoot": "game/", 16 | "compileType": "game", 17 | "libVersion": "3.3.4", 18 | "appid": "wx7a727ff7d940bb3f", 19 | "projectname": "quickstart", 20 | "condition": {}, 21 | "packOptions": { 22 | "ignore": [], 23 | "include": [] 24 | }, 25 | "editorSetting": { 26 | "tabIndent": "insertSpaces", 27 | "tabSize": 2 28 | }, 29 | "jsserverRoot": "jsserver/", 30 | "srcMiniprogramRoot": "game/" 31 | } -------------------------------------------------------------------------------- /minicode/requestSubscribeSystemMessage/minigame/project.private.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html", 3 | "projectname": "requestSubscribeSystemMessage", 4 | "libVersion": "3.4.6", 5 | "setting": { 6 | "urlCheck": false 7 | } 8 | } -------------------------------------------------------------------------------- /minicode/requestSubscribeSystemMessage/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "scripts": { 3 | "build": "tsc", 4 | "watch": "tsc -w", 5 | "lint": "eslint \"**/*.ts\" --fix" 6 | }, 7 | "devDependencies": { 8 | "@typescript-eslint/eslint-plugin": "^7.4.0", 9 | "eslint": "^8.57.0", 10 | "eslint-config-prettier": "^9.1.0", 11 | "eslint-plugin-prettier": "^5.1.3", 12 | "minigame-api-typings": "^3.8.4", 13 | "prettier": "^3.2.5", 14 | "typescript": "^5.4.2" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /minicode/requestSubscribeSystemMessage/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "esnext", // 目标 ECMAScript 版本 4 | "module": "esnext", // 使用 CommonJS 模块 5 | "allowJs": false, // 允许编译 JavaScript 文件(方便逐步迁移) 6 | "checkJs": false, // 设置为 true 可检查并报告纯 JavaScript 文件中的错误 7 | "declaration": false, // 生成 ".d.ts" 声明文件 8 | "sourceMap": false, // 生成源映射以便调试 9 | "strict": true, // 启用所有严格类型检查选项 10 | "esModuleInterop": true, // 启用 ES6 模块与 CommonJS 模块的交互 11 | "moduleResolution": "node", 12 | "forceConsistentCasingInFileNames": true, // 禁止对同一文件使用不同的大小写引用 13 | "typeRoots": ["./node_modules/@types", "./node_modules/minigame-api-typings/types"], 14 | "skipLibCheck": true, 15 | }, 16 | "include": [ 17 | "minigame", 18 | ], 19 | "exclude": ["*.js"] 20 | } -------------------------------------------------------------------------------- /miniprogram/TencentSans-W7.subset.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-demo/de1c8edf16cf8bf3d9432f83e1f0d397598e70a3/miniprogram/TencentSans-W7.subset.ttf -------------------------------------------------------------------------------- /miniprogram/game.json: -------------------------------------------------------------------------------- 1 | { 2 | "deviceOrientation": "portrait", 3 | "iOSHighPerformance": false, 4 | "showStatusBar": false, 5 | "networkTimeout": { 6 | "request": 5000, 7 | "connectSocket": 5000, 8 | "uploadFile": 5000, 9 | "downloadFile": 5000 10 | }, 11 | "workers": "workers", 12 | "subpackages": [ 13 | { 14 | "name": "api", 15 | "root": "js/api/" 16 | } 17 | ], 18 | "permission": { 19 | "scope.userLocation": { 20 | "desc": "你的位置信息将用于小程序位置接口的效果展示" 21 | } 22 | }, 23 | "openDataContext": "sub", 24 | "modifyFriendInteractiveStorageTemplates": [ 25 | { 26 | "key": "1", 27 | "action": "赠与", 28 | "object": "金币", 29 | "ratio": 1 30 | } 31 | ], 32 | "modifyFriendInteractiveStorageConfirmWording": "赠与${nickname}金币 x 1?", 33 | "serviceProviderTicket": "t8RALNXjJmVCzQVBT5GnaTorQZUub2XaypXejDPa1tAlV6WNON/+ZcbgUzPfAD0E3Wl6RfEOKn7jbehPOElElmD3ZC8RpQv3yHo=", 34 | "navigateToMiniProgramAppIdList": ["wx4f4a4549a1069d03"], 35 | "plugins":{ 36 | "Layout": { 37 | "version": "1.0.15", 38 | "provider": "wx7a727ff7d940bb3f", 39 | "contexts":[{"type":"openDataContext"}] 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /miniprogram/images/AD.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-demo/de1c8edf16cf8bf3d9432f83e1f0d397598e70a3/miniprogram/images/AD.png -------------------------------------------------------------------------------- /miniprogram/images/APIicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-demo/de1c8edf16cf8bf3d9432f83e1f0d397598e70a3/miniprogram/images/APIicon.png -------------------------------------------------------------------------------- /miniprogram/images/Group 3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-demo/de1c8edf16cf8bf3d9432f83e1f0d397598e70a3/miniprogram/images/Group 3.png -------------------------------------------------------------------------------- /miniprogram/images/abilityOpen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-demo/de1c8edf16cf8bf3d9432f83e1f0d397598e70a3/miniprogram/images/abilityOpen.png -------------------------------------------------------------------------------- /miniprogram/images/chatTool.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-demo/de1c8edf16cf8bf3d9432f83e1f0d397598e70a3/miniprogram/images/chatTool.png -------------------------------------------------------------------------------- /miniprogram/images/circleFriends.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-demo/de1c8edf16cf8bf3d9432f83e1f0d397598e70a3/miniprogram/images/circleFriends.png -------------------------------------------------------------------------------- /miniprogram/images/contact.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-demo/de1c8edf16cf8bf3d9432f83e1f0d397598e70a3/miniprogram/images/contact.png -------------------------------------------------------------------------------- /miniprogram/images/customerService.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-demo/de1c8edf16cf8bf3d9432f83e1f0d397598e70a3/miniprogram/images/customerService.png -------------------------------------------------------------------------------- /miniprogram/images/facility.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-demo/de1c8edf16cf8bf3d9432f83e1f0d397598e70a3/miniprogram/images/facility.png -------------------------------------------------------------------------------- /miniprogram/images/ic-line-done.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-demo/de1c8edf16cf8bf3d9432f83e1f0d397598e70a3/miniprogram/images/ic-line-done.png -------------------------------------------------------------------------------- /miniprogram/images/ic-line-iconsd-share.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-demo/de1c8edf16cf8bf3d9432f83e1f0d397598e70a3/miniprogram/images/ic-line-iconsd-share.png -------------------------------------------------------------------------------- /miniprogram/images/interface.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-demo/de1c8edf16cf8bf3d9432f83e1f0d397598e70a3/miniprogram/images/interface.png -------------------------------------------------------------------------------- /miniprogram/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-demo/de1c8edf16cf8bf3d9432f83e1f0d397598e70a3/miniprogram/images/logo.png -------------------------------------------------------------------------------- /miniprogram/images/media.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-demo/de1c8edf16cf8bf3d9432f83e1f0d397598e70a3/miniprogram/images/media.png -------------------------------------------------------------------------------- /miniprogram/images/miniGame.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-demo/de1c8edf16cf8bf3d9432f83e1f0d397598e70a3/miniprogram/images/miniGame.png -------------------------------------------------------------------------------- /miniprogram/images/network.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-demo/de1c8edf16cf8bf3d9432f83e1f0d397598e70a3/miniprogram/images/network.png -------------------------------------------------------------------------------- /miniprogram/images/off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-demo/de1c8edf16cf8bf3d9432f83e1f0d397598e70a3/miniprogram/images/off.png -------------------------------------------------------------------------------- /miniprogram/images/official.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-demo/de1c8edf16cf8bf3d9432f83e1f0d397598e70a3/miniprogram/images/official.png -------------------------------------------------------------------------------- /miniprogram/images/on.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-demo/de1c8edf16cf8bf3d9432f83e1f0d397598e70a3/miniprogram/images/on.png -------------------------------------------------------------------------------- /miniprogram/images/pause.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-demo/de1c8edf16cf8bf3d9432f83e1f0d397598e70a3/miniprogram/images/pause.png -------------------------------------------------------------------------------- /miniprogram/images/pitch_on.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-demo/de1c8edf16cf8bf3d9432f83e1f0d397598e70a3/miniprogram/images/pitch_on.png -------------------------------------------------------------------------------- /miniprogram/images/play.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-demo/de1c8edf16cf8bf3d9432f83e1f0d397598e70a3/miniprogram/images/play.png -------------------------------------------------------------------------------- /miniprogram/images/recommend.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-demo/de1c8edf16cf8bf3d9432f83e1f0d397598e70a3/miniprogram/images/recommend.png -------------------------------------------------------------------------------- /miniprogram/images/record.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-demo/de1c8edf16cf8bf3d9432f83e1f0d397598e70a3/miniprogram/images/record.png -------------------------------------------------------------------------------- /miniprogram/images/rendering.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-demo/de1c8edf16cf8bf3d9432f83e1f0d397598e70a3/miniprogram/images/rendering.png -------------------------------------------------------------------------------- /miniprogram/images/right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-demo/de1c8edf16cf8bf3d9432f83e1f0d397598e70a3/miniprogram/images/right.png -------------------------------------------------------------------------------- /miniprogram/images/right_arrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-demo/de1c8edf16cf8bf3d9432f83e1f0d397598e70a3/miniprogram/images/right_arrow.png -------------------------------------------------------------------------------- /miniprogram/images/right_arrow_black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-demo/de1c8edf16cf8bf3d9432f83e1f0d397598e70a3/miniprogram/images/right_arrow_black.png -------------------------------------------------------------------------------- /miniprogram/images/share.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-demo/de1c8edf16cf8bf3d9432f83e1f0d397598e70a3/miniprogram/images/share.png -------------------------------------------------------------------------------- /miniprogram/images/star.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-demo/de1c8edf16cf8bf3d9432f83e1f0d397598e70a3/miniprogram/images/star.png -------------------------------------------------------------------------------- /miniprogram/images/stop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-demo/de1c8edf16cf8bf3d9432f83e1f0d397598e70a3/miniprogram/images/stop.png -------------------------------------------------------------------------------- /miniprogram/images/storage-fileSystem.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-demo/de1c8edf16cf8bf3d9432f83e1f0d397598e70a3/miniprogram/images/storage-fileSystem.png -------------------------------------------------------------------------------- /miniprogram/images/trash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-demo/de1c8edf16cf8bf3d9432f83e1f0d397598e70a3/miniprogram/images/trash.png -------------------------------------------------------------------------------- /miniprogram/images/visionkit-ability.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-demo/de1c8edf16cf8bf3d9432f83e1f0d397598e70a3/miniprogram/images/visionkit-ability.png -------------------------------------------------------------------------------- /miniprogram/images/weapp.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-demo/de1c8edf16cf8bf3d9432f83e1f0d397598e70a3/miniprogram/images/weapp.jpg -------------------------------------------------------------------------------- /miniprogram/images/worker.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-demo/de1c8edf16cf8bf3d9432f83e1f0d397598e70a3/miniprogram/images/worker.png -------------------------------------------------------------------------------- /miniprogram/js/api/AD/createInterstitialAd/index.js: -------------------------------------------------------------------------------- 1 | import view from './view'; 2 | import * as show from '../../../libs/show'; 3 | module.exports = function(PIXI, app, obj) { 4 | let interstitialAd, 5 | codeObj = { 6 | 1000: '后端接口调用失败', 7 | 1001: '参数错误', 8 | 1002: '广告单元无效', 9 | 1003: '内部错误', 10 | 1004: '无合适的广告', 11 | 1005: '广告组件审核中', 12 | 1006: '广告组件被驳回', 13 | 1007: '广告组件被封禁', 14 | 1008: '广告单元已关闭' 15 | }; 16 | 17 | return view(PIXI, app, obj, data => { 18 | let { status, drawFn } = data; 19 | switch (status) { 20 | case 'createInterstitialAd': 21 | // 初始化 init 22 | 23 | // 创建插屏广告组件; 24 | interstitialAd = wx.createInterstitialAd({ adUnitId: 'adunit-4a474184cd6eb5cc' }); 25 | 26 | // 监听插屏广告错误事件 27 | interstitialAd.onError(res => { 28 | show.Modal(res.errMsg, codeObj[res.errCode]); 29 | }); 30 | 31 | break; 32 | 33 | case 'show': 34 | // 显示 插屏广告 35 | interstitialAd.show().catch(res => { 36 | show.Modal(res.errMsg, codeObj[res.errCode]); 37 | 38 | // 失败后重新加载广告 39 | interstitialAd.load().catch(res => { 40 | show.Modal(res.errMsg, codeObj[res.errCode]); 41 | }); 42 | }); 43 | 44 | break; 45 | 46 | case 'destroy': 47 | if (!interstitialAd) return; 48 | 49 | if (interstitialAd.destroy) { 50 | // 销毁 插屏广告 51 | interstitialAd.destroy(); 52 | interstitialAd = null; 53 | } else drawFn(); // 更新UI 54 | 55 | break; 56 | } 57 | }); 58 | }; 59 | -------------------------------------------------------------------------------- /miniprogram/js/api/APIentry/index.js: -------------------------------------------------------------------------------- 1 | import pixiScroll from '../../libs/pixiScroll'; 2 | module.exports = function(PIXI, app, parameterObj,methods) { 3 | return pixiScroll(PIXI, app, { 4 | ...parameterObj, 5 | methods 6 | }); 7 | }; 8 | 9 | -------------------------------------------------------------------------------- /miniprogram/js/api/AR/face-detect/index.js: -------------------------------------------------------------------------------- 1 | import view from '../common/view' 2 | 3 | module.exports = function (PIXI, app, obj, callBack) { 4 | let container = view(PIXI, app, obj, '实时人脸检测', '切换为前置摄像头', '提示:将摄像头对准人脸, \n检测到的人脸将会被标记出识别框和面部标记点', { 5 | track: { 6 | plane: { 7 | mode: 3 8 | }, 9 | face: { 10 | mode: 1 11 | } 12 | }, 13 | cameraPosition: 0, 14 | version: 'v1', 15 | }, 'faceDetect') 16 | return container; 17 | }; -------------------------------------------------------------------------------- /miniprogram/js/api/AR/loaders/gltf-clone.js: -------------------------------------------------------------------------------- 1 | export default function(gltf, THREE) { 2 | const clone = { 3 | animations: gltf.animations, 4 | scene: gltf.scene.clone(true) 5 | } 6 | 7 | const skinnedMeshes = {} 8 | 9 | gltf.scene.traverse(node => { 10 | if (node.isSkinnedMesh) { 11 | skinnedMeshes[node.name] = node 12 | } 13 | }) 14 | 15 | const cloneBones = {} 16 | const cloneSkinnedMeshes = {} 17 | 18 | clone.scene.traverse(node => { 19 | if (node.isBone) { 20 | cloneBones[node.name] = node 21 | } 22 | 23 | if (node.isSkinnedMesh) { 24 | cloneSkinnedMeshes[node.name] = node 25 | } 26 | }) 27 | 28 | for (let name in skinnedMeshes) { 29 | const skinnedMesh = skinnedMeshes[name] 30 | const skeleton = skinnedMesh.skeleton 31 | const cloneSkinnedMesh = cloneSkinnedMeshes[name] 32 | 33 | const orderedCloneBones = [] 34 | 35 | for (let i = 0; i < skeleton.bones.length; ++i) { 36 | const cloneBone = cloneBones[skeleton.bones[i].name] 37 | orderedCloneBones.push(cloneBone) 38 | } 39 | 40 | cloneSkinnedMesh.bind(new THREE.Skeleton(orderedCloneBones, skeleton.boneInverses), cloneSkinnedMesh.matrixWorld) 41 | } 42 | 43 | return clone 44 | } 45 | -------------------------------------------------------------------------------- /miniprogram/js/api/AR/plane-ar/index.js: -------------------------------------------------------------------------------- 1 | import view from '../common/view' 2 | 3 | module.exports = function (PIXI, app, obj, callBack) { 4 | let container = view(PIXI, app, obj, '水平面AR', null, '提示:触碰屏幕任意点, \n可在对应位置生成示例的机器小人, 其中光标标记指示的是水平面', { 5 | track: { 6 | plane: { 7 | mode: 3 8 | }, 9 | }, 10 | version: 'v1', 11 | }, 'planeAR') 12 | return container; 13 | }; -------------------------------------------------------------------------------- /miniprogram/js/api/AR/visionkit-basic-v2/index.js: -------------------------------------------------------------------------------- 1 | import view from '../common/view' 2 | 3 | module.exports = function (PIXI, app, obj, callBack) { 4 | let container = view(PIXI, app, obj, 'VisionKit基础-v2', null, '提示:触碰屏幕任意点, \n可在对应位置生成示例的机器小人', { 5 | track: { 6 | plane: { 7 | mode: 3 8 | }, 9 | }, 10 | version: 'v2', 11 | }) 12 | return container; 13 | }; -------------------------------------------------------------------------------- /miniprogram/js/api/AR/visionkit-basic/index.js: -------------------------------------------------------------------------------- 1 | 2 | import view from '../common/view' 3 | 4 | module.exports = function (PIXI, app, obj, callBack) { 5 | let container = view(PIXI, app, obj, 'VisionKit基础', null, '提示:触碰屏幕任意点, \n可在对应位置生成示例的机器小人', 6 | { 7 | track: { 8 | plane: { 9 | mode: 3 10 | }, 11 | }, 12 | version: 'v1', 13 | }) 14 | return container; 15 | }; -------------------------------------------------------------------------------- /miniprogram/js/api/abilityOpen/UnionID/index.js: -------------------------------------------------------------------------------- 1 | import view from './view'; 2 | import show from '../../../libs/show'; 3 | module.exports = function(PIXI, app, obj) { 4 | return view(PIXI, app, obj, data => { 5 | let { status, drawFn } = data; 6 | switch (status) { 7 | case 'UnionID': 8 | wx.showLoading({ title: '响应中...', mask: true }); 9 | // 这里我们调用云函数来获取UnionID 10 | wx.cloud.callFunction({ 11 | // 需调用的云函数名 12 | name: 'getUnionID', 13 | success(res) { 14 | wx.hideLoading(); 15 | drawFn(res.result.unionid || res.result.openid) //更新 UI 16 | console.log(res.result); 17 | }, 18 | fail(res) { 19 | wx.hideLoading(); 20 | 21 | show.Modal(`${res.errCode}`, '失败'); 22 | 23 | console.log(`调起失败: ${res.errCode}`); 24 | } 25 | }); 26 | break; 27 | } 28 | }); 29 | }; 30 | -------------------------------------------------------------------------------- /miniprogram/js/api/abilityOpen/appletCode/index.js: -------------------------------------------------------------------------------- 1 | import view from './view'; 2 | import show from '../../../libs/show'; 3 | module.exports = function(PIXI, app, obj) { 4 | return view(PIXI, app, obj, drawFn => { 5 | wx.showLoading({ title: '生成中...', mask: true }); 6 | wx.cloud.callFunction({ 7 | // 需调用的云函数名 8 | name: 'getAppletCode', 9 | // 成功回调 10 | success(res) { 11 | wx.hideLoading(); 12 | 13 | show.Toast('生成成功', 'success', 1000); 14 | 15 | console.log(res); 16 | 17 | drawFn(res.result.base64); //绘制二维码 18 | }, 19 | fail(res) { 20 | wx.hideLoading(); 21 | 22 | show.Toast('生成失败', 'success', 1000); 23 | 24 | console.log(res.errCode); 25 | } 26 | }); 27 | }); 28 | }; 29 | -------------------------------------------------------------------------------- /miniprogram/js/api/abilityOpen/appletCode/view.js: -------------------------------------------------------------------------------- 1 | import { p_button, p_text } from '../../../libs/component/index'; 2 | import fixedTemplate from '../../../libs/template/fixed'; 3 | module.exports = function(PIXI, app, obj, callBack) { 4 | let container = new PIXI.Container(), 5 | { goBack, title, api_name, underline, logo, logoName } = fixedTemplate(PIXI, { 6 | obj, 7 | title: '生成二维码', 8 | api_name: 'cloudFunction:getAppletCode' 9 | }), 10 | appletCode = null, 11 | button = p_button(PIXI, { 12 | width: 580 * PIXI.ratio, 13 | y: underline.height + underline.y + 123 * PIXI.ratio 14 | }); 15 | 16 | // 点击生成“按钮”开始 17 | button.myAddChildFn( 18 | p_text(PIXI, { 19 | content: `点击生成`, 20 | fontSize: 36 * PIXI.ratio, 21 | fill: 0xffffff, 22 | relative_middle: { containerWidth: button.width, containerHeight: button.height } 23 | }) 24 | ); 25 | button.onClickFn(() => { 26 | callBack(base64 => { 27 | appletCode = new PIXI.Sprite(PIXI.Texture.from(base64)); 28 | appletCode.width = appletCode.height = 430 * PIXI.ratio; 29 | appletCode.position.set((obj.width - appletCode.width) / 2, underline.y + underline.height + 100 * PIXI.ratio); 30 | container.addChild(appletCode); 31 | button.hideFn(); 32 | }); 33 | }); 34 | // 点击生成“按钮”结束 35 | 36 | container.addChild(goBack, title, api_name, underline, button, logo, logoName); 37 | 38 | app.stage.addChild(container); 39 | 40 | return container; 41 | }; 42 | -------------------------------------------------------------------------------- /miniprogram/js/api/abilityOpen/createGameClubButton/index.js: -------------------------------------------------------------------------------- 1 | import view from './view'; 2 | module.exports = function(PIXI, app, obj) { 3 | let button; 4 | return view(PIXI, app, obj, data => { 5 | let { status, style } = data; 6 | switch (status) { 7 | case 'createGameClubButton': 8 | // 创建游戏圈按钮,游戏圈按钮被点击后会跳转到小游戏的游戏圈 9 | button = wx.createGameClubButton({ 10 | icon: 'green', 11 | style: { 12 | left: style.x, 13 | top: style.y, 14 | width: 40, 15 | height: 40 16 | } 17 | }); 18 | 19 | break; 20 | case 'destroy': 21 | // 销毁游戏圈按钮 22 | button.destroy(); 23 | 24 | break; 25 | } 26 | }); 27 | }; 28 | -------------------------------------------------------------------------------- /miniprogram/js/api/abilityOpen/createGameClubButton/view.js: -------------------------------------------------------------------------------- 1 | import { p_text, p_img } from '../../../libs/component/index'; 2 | import fixedTemplate from '../../../libs/template/fixed'; 3 | module.exports = function(PIXI, app, obj, callBack) { 4 | let container = new PIXI.Container(), 5 | { goBack, title, api_name, underline, logo, logoName } = fixedTemplate(PIXI, { 6 | obj, 7 | title: '游戏圈', 8 | api_name: 'createGameClubButton' 9 | }), 10 | prompt = p_text(PIXI, { 11 | content: '点击图标打开游戏圈界面', 12 | fontSize: 28 * PIXI.ratio, 13 | y: 350 * PIXI.ratio, 14 | relative_middle: { containerWidth: obj.width } 15 | }); 16 | 17 | callBack({ status: 'createGameClubButton', style: { x: ((375 - 40) * obj.width) / (375 * 2 * obj.pixelRatio), y: (450 * PIXI.ratio) / obj.pixelRatio } }); 18 | 19 | goBack.callBack = callBack.bind(null, { status: 'destroy' }); 20 | 21 | container.addChild(goBack, title, api_name, underline, prompt, logo, logoName); 22 | app.stage.addChild(container); 23 | 24 | return container; 25 | }; 26 | -------------------------------------------------------------------------------- /miniprogram/js/api/abilityOpen/customerService/index.js: -------------------------------------------------------------------------------- 1 | import view from './view'; 2 | module.exports = function(PIXI, app, obj) { 3 | return view(PIXI, app, obj, data => { 4 | let { status } = data; 5 | switch (status) { 6 | case 'openCustomerServiceConversation': 7 | // 调起客服聊天窗口 8 | wx.openCustomerServiceConversation({ 9 | success() { 10 | console.log('调起成功'); 11 | }, 12 | fail() { 13 | console.log('调起失败'); 14 | } 15 | }); 16 | 17 | break; 18 | } 19 | }); 20 | }; 21 | -------------------------------------------------------------------------------- /miniprogram/js/api/abilityOpen/customerService/view.js: -------------------------------------------------------------------------------- 1 | import { p_text, p_img } from '../../../libs/component/index'; 2 | import fixedTemplate from '../../../libs/template/fixed'; 3 | module.exports = function(PIXI, app, obj, callBack) { 4 | let container = new PIXI.Container(), 5 | { goBack, title, api_name, underline, logo, logoName } = fixedTemplate(PIXI, { 6 | obj, 7 | title: '客服服务', 8 | api_name: 'customerService' 9 | }), 10 | prompt = p_text(PIXI, { 11 | content: '点击气泡icon打开客服消息界面', 12 | fontSize: 28 * PIXI.ratio, 13 | y: 350 * PIXI.ratio, 14 | relative_middle: { containerWidth: obj.width } 15 | }), 16 | icon = p_img(PIXI, { 17 | width: 75 * PIXI.ratio, 18 | height: 61 * PIXI.ratio, 19 | y: 500 * PIXI.ratio, 20 | src: 'images/contact.png', 21 | relative_middle: { containerWidth: obj.width } 22 | }); 23 | 24 | icon.onClickFn(() => { 25 | callBack({ 26 | status: 'openCustomerServiceConversation' 27 | }); 28 | }); 29 | 30 | container.addChild(goBack, title, api_name, underline, prompt, icon, logo, logoName); 31 | app.stage.addChild(container); 32 | 33 | return container; 34 | }; 35 | -------------------------------------------------------------------------------- /miniprogram/js/api/abilityOpen/directedSharing/index.js: -------------------------------------------------------------------------------- 1 | import view from "./view"; 2 | import { ShareCanvas } from "../openDataContext/ShareCanvas"; 3 | 4 | module.exports = function (PIXI, app, obj) { 5 | let { container, Yaxis, callBack } = view(PIXI, app, obj, (data) => { 6 | let { status } = data; 7 | switch (status) { 8 | case "directedSharing": 9 | // 初始化 10 | if (!SC.friendRankShow) { 11 | SC.friendRankShow = true; 12 | ticker.add(tick); 13 | 14 | SC.openDataContext.postMessage({ 15 | event: "directedSharing", 16 | }); 17 | } 18 | break; 19 | case "close": 20 | SC.friendRankShow = false; 21 | 22 | ticker.remove(tick); 23 | 24 | SC.rankTiker(PIXI, app); 25 | 26 | SC.openDataContext.postMessage({ 27 | event: "close", 28 | }); 29 | 30 | wx.triggerGC(); // 垃圾回收 31 | break; 32 | } 33 | }); 34 | 35 | const SC = new ShareCanvas(1344, 1974, 0.896, Yaxis); 36 | 37 | let tick = () => { 38 | SC.rankTiker(PIXI, app); 39 | }; 40 | let ticker = PIXI.ticker.shared; 41 | 42 | callBack({ status: "directedSharing" }); 43 | 44 | return container; 45 | }; 46 | -------------------------------------------------------------------------------- /miniprogram/js/api/abilityOpen/directedSharing/view.js: -------------------------------------------------------------------------------- 1 | import { p_text } from "../../../libs/component/index"; 2 | import fixedTemplate from "../../../libs/template/fixed"; 3 | module.exports = function (PIXI, app, obj, callBack) { 4 | let container = new PIXI.Container(), 5 | { goBack, title, api_name, logo, logoName } = fixedTemplate(PIXI, { 6 | obj, 7 | title: "定向分享", 8 | api_name: "directed sharing", 9 | underline: false, 10 | }), 11 | tipText = p_text(PIXI, { 12 | content: "提示:拉取同玩好友/可能感兴趣的好友列表\n无需跳出,在小游戏内完成分享流程", 13 | fontSize: 32 * PIXI.ratio, 14 | fill: 0xbebebe, 15 | align: "center", 16 | lineHeight: 45 * PIXI.ratio, 17 | y: api_name.height + api_name.y + 830 * PIXI.ratio, 18 | relative_middle: { containerWidth: obj.width }, 19 | }); 20 | 21 | goBack.callBack = () => { 22 | callBack({ status: "close" }); 23 | }; 24 | 25 | container.addChild(goBack, title, api_name, tipText, logo, logoName); 26 | 27 | app.stage.addChild(container); 28 | 29 | return { 30 | container, 31 | Yaxis: api_name.y + api_name.height + 10 * PIXI.ratio, 32 | callBack 33 | }; 34 | }; 35 | -------------------------------------------------------------------------------- /miniprogram/js/api/abilityOpen/getGameRecorder/bgm.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-demo/de1c8edf16cf8bf3d9432f83e1f0d397598e70a3/miniprogram/js/api/abilityOpen/getGameRecorder/bgm.mp3 -------------------------------------------------------------------------------- /miniprogram/js/api/abilityOpen/getUserInfo/index.js: -------------------------------------------------------------------------------- 1 | import view from './view'; 2 | import show from '../../../libs/show'; 3 | module.exports = function(PIXI, app, obj) { 4 | let userInfoButton = null; 5 | return view(PIXI, app, obj, data => { 6 | switch (data.status) { 7 | case 'createUserInfoButton': 8 | //调用wx.createUserInfoButton(),返回一个“用户信息按钮”对象 9 | userInfoButton = wx.createUserInfoButton({ 10 | type: 'text', 11 | text: '获取用户信息', 12 | style: { 13 | left: data.left, 14 | top: data.top, 15 | width: data.width, 16 | height: 40, 17 | lineHeight: 40, 18 | backgroundColor: '#1aad19', 19 | color: '#ffffff', 20 | textAlign: 'center', 21 | fontSize: 16, 22 | borderRadius: 4 23 | } 24 | }); 25 | userInfoButton.onTap(res => { 26 | if (res.errMsg === 'getUserInfo:fail auth deny') 27 | return show.Modal('用户不授权是无法获取到用户信息的', '授权失败'); 28 | 29 | wx.getUserInfo({ 30 | success(res) { 31 | show.Toast('获取成功', 'success', 1000); 32 | data.drawFn(res.userInfo); //绘制UI 33 | console.log(res); 34 | } 35 | }); 36 | }); 37 | 38 | break; 39 | case 'destroyUserInfoButton': 40 | //销毁对象 41 | userInfoButton && userInfoButton.destroy(); 42 | break; 43 | } 44 | }); 45 | }; 46 | -------------------------------------------------------------------------------- /miniprogram/js/api/abilityOpen/login/index.js: -------------------------------------------------------------------------------- 1 | import view from './view'; 2 | module.exports = function(PIXI, app, obj) { 3 | return view(PIXI, app, obj, data => { 4 | let { status, drawFn } = data; 5 | switch (status) { 6 | case 'login': 7 | // 微信登录 8 | wx.login({ 9 | success(res) { 10 | if (res.code) { 11 | // 发起网络请求 12 | drawFn(); 13 | } else { 14 | console.log('登录失败!' + res.errMsg); 15 | } 16 | } 17 | }); 18 | break; 19 | } 20 | }); 21 | }; 22 | -------------------------------------------------------------------------------- /miniprogram/js/api/abilityOpen/matchedPattern/index.js: -------------------------------------------------------------------------------- 1 | import view from './view'; 2 | module.exports = function (PIXI, app, obj) { 3 | const gameServer = wx.getGameServerManager(), 4 | matchId = { 5 | '1v1': 'npvL4nYFZCEJuKT6jQwiWGO2FKMB6gIYN9svnB6C8PI', 6 | '3v3': 'rgisvVgmGZz0p3C61zIUexIgDibx0DNzbNTn4QcHZEc', 7 | }; 8 | let recordFunc, isOncelogin; 9 | 10 | return view(PIXI, app, obj, (data) => { 11 | let { status, pattern, drawFn } = data; 12 | switch (status) { 13 | case 'startMatch': 14 | gameServer.startMatch({ match_id: matchId[pattern] }); // 开始匹配 15 | 16 | wx.showLoading({ title: '匹配中...' }); 17 | 18 | drawFn(); // 更新UI 19 | 20 | gameServer.onMatch( 21 | (recordFunc = function (res) { 22 | // 匹配成功 23 | wx.hideLoading(); 24 | 25 | drawFn(res.groupInfoList); // 更新UI 26 | 27 | gameServer.offMatch(recordFunc); 28 | 29 | recordFunc = null; 30 | }) 31 | ); 32 | 33 | break; 34 | 35 | case 'cancelMatch': 36 | // 取消匹配 37 | if (recordFunc) wx.hideLoading(), gameServer.offMatch(recordFunc), (recordFunc = null); 38 | gameServer.cancelMatch({ match_id: matchId[pattern] }); 39 | drawFn(); // 更新UI 40 | break; 41 | 42 | case 'login': 43 | // 登录游戏服务 44 | if (!isOncelogin) { 45 | gameServer.login(); 46 | gameServer.onLogout(gameServer.login); 47 | isOncelogin = true; 48 | } 49 | break; 50 | 51 | case 'logout': 52 | // 登出游戏服务 53 | if (!recordFunc) { 54 | gameServer.offLogout(gameServer.login); 55 | gameServer.logout(); 56 | isOncelogin = false; 57 | } 58 | break; 59 | } 60 | }); 61 | }; 62 | -------------------------------------------------------------------------------- /miniprogram/js/api/abilityOpen/onShareAppMessage/index.js: -------------------------------------------------------------------------------- 1 | import view from './view'; 2 | module.exports = function(PIXI, app, obj) { 3 | let transpondFn; 4 | return view(PIXI, app, obj, data => { 5 | let { status } = data; 6 | switch (status) { 7 | case 'onShareAppMessage': 8 | // 显示当前页面的转发按钮 9 | wx.showShareMenu({ 10 | withShareTicket: true 11 | }); 12 | 13 | // 监听被动调起分享 14 | wx.onShareAppMessage( 15 | transpondFn || 16 | (transpondFn = function() { 17 | return { 18 | title: '自定义转发标题', 19 | desc: '自定义转发描述', 20 | imageUrl: canvas.toTempFilePathSync({ 21 | x: 0, 22 | y: 0, 23 | width: canvas.width, 24 | height: (canvas.width * 4) / 5 25 | }), 26 | query: `pathName=${window.router.getNowPageName()}` 27 | }; 28 | }) 29 | ); 30 | break; 31 | case 'offShareAppMessage': 32 | // 隐藏转发按钮 33 | wx.hideShareMenu(); 34 | 35 | // 取消监听被动调起分享 36 | wx.offShareAppMessage(transpondFn); 37 | transpondFn = null; 38 | break; 39 | } 40 | }); 41 | }; 42 | -------------------------------------------------------------------------------- /miniprogram/js/api/abilityOpen/relationalChaininteractiveData/index.js: -------------------------------------------------------------------------------- 1 | import view from './view'; 2 | import { ShareCanvas } from '../openDataContext/ShareCanvas'; 3 | 4 | module.exports = function(PIXI, app, obj) { 5 | const SC = new ShareCanvas(1344, 1974, 0.896, 315 * PIXI.ratio); 6 | 7 | let tick = () => { 8 | SC.rankTiker(PIXI, app); 9 | }; 10 | let ticker = PIXI.ticker.shared; 11 | 12 | return view(PIXI, app, obj, data => { 13 | let { status } = data; 14 | switch (status) { 15 | case 'relationalChaininteractiveData': 16 | // 初始化 17 | if (!SC.friendRankShow) { 18 | SC.friendRankShow = true; 19 | ticker.add(tick); 20 | 21 | SC.openDataContext.postMessage({ 22 | event: 'relationalChaininteractiveData' 23 | }); 24 | } 25 | break; 26 | case 'close': 27 | SC.friendRankShow = false; 28 | 29 | ticker.remove(tick); 30 | 31 | SC.rankTiker(PIXI, app); 32 | 33 | SC.openDataContext.postMessage({ 34 | event: 'close' 35 | }); 36 | 37 | wx.triggerGC(); // 垃圾回收 38 | break; 39 | } 40 | }); 41 | }; 42 | -------------------------------------------------------------------------------- /miniprogram/js/api/abilityOpen/relationalChaininteractiveData/view.js: -------------------------------------------------------------------------------- 1 | import { p_text } from '../../../libs/component/index'; 2 | import fixedTemplate from '../../../libs/template/fixed'; 3 | module.exports = function(PIXI, app, obj, callBack) { 4 | let container = new PIXI.Container(), 5 | { goBack, title, api_name, underline, logo, logoName } = fixedTemplate(PIXI, { 6 | obj, 7 | title: '关系链互动', 8 | api_name: 'relationalChaininteractiveData' 9 | }), 10 | tipText = p_text(PIXI, { 11 | content: '提示:在赠送/索要/邀请场景可搭配好友列表、\n排行榜使用,跟同玩好友间进行互动', 12 | fontSize: 32 * PIXI.ratio, 13 | fill: 0xbebebe, 14 | align: 'center', 15 | lineHeight: 45 * PIXI.ratio, 16 | y: underline.height + underline.y + 720 * PIXI.ratio, 17 | relative_middle: { containerWidth: obj.width } 18 | }); 19 | 20 | goBack.callBack = () => { 21 | callBack({ status: 'close' }); 22 | }; 23 | 24 | // 默认上报分数 25 | wx.setUserCloudStorage({ 26 | KVDataList: [ 27 | { 28 | key: 'score', 29 | value: JSON.stringify({ 30 | wxgame: { 31 | score: 0, 32 | update_time: (Date.now() / 1000) | 0 33 | } 34 | }) 35 | } 36 | ] 37 | }); 38 | 39 | callBack({ status: 'relationalChaininteractiveData' }); 40 | 41 | container.addChild(goBack, title, api_name, underline, tipText, logo, logoName); 42 | 43 | app.stage.addChild(container); 44 | 45 | return container; 46 | }; 47 | -------------------------------------------------------------------------------- /miniprogram/js/api/abilityOpen/requestSubscribeMessage/index.js: -------------------------------------------------------------------------------- 1 | import view from './view'; 2 | import show from '../../../libs/show'; 3 | module.exports = function(PIXI, app, obj) { 4 | return view(PIXI, app, obj, res => { 5 | let { status } = res; 6 | switch (status) { 7 | case 'requestSubscribeMessage': 8 | // 调起小游戏订阅消息界面,返回用户订阅消息的操作结果 9 | wx.requestSubscribeMessage({ 10 | // tmplIds的值是:具有模板ID的数组 11 | tmplIds: ['wAniOv_NUi6TXiQWX74_1LD5E4_6EfqvaeSxUxhqllg'], 12 | success(res) { 13 | // 用户允许订阅 14 | if (res['wAniOv_NUi6TXiQWX74_1LD5E4_6EfqvaeSxUxhqllg'] === 'accept') 15 | // 调用云函数进行推送消息 16 | return wx.cloud.callFunction({ 17 | // 云函数名称 18 | name: 'pushMessage', 19 | // 传给云函数的参数 20 | data: { 21 | page: `pathName=${window.router.getNowPageName()}` 22 | }, 23 | success() { 24 | show.Toast('推送成功', 'success', 1000); 25 | }, 26 | fail: console.error 27 | }); 28 | 29 | // 用户拒绝订阅 30 | if (res['wAniOv_NUi6TXiQWX74_1LD5E4_6EfqvaeSxUxhqllg'] === 'reject') return show.Modal('你已拒绝消息订阅,可前往“右上角三个点-设置”中打开', '订阅失败'); 31 | }, 32 | fail(){ 33 | show.Modal('你已拒绝消息订阅,可前往“右上角三个点-设置”中打开', '订阅失败'); 34 | } 35 | }); 36 | break; 37 | } 38 | }); 39 | }; 40 | -------------------------------------------------------------------------------- /miniprogram/js/api/abilityOpen/requestSubscribeSystemMessage/index.js: -------------------------------------------------------------------------------- 1 | import view from './view'; 2 | import show from '../../../libs/show'; 3 | module.exports = function(PIXI, app, obj) { 4 | let msgType = { 5 | SYS_MSG_TYPE_INTERACTIVE: '好友互动', 6 | SYS_MSG_TYPE_RANK: '好友排行榜超越', 7 | accept: '接受订阅', 8 | reject: '拒绝订阅', 9 | ban: '被封禁' 10 | }; 11 | return view(PIXI, app, obj, data => { 12 | let { status, drawFn } = data; 13 | switch (status) { 14 | case 'requestSubscribeSystemMessage': 15 | // 调起小游戏永久订阅消息界面 16 | wx.requestSubscribeSystemMessage({ 17 | msgTypeList: Object.keys(msgType).slice(0,2), 18 | success(res) { 19 | delete res.errMsg; 20 | let msgObj = {}; 21 | Object.keys(res).forEach(item => { 22 | msgObj[msgType[item]] = msgType[res[item]]; 23 | }); 24 | drawFn(msgObj); // 绘制UI 25 | }, 26 | fail() { 27 | show.Modal('你已拒绝消息订阅,可前往“右上角三个点-设置”中打开', '永久订阅失败'); 28 | } 29 | }); 30 | break; 31 | } 32 | }); 33 | }; 34 | -------------------------------------------------------------------------------- /miniprogram/js/api/abilityOpen/setting/index.js: -------------------------------------------------------------------------------- 1 | import view from './view'; 2 | module.exports = function(PIXI, app, obj) { 3 | return view(PIXI, app, obj, data => { 4 | let { status, drawFn } = data; 5 | switch (status) { 6 | case 'getSetting': 7 | //获取用户的当前设置。返回值中只会出现小程序已经向用户请求过的权限。 8 | wx.getSetting({ 9 | success(res) { 10 | console.log(res.authSetting); 11 | drawFn(res.authSetting); //绘制UI 12 | } 13 | }); 14 | break; 15 | case 'openSetting': 16 | //调起客户端小程序设置界面,返回用户设置的操作结果。设置界面只会出现小程序已经向用户请求过的权限。 17 | wx.openSetting({ 18 | success(res) { 19 | console.log(res.authSetting); 20 | drawFn(res.authSetting); //绘制UI 21 | } 22 | }); 23 | break; 24 | } 25 | }); 26 | }; 27 | -------------------------------------------------------------------------------- /miniprogram/js/api/abilityOpen/shareAppMessage/index.js: -------------------------------------------------------------------------------- 1 | import view from './view'; 2 | module.exports = function(PIXI, app, obj) { 3 | return view(PIXI, app, obj, data => { 4 | let { status } = data; 5 | switch (status) { 6 | case 'shareAppMessage': 7 | //主动拉起转发,进入选择通讯录界面。 8 | wx.shareAppMessage({ 9 | imageUrl: canvas.toTempFilePathSync({ 10 | x: 0, 11 | y: 0, 12 | width: canvas.width, 13 | height: (canvas.width * 4) / 5 14 | }), 15 | query: `pathName=${window.router.getNowPageName()}` 16 | }); 17 | break; 18 | } 19 | }); 20 | }; 21 | -------------------------------------------------------------------------------- /miniprogram/js/api/abilityOpen/shareAppMessage/view.js: -------------------------------------------------------------------------------- 1 | import { p_text, p_img } from '../../../libs/component/index'; 2 | import fixedTemplate from '../../../libs/template/fixed'; 3 | module.exports = function(PIXI, app, obj, callBack) { 4 | let container = new PIXI.Container(), 5 | { goBack, title, api_name, underline, logo, logoName } = fixedTemplate(PIXI, { 6 | obj, 7 | title: '主动转发', 8 | api_name: 'shareAppMessage' 9 | }), 10 | prompt = p_text(PIXI, { 11 | content: '轻触下方图标即可转发', 12 | fontSize: 28 * PIXI.ratio, 13 | y: 365 * PIXI.ratio, 14 | relative_middle: { containerWidth: obj.width } 15 | }), 16 | icon = p_img(PIXI, { 17 | width: 54 * PIXI.ratio, 18 | height: 54 * PIXI.ratio, 19 | y: 500 * PIXI.ratio, 20 | src: 'images/share.png', 21 | relative_middle: { containerWidth: obj.width } 22 | }); 23 | 24 | icon.onClickFn(() => { 25 | callBack({ 26 | status: 'shareAppMessage' 27 | }); 28 | }); 29 | 30 | container.addChild(goBack, title, api_name, underline, prompt, icon, logo, logoName); 31 | 32 | app.stage.addChild(container); 33 | 34 | return container; 35 | }; 36 | -------------------------------------------------------------------------------- /miniprogram/js/api/abilityOpen/shareTimeLine/index.js: -------------------------------------------------------------------------------- 1 | import view from './view'; 2 | module.exports = function (PIXI, app, obj) { 3 | return view(PIXI, app, obj, (data) => { 4 | let { status } = data; 5 | switch (status) { 6 | case 'shareTimeLine': 7 | //主动转发到朋友圈。 8 | wx.shareTimeLine({ 9 | imageUrl: canvas.toTempFilePathSync({ 10 | x: 0, 11 | y: 0, 12 | width: canvas.width, 13 | height: (canvas.width * 4) / 5, 14 | }), 15 | query: `pathName=${window.router.getNowPageName()}`, 16 | }); 17 | break; 18 | } 19 | }); 20 | }; 21 | -------------------------------------------------------------------------------- /miniprogram/js/api/abilityOpen/shareTimeLine/view.js: -------------------------------------------------------------------------------- 1 | import { p_text, p_img } from '../../../libs/component/index'; 2 | import fixedTemplate from '../../../libs/template/fixed'; 3 | module.exports = function(PIXI, app, obj, callBack) { 4 | !wx.shareTimeLine && wx.shareTimeLine(); 5 | 6 | let container = new PIXI.Container(), 7 | { goBack, title, api_name, underline, logo, logoName } = fixedTemplate(PIXI, { 8 | obj, 9 | title: '转发到朋友圈', 10 | api_name: 'shareTimeLine' 11 | }), 12 | prompt = p_text(PIXI, { 13 | content: '轻触下方图标即可转发', 14 | fontSize: 28 * PIXI.ratio, 15 | y: 365 * PIXI.ratio, 16 | relative_middle: { containerWidth: obj.width } 17 | }), 18 | icon = p_img(PIXI, { 19 | width: 110 * PIXI.ratio, 20 | height: 110 * PIXI.ratio, 21 | y: 500 * PIXI.ratio, 22 | src: 'images/circleFriends.png', 23 | relative_middle: { containerWidth: obj.width } 24 | }); 25 | 26 | icon.onClickFn(() => { 27 | callBack({ 28 | status: 'shareTimeLine' 29 | }); 30 | }); 31 | 32 | container.addChild(goBack, title, api_name, underline, prompt, icon, logo, logoName); 33 | 34 | app.stage.addChild(container); 35 | 36 | return container; 37 | }; 38 | -------------------------------------------------------------------------------- /miniprogram/js/api/abilityOpen/startHandoff/index.js: -------------------------------------------------------------------------------- 1 | import view from './view'; 2 | import { ShareCanvas } from '../openDataContext/ShareCanvas'; 3 | 4 | module.exports = function (PIXI, app, obj) { 5 | const SC = new ShareCanvas(void 0, void 0, 1, 300 * PIXI.ratio); 6 | 7 | let tick = () => { 8 | SC.rankTiker(PIXI, app); 9 | }; 10 | let ticker = PIXI.ticker.shared; 11 | 12 | return view(PIXI, app, obj, (data) => { 13 | let { status } = data; 14 | switch (status) { 15 | case 'PCHandoff': 16 | // 初始化 17 | if (!SC.friendRankShow) { 18 | SC.friendRankShow = true; 19 | ticker.add(tick); 20 | 21 | SC.openDataContext.postMessage({ 22 | event: 'PCHandoff', 23 | }); 24 | } 25 | break; 26 | case 'close': 27 | SC.friendRankShow = false; 28 | 29 | ticker.remove(tick); 30 | 31 | SC.rankTiker(PIXI, app); 32 | 33 | SC.openDataContext.postMessage({ 34 | event: 'close', 35 | }); 36 | 37 | wx.triggerGC(); // 垃圾回收 38 | break; 39 | } 40 | }); 41 | }; 42 | -------------------------------------------------------------------------------- /miniprogram/js/api/abilityOpen/startHandoff/view.js: -------------------------------------------------------------------------------- 1 | import { p_text } from '../../../libs/component/index'; 2 | import fixedTemplate from '../../../libs/template/fixed'; 3 | module.exports = function (PIXI, app, obj, callBack) { 4 | let container = new PIXI.Container(), 5 | { goBack, title, api_name, underline, logo, logoName } = fixedTemplate(PIXI, { 6 | obj, 7 | title: 'PC接力', 8 | api_name: 'startHandoff', 9 | }), 10 | tipText = p_text(PIXI, { 11 | content: '提示:相关API只能在开放数据域里调用,右\n上角...同样提供“在电脑上打开”接力按钮。为\n确保能体验完整功能,需先登录windows\n电脑端微信(3.1.0及以上版本)', 12 | fontSize: 32 * PIXI.ratio, 13 | fill: 0xbebebe, 14 | align: 'center', 15 | lineHeight: 45 * PIXI.ratio, 16 | y: underline.height + underline.y + 173 * PIXI.ratio, 17 | relative_middle: { containerWidth: obj.width }, 18 | }); 19 | 20 | goBack.callBack = callBack.bind(null, { status: 'close' }); 21 | 22 | callBack({ status: 'PCHandoff' }); 23 | 24 | container.addChild(goBack, title, api_name, underline, tipText, logo, logoName); 25 | 26 | app.stage.addChild(container); 27 | 28 | return container; 29 | }; 30 | -------------------------------------------------------------------------------- /miniprogram/js/api/chatTool/groupTask/const.js: -------------------------------------------------------------------------------- 1 | // 分享结果 emoji 2 | export const GROUP_TASK_RESULT_EMOJI_URL = 'https://mmgame.qpic.cn/rimage/751e092d57e5e2922c9d3b61940d164522a594924b683037409533612decb526'; 3 | // 分享app图 4 | export const GROUP_TASK_SHARE_APP_MESSAGE_IMAGE_URL = 'https://mmgame.qpic.cn/image/b01e3e86d981c1725325006381a8b0132d77dac1f955fbd6f512e7f41b9d41c5/0'; 5 | // 动态消息模版ID 6 | export const ACTIVITY_TEMPLATE_ID_1 = '2A84254B945674A2F88CE4970782C402795EB607'; // 参与 7 | export const ACTIVITY_TEMPLATE_ID_2 = '4A68CBB88A92B0A9311848DBA1E94A199B166463'; // 完成 8 | -------------------------------------------------------------------------------- /miniprogram/js/api/chatTool/groupTask/const.ts: -------------------------------------------------------------------------------- 1 | 2 | // 分享结果 emoji 3 | export const GROUP_TASK_RESULT_EMOJI_URL = 'https://mmgame.qpic.cn/rimage/751e092d57e5e2922c9d3b61940d164522a594924b683037409533612decb526'; 4 | 5 | // 分享app图 6 | export const GROUP_TASK_SHARE_APP_MESSAGE_IMAGE_URL = 'https://mmgame.qpic.cn/image/b01e3e86d981c1725325006381a8b0132d77dac1f955fbd6f512e7f41b9d41c5/0'; 7 | 8 | // 动态消息模版ID 9 | export const ACTIVITY_TEMPLATE_ID_1 = '2A84254B945674A2F88CE4970782C402795EB607'; // 参与 10 | export const ACTIVITY_TEMPLATE_ID_2 = '4A68CBB88A92B0A9311848DBA1E94A199B166463'; // 完成 11 | -------------------------------------------------------------------------------- /miniprogram/js/api/chatTool/groupTask/index.js: -------------------------------------------------------------------------------- 1 | import view from "./view"; 2 | import { openChatTool, showToast } from "./util"; 3 | /** 4 | * 群任务模块的主入口 5 | * @param {any} PIXI - PIXI.js 实例 6 | * @param {any} app - 应用实例 7 | * @param {any} obj - 传入的参数对象 8 | */ 9 | module.exports = function (PIXI, app, obj) { 10 | // 活动列表数据 11 | let activityList = []; 12 | /** 13 | * 获取活动列表 14 | * @param {Function} drawFn - 视图更新回调函数,接收活动列表作为参数 15 | */ 16 | function fetchActivityList(drawFn) { 17 | wx.cloud.callFunction({ 18 | name: 'quickstartFunctions', 19 | data: { 20 | type: 'fetchActivityList', 21 | } 22 | }).then((resp) => { 23 | console.info('fetchActivityList: ', resp); 24 | if (resp.result) { 25 | activityList = resp.result.dataList; // 更新活动列表数据 26 | drawFn(activityList); // 更新视图 27 | wx.hideLoading(); 28 | } 29 | }).catch(err => { 30 | console.error('fetchActivityList fail: ', err); 31 | showToast("获取活动列表失败"); 32 | }); 33 | } 34 | // 返回视图模块,处理各种事件 35 | return view(PIXI, app, obj, (data) => { 36 | let { status, drawFn } = data; 37 | switch (status) { 38 | case "createTask": // 创建新任务 39 | openChatTool({ 40 | success: () => { 41 | drawFn(); 42 | }, 43 | fail: (err) => { 44 | console.error("openChatTool fail:", err); 45 | }, 46 | }); 47 | break; 48 | case "fetchActivityList": // 获取活动列表 49 | wx.showLoading({ 50 | title: '加载中', 51 | mask: true, 52 | }); 53 | fetchActivityList(drawFn); 54 | break; 55 | } 56 | }); 57 | }; 58 | -------------------------------------------------------------------------------- /miniprogram/js/api/chatTool/groupTask/index.ts: -------------------------------------------------------------------------------- 1 | import view from "./view"; 2 | import { ActivityInfo } from "./types"; 3 | import { openChatTool, showToast } from "./util"; 4 | 5 | /** 6 | * 群任务模块的主入口 7 | * @param {any} PIXI - PIXI.js 实例 8 | * @param {any} app - 应用实例 9 | * @param {any} obj - 传入的参数对象 10 | */ 11 | module.exports = function (PIXI: any, app: any, obj: any) { 12 | // 活动列表数据 13 | let activityList: ActivityInfo[] = []; 14 | 15 | /** 16 | * 获取活动列表 17 | * @param {Function} drawFn - 视图更新回调函数,接收活动列表作为参数 18 | */ 19 | function fetchActivityList(drawFn: (activityList: ActivityInfo[]) => void) { 20 | wx.cloud.callFunction({ 21 | name: 'quickstartFunctions', 22 | data: { 23 | type: 'fetchActivityList', 24 | } 25 | }).then((resp: any) => { 26 | console.info('fetchActivityList: ', resp) 27 | if (resp.result) { 28 | activityList = resp.result.dataList; // 更新活动列表数据 29 | drawFn(activityList); // 更新视图 30 | wx.hideLoading(); 31 | } 32 | }).catch(err => { 33 | console.error('fetchActivityList fail: ', err) 34 | showToast("获取活动列表失败"); 35 | }) 36 | } 37 | 38 | // 返回视图模块,处理各种事件 39 | return view(PIXI, app, obj, (data: any) => { 40 | let { status, drawFn } = data; 41 | 42 | switch (status) { 43 | case "createTask": // 创建新任务 44 | openChatTool({ 45 | success: () => { 46 | drawFn(); 47 | }, 48 | fail: (err: any) => { 49 | console.error("openChatTool fail:", err); 50 | }, 51 | }) 52 | break; 53 | case "fetchActivityList": // 获取活动列表 54 | wx.showLoading({ 55 | title: '加载中', 56 | mask: true, 57 | }); 58 | fetchActivityList(drawFn); 59 | break; 60 | } 61 | }); 62 | }; 63 | -------------------------------------------------------------------------------- /miniprogram/js/api/chatTool/groupTask/types.js: -------------------------------------------------------------------------------- 1 | export {}; 2 | -------------------------------------------------------------------------------- /miniprogram/js/api/facility/accelerometerChange/index.js: -------------------------------------------------------------------------------- 1 | import view from './view'; 2 | module.exports = function(PIXI, app, obj) { 3 | let monitorFunc; 4 | return view(PIXI, app, obj, data => { 5 | let { status, drawFn } = data; 6 | switch (status) { 7 | case 'onAccelerometerChange': 8 | // 开启获取加速度数据 9 | wx.startAccelerometer({ 10 | interval: 'game' 11 | }); 12 | 13 | if (monitorFunc) return; 14 | 15 | // 监听加速度数据变化事件。 16 | wx.onAccelerometerChange( 17 | (monitorFunc = res => { 18 | drawFn(res); //绘制UI 19 | }) 20 | ); 21 | break; 22 | case 'offAccelerometerChange': 23 | // 停止获取罗盘数据 24 | wx.stopAccelerometer(); 25 | 26 | // 取消监听加速度数据变化事件。 27 | if (monitorFunc && wx.offAccelerometerChange) { 28 | wx.offAccelerometerChange(monitorFunc); 29 | monitorFunc = null; 30 | } 31 | break; 32 | } 33 | }); 34 | }; 35 | -------------------------------------------------------------------------------- /miniprogram/js/api/facility/clipboardData/index.js: -------------------------------------------------------------------------------- 1 | import view from './view'; 2 | import show from '../../../libs/show'; 3 | module.exports = function(PIXI, app, obj) { 4 | return view(PIXI, app, obj, data => { 5 | let { status, value, drawFn } = data; 6 | switch (status) { 7 | case 'setClipboardData': 8 | // 设置系统剪贴板的内容,即复制内容 9 | wx.setClipboardData({ 10 | data: value, 11 | success() { 12 | drawFn(); //绘制UI 13 | } 14 | }); 15 | break; 16 | case 'getClipboardData': 17 | // 获取系统剪贴板的内容,即粘贴内容 18 | wx.getClipboardData({ 19 | success(res) { 20 | console.log(res.data); 21 | 22 | drawFn(res.data); //绘制UI 23 | 24 | show.Toast('粘贴成功', 'success', 500); 25 | } 26 | }); 27 | break; 28 | } 29 | }); 30 | }; 31 | -------------------------------------------------------------------------------- /miniprogram/js/api/facility/compassChange/index.js: -------------------------------------------------------------------------------- 1 | import view from './view'; 2 | module.exports = function(PIXI, app, obj) { 3 | let monitorFunc; 4 | return view(PIXI, app, obj, data => { 5 | let { status, drawFn } = data; 6 | switch (status) { 7 | case 'onCompassChange': 8 | // 开启获取罗盘数据 9 | wx.startCompass({ 10 | interval: 'game' 11 | }); 12 | 13 | if (monitorFunc) return; 14 | 15 | // 监听设备方向变化事件。 16 | wx.onCompassChange( 17 | (monitorFunc = res => { 18 | drawFn(res); //绘制UI 19 | }) 20 | ); 21 | break; 22 | case 'offCompassChange': 23 | // 停止获取罗盘数据 24 | wx.stopCompass(); 25 | 26 | // 取消监听设备方向变化事件。 27 | if (monitorFunc && wx.offCompassChange) { 28 | wx.offCompassChange(monitorFunc); 29 | monitorFunc = null; 30 | } 31 | break; 32 | } 33 | }); 34 | }; 35 | -------------------------------------------------------------------------------- /miniprogram/js/api/facility/deviceMotionChange/index.js: -------------------------------------------------------------------------------- 1 | import view from './view'; 2 | module.exports = function(PIXI, app, obj) { 3 | let monitorFunc; 4 | return view(PIXI, app, obj, data => { 5 | let { status, drawFn } = data; 6 | switch (status) { 7 | case 'onDeviceMotionChange': 8 | // 开启获取设备方向的变化 9 | wx.startDeviceMotionListening(); 10 | 11 | if (monitorFunc) return; 12 | 13 | // 监听设备方向变化事件。 14 | wx.onDeviceMotionChange( 15 | (monitorFunc = res => { 16 | drawFn(res); //绘制UI 17 | }) 18 | ); 19 | break; 20 | case 'offDeviceMotionChange': 21 | // 停止获取设备方向的变化 22 | wx.stopDeviceMotionListening(); 23 | 24 | // 取消监听设备方向变化事件。 25 | if (monitorFunc && wx.offDeviceMotionChange) { 26 | wx.offDeviceMotionChange(monitorFunc); 27 | monitorFunc = null; 28 | } 29 | break; 30 | } 31 | }); 32 | }; 33 | -------------------------------------------------------------------------------- /miniprogram/js/api/facility/deviceOrientationChange/index.js: -------------------------------------------------------------------------------- 1 | import view from './view'; 2 | import show from '../../../libs/show'; 3 | module.exports = function(PIXI, app, obj) { 4 | return view(PIXI, app, obj, data => { 5 | let { status, drawFn } = data; 6 | switch (status) { 7 | case 'onDeviceOrientationChange': 8 | // 监听横竖屏切换事件 9 | wx.onDeviceOrientationChange(res => { 10 | console.log(res); 11 | 12 | show.Toast('触发成功', 'success', 800); 13 | 14 | drawFn(); //绘制UI 15 | }); 16 | break; 17 | case 'offDeviceOrientationChange': 18 | // 取消监听横竖屏切换事件 19 | wx.offDeviceOrientationChange(); 20 | break; 21 | } 22 | }); 23 | }; 24 | -------------------------------------------------------------------------------- /miniprogram/js/api/facility/getBatteryInfo/index.js: -------------------------------------------------------------------------------- 1 | import view from './view'; 2 | module.exports = function(PIXI, app, obj) { 3 | return view(PIXI, app, obj, data => { 4 | let { status, drawFn } = data; 5 | switch (status) { 6 | case 'getBatteryInfo': 7 | // 获取设备电量。 8 | wx.getBatteryInfo({ 9 | success(res) { 10 | console.log(res); 11 | drawFn(res); //绘制UI 12 | } 13 | }); 14 | break; 15 | } 16 | }); 17 | }; 18 | -------------------------------------------------------------------------------- /miniprogram/js/api/facility/getLocation/index.js: -------------------------------------------------------------------------------- 1 | import view from './view'; 2 | module.exports = function(PIXI, app, obj) { 3 | return view(PIXI, app, obj, data => { 4 | let { status, drawFn } = data; 5 | switch (status) { 6 | case 'getLocation': 7 | wx.getLocation({ 8 | success: drawFn // 获取成功后直接调用drawFn函数修改UI 9 | }); 10 | break; 11 | } 12 | }); 13 | }; 14 | 15 | // getLocation 需要在game.json 中声明 permission 字段 16 | // "permission": { 17 | // "scope.userLocation": { 18 | // "desc": "你的位置信息将用于小程序位置接口的效果展示" 19 | // } 20 | // } 21 | -------------------------------------------------------------------------------- /miniprogram/js/api/facility/getNetworkType/index.js: -------------------------------------------------------------------------------- 1 | import view from './view'; 2 | import show from '../../../libs/show'; 3 | module.exports = function(PIXI, app, obj) { 4 | return view(PIXI, app, obj, data => { 5 | let { status, drawFn } = data; 6 | switch (status) { 7 | case 'getNetworkType': 8 | wx.getNetworkType({ 9 | success(res) { 10 | drawFn(res);//更新UI 11 | }, 12 | fail() { 13 | show.Toast('获取失败', 'success', 500); 14 | } 15 | }); 16 | break; 17 | } 18 | }); 19 | }; 20 | -------------------------------------------------------------------------------- /miniprogram/js/api/facility/getUpdateManager/index.js: -------------------------------------------------------------------------------- 1 | import view from './view'; 2 | import * as show from '../../../libs/show'; 3 | module.exports = function(PIXI, app, obj) { 4 | let gameIcon; 5 | return view(PIXI, app, obj, data => { 6 | let { status } = data, 7 | updateManager; 8 | switch (status) { 9 | case 'getUpdateManager': 10 | // 获取全局唯一的版本更新管理器,用于管理小程序更新。 11 | updateManager = wx.getUpdateManager(); 12 | 13 | updateManager.onCheckForUpdate(res => { 14 | // 请求完新版本信息的回调 15 | !res.hasUpdate && show.Modal('已是最新版,无需更新!', '提示'); 16 | }); 17 | 18 | updateManager.onUpdateReady(() => { 19 | show.Modal('新版本已经准备好,重启应用!', '更新提示', () => { 20 | // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启 21 | updateManager.applyUpdate(); 22 | }); 23 | }); 24 | 25 | updateManager.onUpdateFailed(() => { 26 | // 新版本下载失败 27 | show.Modal('新版本下载失败(可能是网络原因等)!', '提示'); 28 | }); 29 | } 30 | }); 31 | }; 32 | -------------------------------------------------------------------------------- /miniprogram/js/api/facility/getUpdateManager/view.js: -------------------------------------------------------------------------------- 1 | import { p_button, p_text } from '../../../libs/component/index'; 2 | import fixedTemplate from '../../../libs/template/fixed'; 3 | module.exports = function(PIXI, app, obj, callBack) { 4 | let container = new PIXI.Container(), 5 | { goBack, title, api_name, underline, logo, logoName } = fixedTemplate(PIXI, { 6 | obj, 7 | title: '更新', 8 | api_name: 'getUpdateManager' 9 | }), 10 | updateButton = p_button(PIXI, { 11 | width: 580 * PIXI.ratio, 12 | y: underline.height + underline.y + 123 * PIXI.ratio 13 | }), 14 | tipText = p_text(PIXI, { 15 | content: '提示:此API不需由开发者主动触发,而这里\n为了演示而使用', 16 | fontSize: 32 * PIXI.ratio, 17 | fill: 0xbebebe, 18 | align: 'center', 19 | lineHeight: 45 * PIXI.ratio, 20 | y: updateButton.height + updateButton.y + 120 * PIXI.ratio, 21 | relative_middle: { containerWidth: obj.width } 22 | }); 23 | 24 | // 点击更新 “按钮” 开始 25 | updateButton.myAddChildFn( 26 | p_text(PIXI, { 27 | content: `点击更新`, 28 | fontSize: 36 * PIXI.ratio, 29 | fill: 0xffffff, 30 | relative_middle: { containerWidth: updateButton.width, containerHeight: updateButton.height } 31 | }) 32 | ); 33 | updateButton.onClickFn(() => { 34 | callBack({ 35 | status: 'getUpdateManager', 36 | }); 37 | }); 38 | // 点击更新 “按钮” 结束 39 | 40 | !wx.getUpdateManager && wx.getUpdateManager(); 41 | 42 | goBack.callBack = callBack.bind(null, { status: 'destroy' }); 43 | 44 | container.addChild(goBack, title, api_name, underline, updateButton, tipText, logo, logoName); 45 | 46 | app.stage.addChild(container); 47 | 48 | return container; 49 | }; 50 | -------------------------------------------------------------------------------- /miniprogram/js/api/facility/gyroscopeChange/index.js: -------------------------------------------------------------------------------- 1 | import view from './view'; 2 | module.exports = function(PIXI, app, obj) { 3 | let monitorFunc; 4 | return view(PIXI, app, obj, data => { 5 | let { status, drawFn } = data; 6 | switch (status) { 7 | case 'onGyroscopeChange': 8 | // 开启获取陀螺仪数据 9 | wx.startGyroscope(); 10 | 11 | if (monitorFunc) return; 12 | 13 | // 监听陀螺仪数据变化事件。 14 | wx.onGyroscopeChange( 15 | (monitorFunc = res => { 16 | drawFn(res); //绘制UI 17 | }) 18 | ); 19 | break; 20 | case 'offGyroscopeChange': 21 | // 停止获取陀螺仪数据 22 | wx.stopGyroscope(); 23 | 24 | // 取消监听陀螺仪数据变化事件。 25 | if (monitorFunc && wx.offGyroscopeChange) { 26 | wx.offGyroscopeChange(monitorFunc); 27 | monitorFunc = null; 28 | } 29 | break; 30 | } 31 | }); 32 | }; 33 | -------------------------------------------------------------------------------- /miniprogram/js/api/facility/onNetworkStatusChange/index.js: -------------------------------------------------------------------------------- 1 | import view from './view'; 2 | import show from '../../../libs/show'; 3 | module.exports = function(PIXI, app, obj) { 4 | return view(PIXI, app, obj, data => { 5 | let { status, drawFn } = data; 6 | switch (status) { 7 | case 'onNetworkStatusChange': 8 | wx.onNetworkStatusChange(res => { 9 | console.log(res); 10 | drawFn(res); //更新UI 11 | }); 12 | show.Modal('请去切换网络状态进行测试', '监听成功'); 13 | break; 14 | } 15 | }); 16 | }; 17 | -------------------------------------------------------------------------------- /miniprogram/js/api/facility/onNetworkStatusChange/view.js: -------------------------------------------------------------------------------- 1 | import { p_text, p_box } from '../../../libs/component/index'; 2 | import fixedTemplate from '../../../libs/template/fixed'; 3 | module.exports = function(PIXI, app, obj, callBack) { 4 | let container = new PIXI.Container(), 5 | { goBack, title, api_name, underline, logo, logoName } = fixedTemplate(PIXI, { 6 | obj, 7 | title: '监听手机网络变化', 8 | api_name: 'onNetworkStatusChange' 9 | }), 10 | div = p_box(PIXI, { 11 | height: 400 * PIXI.ratio, 12 | y: underline.y + underline.height + 80 * PIXI.ratio 13 | }), 14 | network_state_text = p_text(PIXI, { 15 | content: '', 16 | fontSize: 60 * PIXI.ratio, 17 | align: 'center', 18 | y: 220 * PIXI.ratio, 19 | relative_middle: { containerWidth: obj.width } 20 | }); 21 | 22 | div.addChild( 23 | p_text(PIXI, { 24 | content: '网络状态', 25 | fontSize: 30 * PIXI.ratio, 26 | y: 50 * PIXI.ratio, 27 | relative_middle: { containerWidth: div.width } 28 | }), 29 | network_state_text 30 | ); 31 | 32 | callBack({ 33 | status: 'onNetworkStatusChange', 34 | drawFn(res) { 35 | network_state_text.turnText( 36 | { 37 | wifi: 'wifi', 38 | '2g': '2g', 39 | '3g': '3g', 40 | '4g': '4g', 41 | unknown: '不常见的未知网络', 42 | none: '无网络' 43 | }[res.networkType] 44 | ); 45 | } 46 | }); 47 | 48 | container.addChild(goBack, title, api_name, underline, div, logo, logoName); 49 | app.stage.addChild(container); 50 | 51 | return container; 52 | }; 53 | -------------------------------------------------------------------------------- /miniprogram/js/api/facility/screenBrightness/index.js: -------------------------------------------------------------------------------- 1 | import view from './view'; 2 | module.exports = function(PIXI, app, obj) { 3 | return view(PIXI, app, obj, data => { 4 | let { status, value, drawFn } = data; 5 | switch (status) { 6 | case 'setScreenBrightness': 7 | //设置屏幕亮度 8 | wx.setScreenBrightness({ value }); 9 | break; 10 | case 'getScreenBrightness': 11 | //获取屏幕亮度 12 | wx.getScreenBrightness({ 13 | success(res) { 14 | console.log(res); 15 | drawFn(res); 16 | } 17 | }); 18 | break; 19 | } 20 | }); 21 | }; 22 | -------------------------------------------------------------------------------- /miniprogram/js/api/facility/setKeepScreenOn/index.js: -------------------------------------------------------------------------------- 1 | import view from './view'; 2 | import show from '../../../libs/show'; 3 | module.exports = function(PIXI, app, obj) { 4 | return view(PIXI, app, obj, data => { 5 | let { status, keepScreenOn, drawFn } = data; 6 | switch (status) { 7 | case 'setKeepScreenOn': 8 | // 设置保持常亮状态。 9 | wx.setKeepScreenOn({ 10 | keepScreenOn, 11 | success(res) { 12 | console.log(res); 13 | 14 | show.Toast(`常亮${keepScreenOn ? '已开启' : '已关闭'}`, 'success', 800); 15 | 16 | drawFn(res); //绘制UI 17 | } 18 | }); 19 | break; 20 | } 21 | }); 22 | }; 23 | -------------------------------------------------------------------------------- /miniprogram/js/api/facility/vibrate/index.js: -------------------------------------------------------------------------------- 1 | import view from './view'; 2 | module.exports = function(PIXI, app, obj) { 3 | return view(PIXI, app, obj, res => { 4 | let { status } = res; 5 | switch (status) { 6 | case 'vibrateLong': 7 | // 使手机发生较长时间的振动(400 ms) 8 | wx.vibrateLong(); 9 | break; 10 | case 'vibrateShort': 11 | // 使手机发生较短时间的振动(15 ms) 12 | wx.vibrateShort(); 13 | break; 14 | } 15 | }); 16 | }; 17 | -------------------------------------------------------------------------------- /miniprogram/js/api/facility/vibrate/view.js: -------------------------------------------------------------------------------- 1 | import { p_text, p_button } from '../../../libs/component/index'; 2 | import fixedTemplate from '../../../libs/template/fixed'; 3 | module.exports = function(PIXI, app, obj, callBack) { 4 | let container = new PIXI.Container(), 5 | { goBack, title, api_name, underline, logo, logoName } = fixedTemplate(PIXI, { 6 | obj, 7 | title: '震动', 8 | api_name: 'vibrate/Long/Short' 9 | }), 10 | longButton = p_button(PIXI, { 11 | width: 334 * PIXI.ratio, 12 | height: 80 * PIXI.ratio, 13 | color: 0x05c25f, 14 | y: underline.height + underline.y + 123 * PIXI.ratio 15 | }), 16 | shortButton = p_button(PIXI, { 17 | width: longButton.width, 18 | height: longButton.height, 19 | color: 0xf2f2f2, 20 | y: longButton.height + longButton.y + 20 * PIXI.ratio 21 | }); 22 | 23 | // 长振动 “按钮” 开始 24 | longButton.myAddChildFn( 25 | p_text(PIXI, { 26 | content: `长振动`, 27 | fontSize: 30 * PIXI.ratio, 28 | fill: 0xffffff, 29 | fontWeight: 'bold', 30 | relative_middle: { containerWidth: longButton.width, containerHeight: longButton.height } 31 | }) 32 | ); 33 | longButton.onClickFn(() => { 34 | callBack({ 35 | status: 'vibrateLong' 36 | }); 37 | }); 38 | // 长振动 “按钮” 结束 39 | 40 | // 短振动 “按钮” 开始 41 | shortButton.myAddChildFn( 42 | p_text(PIXI, { 43 | content: `短振动`, 44 | fontSize: 30 * PIXI.ratio, 45 | fill: 0x05c25f, 46 | fontWeight: 'bold', 47 | relative_middle: { containerWidth: shortButton.width, containerHeight: shortButton.height } 48 | }) 49 | ); 50 | shortButton.onClickFn(() => { 51 | callBack({ 52 | status: 'vibrateShort' 53 | }); 54 | }); 55 | // 短振动 “按钮” 结束 56 | 57 | container.addChild(goBack, title, api_name, underline, longButton, shortButton, logo, logoName); 58 | 59 | app.stage.addChild(container); 60 | 61 | return container; 62 | }; 63 | -------------------------------------------------------------------------------- /miniprogram/js/api/game.js: -------------------------------------------------------------------------------- 1 | module.exports = require("./router"); -------------------------------------------------------------------------------- /miniprogram/js/api/interface/showActionSheet/index.js: -------------------------------------------------------------------------------- 1 | import view from './view'; 2 | module.exports = function (PIXI, app, obj) { 3 | return view(PIXI, app, obj, (data) => { 4 | let { status } = data; 5 | switch (status) { 6 | case 'showActionSheet': 7 | wx.showActionSheet({ 8 | itemList: ['item1', 'item2', 'item3', 'item4'], 9 | success(e) { 10 | console.log(e.tapIndex); 11 | }, 12 | }); 13 | 14 | break; 15 | } 16 | }); 17 | }; 18 | -------------------------------------------------------------------------------- /miniprogram/js/api/interface/showActionSheet/view.js: -------------------------------------------------------------------------------- 1 | import { p_button, p_text } from '../../../libs/component/index'; 2 | import fixedTemplate from '../../../libs/template/fixed'; 3 | module.exports = function(PIXI, app, obj, callBack) { 4 | let container = new PIXI.Container(), 5 | { goBack, title, api_name, underline, logo, logoName } = fixedTemplate(PIXI, { 6 | obj, 7 | title: '显示操作菜单', 8 | api_name: 'showActionSheet' 9 | }); 10 | 11 | //弹出action sheet “按钮” 开始 12 | let button = p_button(PIXI, { 13 | width: 300 * PIXI.ratio, 14 | height: 80 * PIXI.ratio, 15 | color: 0xeeeeee, 16 | y: underline.y + underline.height + 150 * PIXI.ratio 17 | }); 18 | button.addChild( 19 | p_text(PIXI, { 20 | content: '弹出action sheet', 21 | fontSize: 30 * PIXI.ratio, 22 | fill: 0x1aad19, 23 | fontWeight: 'bold', 24 | relative_middle: { containerWidth: button.width, containerHeight: button.height } 25 | }) 26 | ); 27 | button.onClickFn(() => { 28 | callBack({ 29 | status: 'showActionSheet' 30 | }); 31 | }); 32 | //弹出action sheet “按钮” 结束 33 | 34 | container.addChild(goBack, title, api_name, underline, button, logo, logoName); 35 | app.stage.addChild(container); 36 | 37 | return container; 38 | }; 39 | -------------------------------------------------------------------------------- /miniprogram/js/api/interface/showModal/index.js: -------------------------------------------------------------------------------- 1 | import view from './view'; 2 | module.exports = function (PIXI, app, obj) { 3 | return view(PIXI, app, obj, (data) => { 4 | let { status } = data; 5 | switch (status) { 6 | case 'with title': 7 | //有标题的模态弹窗 8 | wx.showModal({ 9 | title: '弹窗标题', 10 | content: '弹窗内容,告知当前状态、信息和解决方法,描述文字尽量控制在三行内', 11 | showCancel: false, 12 | confirmText: '确定', 13 | }); 14 | 15 | break; 16 | 17 | case 'without title': 18 | //无标题的模态弹窗 19 | wx.showModal({ 20 | content: '弹窗内容,告知当前状态、信息和解决方法,描述文字尽量控制在三行内', 21 | confirmText: '确定', 22 | cancelText: '取消', 23 | }); 24 | break; 25 | } 26 | }); 27 | }; 28 | -------------------------------------------------------------------------------- /miniprogram/js/api/interface/showToast/index.js: -------------------------------------------------------------------------------- 1 | import view from './view'; 2 | module.exports = function(PIXI, app, obj) { 3 | return view(PIXI, app, obj, data => { 4 | let { status } = data; 5 | switch (status) { 6 | case 'toast1Tap': 7 | //触发弹出默认toast 8 | wx.showToast({ 9 | title: '默认' 10 | }); 11 | break; 12 | 13 | case 'toast2Tap': 14 | //触发弹出设置duration的toast 15 | wx.showToast({ 16 | title: 'duration 3000', 17 | duration: 3000 18 | }); 19 | break; 20 | 21 | case 'toast3Tap': 22 | //触发弹出显示loading的toast 23 | wx.showToast({ 24 | title: 'loading', 25 | icon: 'loading', 26 | duration: 5000 27 | }); 28 | break; 29 | 30 | case 'hideToast': 31 | //触发隐藏toast 32 | wx.hideToast(); 33 | break; 34 | } 35 | }); 36 | }; 37 | -------------------------------------------------------------------------------- /miniprogram/js/api/media/video/index.js: -------------------------------------------------------------------------------- 1 | import view from './view'; 2 | import { errMsgGlobal } from '../../../errMsg/index'; 3 | import show from '../../../libs/show'; 4 | module.exports = function(PIXI, app, obj) { 5 | let video; 6 | return view(PIXI, app, obj, res => { 7 | let { status, data } = res; 8 | switch (status) { 9 | case 'createVideo': 10 | // 调起视频控件 11 | video = wx.createVideo({ 12 | x: data.x, 13 | y: data.y, 14 | width: data.width, 15 | height: data.height, 16 | // 显示默认的视频控件 17 | controls: true, 18 | enablePlayGesture: true, 19 | // 传入 20 | src: 'https://res.wx.qq.com/wechatgame/product/webpack/userupload/20190812/video.mp4' 21 | }); 22 | video.onError(res => { 23 | for (var i = 0, errMsglist = Object.keys(errMsgGlobal); i < errMsglist.length; i++) { 24 | if (res.errMsg.includes(errMsglist[i])) { 25 | errMsgGlobal[errMsglist[i]]({ 26 | callback(res) { 27 | show.Modal(res, '发生错误'); 28 | } 29 | }); 30 | break; 31 | } 32 | } 33 | }); 34 | video.onEnded(() => { 35 | show.Toast('播放结束', 'success', 1000); 36 | }); 37 | video.onPause(() => { 38 | show.Toast('暂停成功', 'success', 1000); 39 | }); 40 | video.onPlay(() => { 41 | show.Toast('播放成功', 'success', 1000); 42 | }); 43 | video.onWaiting(() => { 44 | show.Toast('视频缓冲中', 'success', 1000); 45 | }); 46 | break; 47 | case 'destroy': //销毁当前视频控件 48 | video.destroy(); 49 | break; 50 | } 51 | }); 52 | }; 53 | -------------------------------------------------------------------------------- /miniprogram/js/api/media/video/view.js: -------------------------------------------------------------------------------- 1 | import fixedTemplate from '../../../libs/template/fixed'; 2 | module.exports = function(PIXI, app, obj, callBack) { 3 | let container = new PIXI.Container(), 4 | { goBack, title, api_name, underline, logo, logoName } = fixedTemplate(PIXI, { 5 | obj, 6 | title: '视频', 7 | api_name: 'video' 8 | }); 9 | 10 | // 创建视频 开始 11 | callBack({ 12 | status: 'createVideo', 13 | data: { 14 | x: (75 * obj.width) / (375 * 2 * obj.pixelRatio), 15 | y: (underline.y + underline.height + 83 * PIXI.ratio) / obj.pixelRatio, 16 | width: (300 * obj.width) / (375 * obj.pixelRatio), 17 | height: (225 * obj.width) / (375 * obj.pixelRatio) 18 | } 19 | }); 20 | // 创建视频 结束 21 | 22 | goBack.callBack = callBack.bind(null, { status: 'destroy' }); 23 | container.addChild(goBack, title, api_name, underline, logo, logoName); 24 | 25 | app.stage.addChild(container); 26 | 27 | return container; 28 | }; 29 | -------------------------------------------------------------------------------- /miniprogram/js/api/network/downloadFile/index.js: -------------------------------------------------------------------------------- 1 | import view from './view'; 2 | import { downloadFile } from '../apiList'; 3 | module.exports = function(PIXI, app, obj) { 4 | return view(PIXI, app, obj, func => { 5 | downloadFile(res => { 6 | let tempFilePath = res.tempFilePath; 7 | func(tempFilePath); //绘制图片 8 | }); 9 | }); 10 | }; 11 | -------------------------------------------------------------------------------- /miniprogram/js/api/network/downloadFile/view.js: -------------------------------------------------------------------------------- 1 | import { p_button, p_text, p_img } from '../../../libs/component/index'; 2 | import fixedTemplate from '../../../libs/template/fixed'; 3 | module.exports = function(PIXI, app, obj, callBack) { 4 | let container = new PIXI.Container(), 5 | { goBack, title, api_name, underline, logo, logoName } = fixedTemplate(PIXI, { 6 | obj, 7 | title: '下载文件', 8 | api_name: 'downloadFile' 9 | }), 10 | explain = p_text(PIXI, { 11 | content: '点击按钮下载服务端实例图片', 12 | fontSize: 30 * PIXI.ratio, 13 | fill: 0x999999, 14 | y: underline.y + underline.height + 300 * PIXI.ratio, 15 | relative_middle: { containerWidth: obj.width } 16 | }), 17 | button = p_button(PIXI, { 18 | y: explain.y + explain.height + 300 * PIXI.ratio 19 | }), 20 | sprite = null; 21 | 22 | button.myAddChildFn( 23 | p_text(PIXI, { 24 | content: '下载', 25 | fontSize: 30 * PIXI.ratio, 26 | fill: 0xffffff, 27 | relative_middle: { containerWidth: button.width, containerHeight: button.height } 28 | }) 29 | ); 30 | 31 | button.onClickFn(() => { 32 | callBack(tempFilePath => { 33 | PIXI.loader.add(tempFilePath).load(() => { 34 | sprite = p_img(PIXI, { 35 | src: tempFilePath, 36 | is_PIXI_loader: true, 37 | x: 30 * PIXI.ratio, 38 | y: underline.y + underline.height + 200 * PIXI.ratio 39 | }); 40 | sprite.height = ((obj.width - 60 * PIXI.ratio) * sprite.height) / sprite.width; 41 | sprite.width = obj.width - 60 * PIXI.ratio; 42 | explain.hideFn(); 43 | button.hideFn(); 44 | container.addChild(sprite); 45 | }); 46 | }); 47 | }); 48 | 49 | container.addChild(goBack, title, api_name, underline, explain, button, logo, logoName); 50 | app.stage.addChild(container); 51 | 52 | return container; 53 | }; 54 | -------------------------------------------------------------------------------- /miniprogram/js/api/network/request/index.js: -------------------------------------------------------------------------------- 1 | import view from './view'; 2 | import { request } from '../apiList'; 3 | module.exports = function(PIXI, app, obj) { 4 | return view(PIXI, app, obj, func => { 5 | let time = Date.now(); 6 | request(res => { 7 | wx.reportPerformance && wx.reportPerformance(1001, Date.now() - time); // 上报请求总时间的耗时 8 | 9 | func(res, time); //绘制信息 10 | }); 11 | }); 12 | }; 13 | -------------------------------------------------------------------------------- /miniprogram/js/api/network/request/view.js: -------------------------------------------------------------------------------- 1 | import { p_button, p_text } from '../../../libs/component/index'; 2 | import fixedTemplate from '../../../libs/template/fixed'; 3 | module.exports = function(PIXI, app, obj, callBack) { 4 | let container = new PIXI.Container(), 5 | { goBack, title, api_name, underline, logo, logoName } = fixedTemplate(PIXI, { 6 | obj, 7 | title: '发送请求', 8 | api_name: 'request' 9 | }), 10 | explain = p_text(PIXI, { 11 | content: '点击向服务器发起请求', 12 | fontSize: 30 * PIXI.ratio, 13 | fill: 0x999999, 14 | y: underline.y + underline.height + 300 * PIXI.ratio, 15 | relative_middle: { containerWidth: obj.width } 16 | }), 17 | button = p_button(PIXI, { 18 | y: explain.y + explain.height + 300 * PIXI.ratio 19 | }); 20 | 21 | button.myAddChildFn( 22 | p_text(PIXI, { 23 | content: 'request', 24 | fontSize: 30 * PIXI.ratio, 25 | fill: 0xffffff, 26 | relative_middle: { containerWidth: button.width, containerHeight: button.height } 27 | }) 28 | ); 29 | 30 | button.onClickFn(() => { 31 | callBack((res, time) => { 32 | explain.turnText(`数据包大小(字符长度):${res.data.length || 0}\n请求耗时:${Date.now() - time}ms`); 33 | }); 34 | }); 35 | 36 | container.addChild(goBack, title, api_name, underline, explain, button, logo, logoName); 37 | app.stage.addChild(container); 38 | 39 | return container; 40 | }; 41 | -------------------------------------------------------------------------------- /miniprogram/js/api/network/uploadFile/index.js: -------------------------------------------------------------------------------- 1 | import view from './view'; 2 | import { uploadFile } from '../apiList'; 3 | module.exports = function (PIXI, app, obj) { 4 | return view(PIXI, app, obj, (imageSrc, bool) => { 5 | uploadFile(imageSrc, bool); 6 | }); 7 | }; 8 | -------------------------------------------------------------------------------- /miniprogram/js/api/network/webSocket/index.js: -------------------------------------------------------------------------------- 1 | import view from './view'; 2 | import show from '../../../libs/show'; 3 | module.exports = function(PIXI, app, obj) { 4 | return view(PIXI, app, obj, (status, func) => { 5 | switch (status) { 6 | case 'connection': 7 | wx.showLoading({ title: '连接中...', mask: true }); 8 | 9 | wx.onSocketOpen(() => { 10 | wx.hideLoading(); 11 | console.log('WebSocket 已连接'); 12 | show.Toast('Socket已连接', 'success', 1000); 13 | func(); // 更新 UI 14 | }); 15 | 16 | wx.onSocketClose(() => { 17 | console.log('WebSocket 已断开'); 18 | }); 19 | 20 | wx.onSocketError(error => { 21 | wx.hideLoading(); 22 | show.Modal(JSON.stringify(error), '发生错误'); 23 | console.error('socket error:', error); 24 | }); 25 | 26 | // 监听服务器推送消息 27 | wx.onSocketMessage(message => { 28 | show.Toast('收到服务器响应', 'success', 1000); 29 | console.log('socket message:', message); 30 | }); 31 | 32 | // 打开信道 33 | wx.connectSocket({ 34 | url: 'wss://echo.websocket.org' 35 | }); 36 | break; 37 | case 'disconnect': 38 | wx.closeSocket({ 39 | success() { 40 | show.Toast('Socket已断开', 'success', 1000); 41 | func && func(); // 更新 UI 42 | } 43 | }); 44 | break; 45 | case 'sendMessage': 46 | wx.sendSocketMessage({ 47 | data: 'Hello, MiniGame!' 48 | }); 49 | break; 50 | } 51 | }); 52 | }; 53 | -------------------------------------------------------------------------------- /miniprogram/js/api/recommend/createGamePortal/view.js: -------------------------------------------------------------------------------- 1 | import { p_button, p_text } from '../../../libs/component/index'; 2 | import fixedTemplate from '../../../libs/template/fixed'; 3 | module.exports = function(PIXI, app, obj, callBack) { 4 | let container = new PIXI.Container(), 5 | { goBack, title, api_name, underline, logo, logoName } = fixedTemplate(PIXI, { 6 | obj, 7 | title: '小游戏推荐弹窗', 8 | api_name: 'createGamePortal' 9 | }), 10 | showButton = p_button(PIXI, { 11 | width: 580 * PIXI.ratio, 12 | y: underline.height + underline.y + 123 * PIXI.ratio 13 | }), 14 | tipText = p_text(PIXI, { 15 | content: '提示:当前小游戏推荐弹窗组件已经初始化', 16 | fontSize: 32 * PIXI.ratio, 17 | fill: 0xbebebe, 18 | align: 'center', 19 | lineHeight: 45 * PIXI.ratio, 20 | y: showButton.height + showButton.y + 40 * PIXI.ratio, 21 | relative_middle: { containerWidth: obj.width } 22 | }); 23 | 24 | // 点击展示 “按钮” 开始 25 | showButton.myAddChildFn( 26 | p_text(PIXI, { 27 | content: `点击展示`, 28 | fontSize: 36 * PIXI.ratio, 29 | fill: 0xffffff, 30 | relative_middle: { containerWidth: showButton.width, containerHeight: showButton.height } 31 | }) 32 | ); 33 | showButton.onClickFn(() => { 34 | showButton.isTouchable(false); 35 | callBack({ status: 'show', drawFn: showButton.isTouchable.bind(null, true) }); 36 | }); 37 | // 点击展示 “按钮” 结束 38 | 39 | // 初始化 小游戏推荐弹窗组件 开始 40 | callBack({ status: 'createGamePortal' }); 41 | // 初始化 小游戏推荐弹窗组件 结束 42 | 43 | !wx.createGamePortal && wx.createGamePortal(); 44 | 45 | goBack.callBack = callBack.bind(null, { status: 'destroy' }); 46 | 47 | container.addChild(goBack, title, api_name, underline, showButton, tipText, logo, logoName); 48 | 49 | app.stage.addChild(container); 50 | 51 | return container; 52 | }; 53 | -------------------------------------------------------------------------------- /miniprogram/js/api/rendering/createImage/index.js: -------------------------------------------------------------------------------- 1 | import view from './view'; 2 | import show from '../../../libs/show'; 3 | module.exports = function(PIXI, app, obj) { 4 | return view(PIXI, app, obj, res => { 5 | let { status, drawFn, Img } = res; 6 | switch (status) { 7 | case 'createImage': 8 | Img = wx.createImage(); 9 | show.Modal(`已创建成功,确认后进行加载图片`, '创建成功', () => { 10 | Img.src = 'images/weapp.jpg'; 11 | Img.onload = () => { 12 | drawFn(Img); 13 | }; 14 | }); 15 | break; 16 | } 17 | }); 18 | }; 19 | -------------------------------------------------------------------------------- /miniprogram/js/api/rendering/loadFont/index.js: -------------------------------------------------------------------------------- 1 | import view from './view'; 2 | module.exports = function(PIXI, app, obj) { 3 | return view(PIXI, app, obj, res => { 4 | let { status, drawFn, font } = res; 5 | switch (status) { 6 | case 'loadFont': 7 | // 加载自定义字体文件 8 | font = wx.loadFont(`TencentSans-W7.subset.ttf`); 9 | drawFn(font); // 更新UI 10 | 11 | break; 12 | } 13 | }); 14 | }; 15 | -------------------------------------------------------------------------------- /miniprogram/js/api/rendering/loadFont/view.js: -------------------------------------------------------------------------------- 1 | import { p_text, p_box, p_button } from '../../../libs/component/index'; 2 | import fixedTemplate from '../../../libs/template/fixed'; 3 | module.exports = function(PIXI, app, obj, callBack) { 4 | let container = new PIXI.Container(), 5 | { goBack, title, api_name, underline, logo, logoName } = fixedTemplate(PIXI, { 6 | obj, 7 | title: '加载自定义字体文件', 8 | api_name: 'loadFont' 9 | }), 10 | box = p_box(PIXI, { 11 | height: 372 * PIXI.ratio, 12 | y: underline.y + underline.height + 23 * PIXI.ratio 13 | }), 14 | text = p_text(PIXI, { 15 | content: 'Hello WeChat', 16 | fontSize: 60 * PIXI.ratio, 17 | fill: 0x353535, 18 | relative_middle: { containerWidth: box.width, containerHeight: box.height } 19 | }), 20 | button = p_button(PIXI, { 21 | width: 580 * PIXI.ratio, 22 | y: box.height + box.y + 80 * PIXI.ratio 23 | }); 24 | 25 | // 加载自定义字体文件 “按钮” 开始 26 | button.myAddChildFn( 27 | p_text(PIXI, { 28 | content: `加载自定义字体文件`, 29 | fontSize: 36 * PIXI.ratio, 30 | fill: 0xffffff, 31 | relative_middle: { containerWidth: button.width, containerHeight: button.height } 32 | }) 33 | ); 34 | button.onClickFn(() => { 35 | callBack({ 36 | status: 'loadFont', 37 | drawFn(font) { 38 | text.turnText('', { fontFamily: font || '' }); 39 | } 40 | }); 41 | }); 42 | // 加载自定义字体文件 “按钮” 结束 43 | 44 | box.addChild(text); 45 | container.addChild(goBack, title, api_name, underline, box, button, logo, logoName); 46 | 47 | app.stage.addChild(container); 48 | 49 | return container; 50 | }; 51 | -------------------------------------------------------------------------------- /miniprogram/js/api/rendering/setPreferredFramesPerSecond/index.js: -------------------------------------------------------------------------------- 1 | import view from './view'; 2 | module.exports = function(PIXI, app, obj) { 3 | return view(PIXI, app, obj, res => { 4 | let { status,value } = res; 5 | switch (status) { 6 | case 'setPreferredFramesPerSecond': 7 | // 设置渲染帧率 8 | wx.setPreferredFramesPerSecond(value); 9 | 10 | break; 11 | } 12 | }); 13 | }; 14 | -------------------------------------------------------------------------------- /miniprogram/js/api/rendering/toDataURL/index.js: -------------------------------------------------------------------------------- 1 | import view from './view'; 2 | import show from '../../../libs/show'; 3 | module.exports = function(PIXI, app, obj) { 4 | const Image = wx.createImage(), 5 | offScreenCanvas = wx.createCanvas(), 6 | ctx = offScreenCanvas.getContext('2d'); 7 | 8 | Image.src = 'images/weapp.jpg'; 9 | Image.onload = () => { 10 | offScreenCanvas.width = Image.width; 11 | offScreenCanvas.height = Image.height; 12 | ctx.drawImage(Image, 0, 0); 13 | }; 14 | 15 | return view(PIXI, app, obj, res => { 16 | let { status, drawFn, base64 } = res; 17 | switch (status) { 18 | case 'toDataURL': 19 | // 把画布内容转换为URL 20 | base64 = offScreenCanvas.toDataURL(); 21 | show.Modal(base64, '转换成功'); 22 | drawFn(base64); 23 | break; 24 | } 25 | }); 26 | }; 27 | -------------------------------------------------------------------------------- /miniprogram/js/api/rendering/toTempFilePath/index.js: -------------------------------------------------------------------------------- 1 | import view from './view'; 2 | module.exports = function(PIXI, app, obj) { 3 | return view(PIXI, app, obj, res => { 4 | let { status, deploy } = res; 5 | switch (status) { 6 | case 'toTempFilePath': 7 | // 将当前 Canvas 保存为一个临时文件 8 | canvas.toTempFilePath({ 9 | ...deploy, 10 | success(res) { 11 | wx.shareAppMessage({ 12 | title: '这是已截好的图', 13 | imageUrl: res.tempFilePath 14 | }); 15 | console.log(res); 16 | } 17 | }); 18 | 19 | break; 20 | } 21 | }); 22 | }; 23 | -------------------------------------------------------------------------------- /miniprogram/js/api/storage-fileSystem/access/index.js: -------------------------------------------------------------------------------- 1 | import view from './view'; 2 | import * as show from '../../../libs/show'; 3 | module.exports = function(PIXI, app, obj) { 4 | return view(PIXI, app, obj, data => { 5 | let { status, index, path } = data; 6 | switch (status) { 7 | case 'access': 8 | path = [`${wx.env.USER_DATA_PATH}/fileA`, `${wx.env.USER_DATA_PATH}/fileA/test.txt`][index]; 9 | // 先获取全局唯一的文件管理器,接着调起access方法 10 | wx.getFileSystemManager().access({ 11 | path, 12 | success() { 13 | wx.showModal({ 14 | content: path + ' 目录存在', 15 | showCancel: false, 16 | confirmColor: '#02BB00' 17 | }); 18 | }, 19 | fail(res) { 20 | if (!res.errMsg) return; 21 | 22 | let err = res.errMsg.split(','); 23 | err[0] = '文件/目录不存在'; 24 | show.Modal(err.join(',')); 25 | } 26 | }); 27 | break; 28 | } 29 | }); 30 | }; 31 | -------------------------------------------------------------------------------- /miniprogram/js/api/storage-fileSystem/dir/index.js: -------------------------------------------------------------------------------- 1 | import view from './view'; 2 | import * as show from '../../../libs/show'; 3 | module.exports = function(PIXI, app, obj) { 4 | return view(PIXI, app, obj, data => { 5 | let { status, drawFn } = data; 6 | switch (status) { 7 | case 'mkdir': 8 | // 先获取全局唯一的文件管理器,接着调起mkdir方法 9 | wx.getFileSystemManager().mkdir({ 10 | dirPath: `${wx.env.USER_DATA_PATH}/fileA`, 11 | recursive: true, 12 | success() { 13 | drawFn(); // 更新UI 14 | 15 | show.Toast('创建成功', 'success', 800); 16 | } 17 | }); 18 | 19 | break; 20 | case 'rmdir': 21 | // 先获取全局唯一的文件管理器,接着调起rmdir方法 22 | wx.getFileSystemManager().rmdir({ 23 | dirPath: `${wx.env.USER_DATA_PATH}/fileA`, 24 | recursive: true, 25 | success() { 26 | drawFn(); // 更新UI 27 | 28 | show.Toast('删除成功', 'success', 800); 29 | } 30 | }); 31 | 32 | break; 33 | } 34 | }); 35 | }; 36 | -------------------------------------------------------------------------------- /miniprogram/js/api/storage-fileSystem/getFileInfo/index.js: -------------------------------------------------------------------------------- 1 | import view from './view'; 2 | import * as show from '../../../libs/show'; 3 | module.exports = function(PIXI, app, obj) { 4 | return view(PIXI, app, obj, data => { 5 | let { status } = data; 6 | switch (status) { 7 | case 'getFileInfo': 8 | // 先获取全局唯一的文件管理器,接着调起getFileInfo方法 9 | wx.getFileSystemManager().getFileInfo({ 10 | filePath: 'images/weapp.jpg', 11 | success(res) { 12 | show.Modal(`这个文件的size:${res.size}B`, '获取成功'); 13 | }, 14 | fail(res) { 15 | if (!res.errMsg) return; 16 | 17 | show.Modal(res.errMsg, '发生错误'); 18 | } 19 | }); 20 | break; 21 | } 22 | }); 23 | }; 24 | -------------------------------------------------------------------------------- /miniprogram/js/api/storage-fileSystem/readdir/index.js: -------------------------------------------------------------------------------- 1 | import view from './view'; 2 | import * as show from '../../../libs/show'; 3 | module.exports = function(PIXI, app, obj) { 4 | return view(PIXI, app, obj, data => { 5 | let { status, dirPath, drawFn } = data; 6 | switch (status) { 7 | case 'readdir': 8 | dirPath = `${wx.env.USER_DATA_PATH}/fileA`; 9 | 10 | // 先获取全局唯一的文件管理器,接着调起readdir方法 11 | wx.getFileSystemManager().readdir({ 12 | dirPath, 13 | success(res) { 14 | if (!(res.files || []).length) return show.Modal('目录内容为空'); 15 | 16 | show.Toast('查看成功', 'success', 800); 17 | 18 | drawFn(dirPath); // 更新UI 19 | }, 20 | fail(res) { 21 | if (!res.errMsg) return; 22 | 23 | if ( 24 | res.errMsg.includes('no such file or directory') || 25 | res.errMsg.includes('fail not a directory') 26 | ) { 27 | res.errMsg = `目录 ${JSON.stringify(dirPath)} 不存在,请去创建`; 28 | 29 | show.Modal(res.errMsg, '发生错误'); 30 | } 31 | } 32 | }); 33 | break; 34 | } 35 | }); 36 | }; 37 | -------------------------------------------------------------------------------- /miniprogram/js/api/storage-fileSystem/rename/index.js: -------------------------------------------------------------------------------- 1 | import view from './view'; 2 | import * as show from '../../../libs/show'; 3 | module.exports = function(PIXI, app, obj) { 4 | return view(PIXI, app, obj, data => { 5 | let { status, pathArr, drawFn } = data; 6 | switch (status) { 7 | case 'rename': 8 | // 先获取全局唯一的文件管理器,接着调起rename方法 9 | wx.getFileSystemManager().rename({ 10 | oldPath: pathArr[0], 11 | newPath: pathArr[1], 12 | success() { 13 | show.Toast('重命名成功', 'success', 800); 14 | 15 | drawFn(); // 更新UI 16 | }, 17 | fail(res) { 18 | if (!res.errMsg) return; 19 | 20 | if (res.errMsg.includes('fail no such file or directory')) { 21 | res.errMsg = `源文件,或目录 ${JSON.stringify( 22 | `${wx.env.USER_DATA_PATH}/fileA` 23 | )} 不存在,请去创建`; 24 | 25 | show.Modal(res.errMsg, '发生错误'); 26 | } 27 | } 28 | }); 29 | break; 30 | } 31 | }); 32 | }; 33 | -------------------------------------------------------------------------------- /miniprogram/js/api/storage-fileSystem/savedFile/index.js: -------------------------------------------------------------------------------- 1 | import view from './view'; 2 | import * as show from '../../../libs/show'; 3 | module.exports = function(PIXI, app, obj) { 4 | return view(PIXI, app, obj, data => { 5 | let { status, paperFile, drawFn } = data; 6 | switch (status) { 7 | case 'getSavedFileList': 8 | // 先获取全局唯一的文件管理器,接着调起getSavedFileList方法 9 | wx.getFileSystemManager().getSavedFileList({ 10 | success(res) { 11 | if (!(res.fileList || []).length) return show.Modal('本地缓存文件列表为空'); 12 | 13 | show.Toast('获取成功', 'success', 800); 14 | 15 | drawFn(res.fileList); // 更新UI 16 | } 17 | }); 18 | break; 19 | 20 | case 'removeSavedFile': 21 | paperFile = paperFile.map(item => { 22 | return new Promise(res => { 23 | // 先获取全局唯一的文件管理器,接着调起removeSavedFile方法 24 | wx.getFileSystemManager().removeSavedFile({ 25 | filePath: item.filePath, 26 | success() { 27 | res(); 28 | } 29 | }); 30 | }); 31 | }); 32 | 33 | Promise.all(paperFile).then(() => { 34 | show.Toast('已清空', 'success', 800); 35 | 36 | drawFn(); // 更新UI 37 | }); 38 | break; 39 | } 40 | }); 41 | }; 42 | -------------------------------------------------------------------------------- /miniprogram/js/api/storage-fileSystem/stat/index.js: -------------------------------------------------------------------------------- 1 | import view from './view'; 2 | import * as show from '../../../libs/show'; 3 | module.exports = function(PIXI, app, obj) { 4 | return view(PIXI, app, obj, data => { 5 | let { status, index } = data; 6 | switch (status) { 7 | case 'stat': 8 | // 先获取全局唯一的文件管理器,接着调起stat方法 9 | wx.getFileSystemManager().stat({ 10 | path: [`${wx.env.USER_DATA_PATH}`, `${wx.env.USER_DATA_PATH}/fileA/hello.txt`][index], 11 | success(res) { 12 | // 获得文件 Stats 对象 13 | let stats = res.stats; 14 | 15 | // 调用 stats.isDirectory() 方法进行判断 16 | show.Toast(`是一个${stats.isDirectory() ? '目录' : '文件'}`, 'success', 800); 17 | }, 18 | fail(res) { 19 | if (!res.errMsg) return; 20 | 21 | if (res.errMsg.includes('no such file or directory')) { 22 | res.errMsg = `源文件,或上级目录 ${JSON.stringify( 23 | `${wx.env.USER_DATA_PATH}/fileA` 24 | )} 不存在,请去创建`; 25 | 26 | show.Modal(res.errMsg, '发生错误'); 27 | } 28 | } 29 | }); 30 | break; 31 | } 32 | }); 33 | }; 34 | -------------------------------------------------------------------------------- /miniprogram/js/api/storage-fileSystem/storage/index.js: -------------------------------------------------------------------------------- 1 | import view from './view'; 2 | import * as show from '../../../libs/show'; 3 | module.exports = function(PIXI, app, obj) { 4 | return view(PIXI, app, obj, data => { 5 | let { status, key, value } = data; 6 | switch (status) { 7 | case 'setStorage': 8 | wx.setStorage({ 9 | key, 10 | data: value, 11 | success() { 12 | show.Modal(`数据存储成功`); 13 | } 14 | }); 15 | break; 16 | 17 | case 'getStorage': 18 | wx.getStorage({ 19 | key, 20 | success(res) { 21 | show.Modal(`data: ${res.data}`, '读取数据成功'); 22 | }, 23 | fail() { 24 | show.Modal('找不到 key 对应的数据', '读取数据失败'); 25 | } 26 | }); 27 | break; 28 | 29 | case 'clearStorage': 30 | wx.clearStorage({ 31 | success() { 32 | show.Modal('清除数据成功'); 33 | } 34 | }); 35 | break; 36 | } 37 | }); 38 | }; 39 | -------------------------------------------------------------------------------- /miniprogram/js/api/storage-fileSystem/unzip/index.js: -------------------------------------------------------------------------------- 1 | import view from './view'; 2 | import * as show from '../../../libs/show'; 3 | module.exports = function(PIXI, app, obj) { 4 | return view(PIXI, app, obj, data => { 5 | let { status } = data; 6 | switch (status) { 7 | case 'unzip': 8 | // 先获取全局唯一的文件管理器,接着调起unzip方法 9 | wx.getFileSystemManager().unzip({ 10 | zipFilePath: 'test.zip', // 压缩包在代码包的根路径上面 11 | targetPath: `${wx.env.USER_DATA_PATH}/fileA`, 12 | success() { 13 | show.Toast('解压成功', 'success', 800); 14 | } 15 | }); 16 | break; 17 | } 18 | }); 19 | }; 20 | -------------------------------------------------------------------------------- /miniprogram/js/api/worker/index.js: -------------------------------------------------------------------------------- 1 | import view from './view'; 2 | import show from '../../libs/show'; 3 | module.exports = function(PIXI, app, obj) { 4 | const worker = wx.createWorker('workers/index.js'); 5 | 6 | return view(PIXI, app, obj, res => { 7 | let num, fabonacci; 8 | switch (res.status) { 9 | case 'noWorker': 10 | fabonacci = n => { 11 | return n < 2 ? n : fabonacci(n - 1) + fabonacci(n - 2); 12 | }; 13 | 14 | num = fabonacci(res.fabonacciIndex); 15 | 16 | show.Modal(`${num}`, '计算结果'); 17 | 18 | break; 19 | case 'Worker': 20 | worker.postMessage({ 21 | msg: res.fabonacciIndex 22 | }); 23 | 24 | worker.onMessage(obj => { 25 | show.Modal(`${obj.msg}`, '计算结果'); 26 | }); 27 | break; 28 | } 29 | }); 30 | }; 31 | -------------------------------------------------------------------------------- /miniprogram/js/errMsg/index.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | errMsgGlobal: { 3 | 'fail file already exists': obj => { 4 | obj.callback(`错误:存在同名文件或目录`); 5 | }, 6 | 'fail tempFilePath file not exist': obj => { 7 | obj.callback(`错误:指定的 tempFilePath 找不到文件`); 8 | }, 9 | 'fail exceeded the maximum size of the file storage limit 50M': obj => { 10 | obj.callback(`错误:超过文件存储限制的最大大小50M`); 11 | }, 12 | 'fail directory not empty': obj => { 13 | obj.callback(`错误:目录不为空`); 14 | }, 15 | ERR_PARENT_DIR_NOT_EXISTS: obj => { 16 | obj.callback(`错误:文件所在目录不存在请去添加目录`); 17 | }, 18 | MEDIA_ERR_NETWORK: obj => { 19 | obj.callback(`当下载时发生错误`); 20 | }, 21 | MEDIA_ERR_DECODE: obj => { 22 | obj.callback(`解码错误`); 23 | }, 24 | MEDIA_ERR_SRC_NOT_SUPPORTED: obj => { 25 | obj.callback(`video 的 src 属性是不支持的资源类型`); 26 | } 27 | }, 28 | gameAdError: { 29 | 1000: '后端错误调用失败:该项错误不是开发者的异常情况', 30 | 1001: '参数错误', 31 | 1002: '推荐位id无效:可能是拼写错误、或者误用了其他小游戏的推荐位id', 32 | 1004: '无适合的推荐:推荐不是每一次都会出现,这次没有出现可能是由于该用户不适合浏览推荐', 33 | 1008: '推荐位已关闭:该推荐位的推荐能力已经被关闭', 34 | 1009: '推荐位id类型错误: 可能复制了其他类型的推荐位id' 35 | }, 36 | subscribeWhatsNew: { 37 | 1: '系统错误', 38 | 2: '用户已订阅该类型消息', 39 | 3: '超过频率限制,暂时不允许发起订阅', 40 | 4: '没有权限或已封禁' 41 | }, 42 | whatsNewSubscriptions: { 43 | 0: '未知状态', 44 | 1: '未订阅,可以发起订阅' 45 | } 46 | }; 47 | -------------------------------------------------------------------------------- /miniprogram/js/libs/compareVersion.js: -------------------------------------------------------------------------------- 1 | module.exports = function (v1, v2) { 2 | v1 = v1.split('.'); 3 | v2 = v2.split('.'); 4 | const len = Math.max(v1.length, v2.length); 5 | 6 | while (v1.length < len) { 7 | v1.push('0'); 8 | } 9 | while (v2.length < len) { 10 | v2.push('0'); 11 | } 12 | 13 | for (let i = 0; i < len; i++) { 14 | const num1 = parseInt(v1[i]); 15 | const num2 = parseInt(v2[i]); 16 | 17 | if (num1 > num2) { 18 | return 1; 19 | } else if (num1 < num2) { 20 | return -1; 21 | } 22 | } 23 | 24 | return 0; 25 | }; 26 | -------------------------------------------------------------------------------- /miniprogram/js/libs/component/box.js: -------------------------------------------------------------------------------- 1 | module.exports = function(PIXI, deploy = {}) { 2 | let { 3 | width = canvas.width, 4 | height = 0, 5 | parentWidth = canvas.width, 6 | background = { 7 | color: 0xffffff, 8 | alpha: 1 9 | }, 10 | border = { 11 | width: 0, 12 | color: 0xffffff, 13 | alpha: 1 14 | }, 15 | x = (parentWidth - width) / 2, 16 | y = 0, 17 | radius = 0 18 | } = deploy; 19 | 20 | function Box() { 21 | this.lineStyle(border.width, border.color, border.alpha).beginFill(background.color, background.alpha); 22 | this[radius ? 'drawRoundedRect' : 'drawRect'](0, 0, width, height, radius).endFill(); 23 | 24 | this.position.set(x, y); 25 | 26 | this.onClickFn = function(callBack) { 27 | this.interactive = true; 28 | this.touchstart = e => { 29 | e.currentTarget.touchend = e => { 30 | e.target.touchend = null; 31 | if (Math.abs(e.recordY - e.data.global.y) < 5) { 32 | callBack(e); 33 | } 34 | }; 35 | e.recordY = e.data.global.y; 36 | }; 37 | }; 38 | 39 | this.turnColors = function(deploy = {}) { 40 | let { background: newBackground, border: newBorder } = deploy; 41 | 42 | newBackground = Object.assign({}, background, newBackground); 43 | newBorder = Object.assign({}, border, newBorder); 44 | 45 | this.clear(); 46 | 47 | this.lineStyle(newBorder.width, newBorder.color, newBorder.alpha) 48 | .beginFill(newBackground.color, newBackground.color) 49 | .drawRoundedRect(0, 0, width, height, radius) 50 | .endFill(); 51 | }; 52 | 53 | this.hideFn = function() { 54 | this.visible = false; 55 | }; 56 | this.showFn = function() { 57 | this.visible = true; 58 | }; 59 | } 60 | Box.prototype = new PIXI.Graphics(); 61 | return new Box(); 62 | }; 63 | -------------------------------------------------------------------------------- /miniprogram/js/libs/component/goBackBtn.js: -------------------------------------------------------------------------------- 1 | import line from './line'; 2 | module.exports = function(PIXI, type, callBack) { 3 | function GoBackBtn() { 4 | const menuButtonInfo = wx.getMenuButtonBoundingClientRect(); 5 | this.beginFill(0xffffff, 0) 6 | .drawRoundedRect(0, 0, 80 * PIXI.ratio, 80 * PIXI.ratio, 0) 7 | .endFill(); 8 | // this.position.set(0, 52 * Math.ceil(PIXI.ratio)); 9 | this.position.set(0, menuButtonInfo.top * PIXI.ratio * 2 - 22 * PIXI.ratio); // 根据menuButtonInfo计算位置 10 | this.addChild( 11 | line( 12 | PIXI, 13 | { 14 | width: 5 * PIXI.ratio, 15 | color: +(type.split(':')[1] || 0x333333) 16 | }, 17 | [41 * PIXI.ratio, 20 * PIXI.ratio], 18 | [-20 * PIXI.ratio, 20 * PIXI.ratio], 19 | [0, 40 * PIXI.ratio] 20 | ) 21 | ); 22 | 23 | (this.isTouchable = function(boolean) { 24 | this.interactive = boolean; 25 | }).call(this, true); 26 | 27 | this.touchstart = e => { 28 | e.currentTarget.touchend = e => { 29 | e.target.touchend = null; 30 | if (Math.abs(e.recordY - e.data.global.y) < 5) { 31 | this.callBack && this.callBack(); 32 | window.router[type.split(':')[0]](); 33 | } 34 | }; 35 | e.recordY = e.data.global.y; 36 | }; 37 | 38 | this.callBack = callBack; 39 | } 40 | GoBackBtn.prototype = new PIXI.Graphics(); 41 | return new GoBackBtn(); 42 | }; 43 | -------------------------------------------------------------------------------- /miniprogram/js/libs/component/index.js: -------------------------------------------------------------------------------- 1 | import box from './box'; 2 | import button from './button'; 3 | import goBackBtn from './goBackBtn'; 4 | import img from './img'; 5 | import line from './line'; 6 | import scroll from './scroll'; 7 | import text from './text'; 8 | import circle from './circle'; 9 | import linearGradientBox from './linearGradientBox'; 10 | import texture from './texture'; 11 | import textarea from './textarea'; 12 | 13 | module.exports = { 14 | p_box: box, 15 | p_button: button, 16 | p_goBackBtn: goBackBtn, 17 | p_img: img, 18 | p_line: line, 19 | p_scroll: scroll, 20 | p_text: text, 21 | p_circle: circle, 22 | p_linearGradientBox: linearGradientBox, 23 | p_texture: texture, 24 | p_textarea: textarea 25 | }; 26 | -------------------------------------------------------------------------------- /miniprogram/js/libs/component/line.js: -------------------------------------------------------------------------------- 1 | module.exports = function(PIXI, deploy = {}) { 2 | let { width = 0, color = 0x000000, alpha = 1 } = deploy; 3 | let pointCoordinatesArr = Array.prototype.slice.call(arguments, 2); 4 | function Line() { 5 | this.lineStyle(width, color, alpha).moveTo(0, 0); 6 | function drawLineFn(arr) { 7 | this.position.set(...arr[0]); 8 | for (let i = 1, len = arr.length; i < len; i++) { 9 | this.lineTo(...arr[i]); 10 | } 11 | } 12 | drawLineFn.call(this, pointCoordinatesArr); 13 | 14 | this.redrawFn = function(css) { 15 | let pointCoordinatesArr = arguments; 16 | if (Object.prototype.toString.call(css) === '[object Object]') pointCoordinatesArr.shift(); 17 | this.clear(); 18 | this.lineStyle(css.width || width, css.color || color, css.alpha || alpha).moveTo(0, 0); 19 | drawLineFn.call(this, pointCoordinatesArr); 20 | }; 21 | } 22 | Line.prototype = new PIXI.Graphics(); 23 | return new Line(); 24 | }; 25 | -------------------------------------------------------------------------------- /miniprogram/js/libs/component/scroll.js: -------------------------------------------------------------------------------- 1 | import Scroller from "../Scroller/index"; 2 | module.exports = function (PIXI, deploy = {}) { 3 | let { 4 | width = canvas.width, 5 | height = 0, 6 | x = (canvas.width - width) / 2, 7 | y = 0, 8 | } = deploy; 9 | 10 | function Scroll() { 11 | let container = new PIXI.Container(), 12 | mask = new PIXI.Graphics(); 13 | 14 | mask.beginFill(0xffffff).drawRect(0, 0, width, height).endFill(); 15 | 16 | container.mask = mask; 17 | 18 | this.myAddChildFn = function (...itemArr) { 19 | container.addChild(...itemArr); 20 | this.scroller.contentSize(width, height, width, container.height); 21 | }; 22 | 23 | this.myRemoveChildrenFn = function (beginIndex, endIndex) { 24 | container.removeChildren(beginIndex, endIndex); 25 | this.scroller.contentSize(width, height, width, container.height); 26 | }; 27 | 28 | this.isTouchable = function (boolean) { 29 | this.interactive = boolean; 30 | }; 31 | 32 | this.scroller = new Scroller((...args) => { 33 | this.monitor && this.monitor(-args[1]); 34 | container.position.y = -args[1]; 35 | }); 36 | 37 | this.touchstart = (e) => { 38 | e.stopPropagation(); 39 | this.scroller.doTouchStart(e.data.global.x, e.data.global.y); 40 | }; 41 | 42 | this.touchmove = (e) => { 43 | e.stopPropagation(); 44 | this.scroller.doTouchMove( 45 | e.data.global.x, 46 | e.data.global.y, 47 | e.data.originalEvent.timeStamp 48 | ); 49 | }; 50 | 51 | this.touchend = (e) => { 52 | e.stopPropagation(); 53 | this.scroller.doTouchEnd(e.data.originalEvent.timeStamp); 54 | }; 55 | 56 | this.isTouchable(true); 57 | 58 | for (let i = 0, arr = ["width", "height"], len = arr.length; i < len; i++) { 59 | Object.defineProperty(this, arr[i], { 60 | get() { 61 | return mask[arr[i]]; 62 | }, 63 | }); 64 | } 65 | 66 | this.addChild(container, mask); 67 | this.position.set(x, y); 68 | } 69 | 70 | Scroll.prototype = new PIXI.Container(); 71 | 72 | return new Scroll(); 73 | }; 74 | -------------------------------------------------------------------------------- /miniprogram/js/libs/component/text.js: -------------------------------------------------------------------------------- 1 | module.exports = function (PIXI, deploy = {}) { 2 | let { 3 | x = 0, 4 | y = 0, 5 | content = "", 6 | fontSize = 0, 7 | fill = 0x000000, 8 | fontWeight = "normal", 9 | align = "left", 10 | lineHeight = fontSize * 1.2, 11 | vertical_center_correction_value = 0, 12 | relative_middle = { 13 | containerWidth: null, 14 | containerHeight: null, 15 | point: null, 16 | }, 17 | } = deploy; 18 | 19 | function Text() { 20 | (this.setPositionFn = function (deploy = {}) { 21 | let { x: new_x, y: new_y, relative_middle: new_relative_middle } = deploy, 22 | { containerWidth, containerHeight, point } = 23 | new_relative_middle || relative_middle; 24 | 25 | new_x = 26 | new_x || 27 | (typeof point === "number" && (new_x = point - this.width / 2)) || 28 | x; 29 | new_y = new_y || y; 30 | 31 | this.position.set( 32 | containerWidth ? (containerWidth - this.width) / 2 : new_x, 33 | containerHeight 34 | ? (containerHeight - this.height + vertical_center_correction_value) / 35 | 2 36 | : new_y 37 | ); 38 | }).call(this); 39 | 40 | this.turnColors = function (newColor) { 41 | this.style.fill = newColor; 42 | }; 43 | this.turnText = function (str, style) { 44 | this.toString.call(style) === "[object Object]" && 45 | Object.assign(this.style, style); 46 | this.text = str || content; 47 | this.setPositionFn(); 48 | }; 49 | this.hideFn = function () { 50 | this.visible = false; 51 | }; 52 | this.showFn = function () { 53 | this.visible = true; 54 | }; 55 | } 56 | Text.prototype = new PIXI.Text(content, { 57 | fontSize: `${fontSize}px`, 58 | fill, 59 | align, 60 | fontWeight, 61 | lineHeight, 62 | }); 63 | return new Text(); 64 | }; 65 | -------------------------------------------------------------------------------- /miniprogram/js/libs/dateFormat.js: -------------------------------------------------------------------------------- 1 | module.exports = function(time, fmt) { 2 | var o = { 3 | 'M+': time.getMonth() + 1, //月份 4 | 'd+': time.getDate(), //日 5 | 'h+': time.getHours(), //小时 6 | 'm+': time.getMinutes(), //分 7 | 's+': time.getSeconds(), //秒 8 | 'q+': Math.floor((time.getMonth() + 3) / 3), //季度 9 | S: time.getMilliseconds() //毫秒 10 | }; 11 | 12 | if (/(y+)/.test(fmt)) { 13 | fmt = fmt.replace(RegExp.$1, (time.getFullYear() + '').substr(4 - RegExp.$1.length)); 14 | } 15 | 16 | for (let i = 0, arr = Object.keys(o), len = arr.length; i < len; i++) { 17 | if (new RegExp('(' + arr[i] + ')').test(fmt)) { 18 | fmt = fmt.replace( 19 | RegExp.$1, 20 | RegExp.$1.length == 1 ? o[arr[i]] : ('00' + o[arr[i]]).substr(('' + o[arr[i]]).length) 21 | ); 22 | } 23 | } 24 | 25 | return fmt; 26 | }; 27 | -------------------------------------------------------------------------------- /miniprogram/js/libs/pmgressBar.js: -------------------------------------------------------------------------------- 1 | module.exports = function(PIXI, app, obj) { 2 | let container = new PIXI.Container(), 3 | pmgressBar = { 4 | gray: new PIXI.Graphics(), 5 | green: new PIXI.Graphics(), 6 | text: new PIXI.Text('分包正在玩命加载中...', { 7 | fontSize: `${28 * PIXI.ratio}px`, 8 | fill: 0x999999 9 | }) 10 | }; 11 | 12 | pmgressBar.gray 13 | .beginFill(0x999999) 14 | .drawRect(0, 0, (obj.width * 9) / 11, 5 * PIXI.ratio) 15 | .endFill(); 16 | pmgressBar.gray.position.set(obj.width / 11, (obj.height - pmgressBar.gray.height) / 2); 17 | pmgressBar.green 18 | .beginFill(0x07c160) 19 | .drawRect(0, 0, pmgressBar.gray.width, pmgressBar.gray.height) 20 | .endFill(); 21 | pmgressBar.green.position.set(pmgressBar.gray.x, pmgressBar.gray.y); 22 | pmgressBar.green.width = 0; 23 | 24 | pmgressBar.text.position.set( 25 | (obj.width - pmgressBar.text.width) / 2, 26 | pmgressBar.gray.y + pmgressBar.gray.height + 10 * PIXI.ratio 27 | ); 28 | 29 | container.addChild(pmgressBar.gray, pmgressBar.green, pmgressBar.text); 30 | app.stage.addChild(container); 31 | return function(int_iPos) { 32 | if (!container) return; 33 | pmgressBar.green.width = (pmgressBar.gray.width / 100) * int_iPos; 34 | if (int_iPos === 100) { 35 | container.visible = false; 36 | app.stage.removeChild(container); 37 | container.destroy(true); 38 | container = null; 39 | } 40 | }; 41 | }; 42 | -------------------------------------------------------------------------------- /miniprogram/js/libs/share.js: -------------------------------------------------------------------------------- 1 | module.exports = function () { 2 | wx.showShareMenu({ 3 | withShareTicket: true, 4 | menus: ['shareAppMessage', 'shareTimeline'], 5 | }); 6 | 7 | const callBack = () => { 8 | let query = window.router.getNowPageName() !== 'APIentry' && `pathName=${window.router.getNowPageName()}`; 9 | (window.query || {}).roomName && (query = query + `&roomName=${window.query.roomName}`); 10 | return { 11 | title: window.router.getNowPageLabel(), 12 | imageUrl: canvas.toTempFilePathSync({ 13 | x: 0, 14 | y: 0, 15 | width: canvas.width, 16 | height: (canvas.width * 4) / 5, 17 | }), 18 | query, 19 | }; 20 | }; 21 | 22 | // 监听被动调起分享 23 | wx.onShareAppMessage(callBack); 24 | 25 | // 监听被动调起分享到朋友圈 26 | wx.onShareTimeline && wx.onShareTimeline(callBack); 27 | }; 28 | -------------------------------------------------------------------------------- /miniprogram/js/libs/show.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | Modal(content, title, callback) { 3 | if (title && typeof title === 'string') title = { title }; 4 | 5 | if (typeof title === 'function') { 6 | callback = title; 7 | title = void 0; 8 | } 9 | 10 | wx.showModal({ 11 | ...title, 12 | content, 13 | showCancel: false, 14 | confirmColor: '#02BB00', 15 | success() { 16 | callback && callback(); 17 | } 18 | }); 19 | }, 20 | Toast(content, icon = 'none', duration = 1500) { 21 | wx.showToast({ 22 | title: content, 23 | icon, 24 | duration, 25 | mask: true 26 | }); 27 | }, 28 | ActionSheet(itemList, callback) { 29 | wx.showActionSheet({ 30 | itemList, 31 | success(res) { 32 | callback && callback(res); 33 | }, 34 | fail(res) { 35 | callback && callback(res); 36 | } 37 | }); 38 | } 39 | }; 40 | -------------------------------------------------------------------------------- /miniprogram/js/libs/template/fixed.js: -------------------------------------------------------------------------------- 1 | import { p_goBackBtn, p_line, p_text, p_img } from '../component/index'; 2 | module.exports = function(PIXI, { obj, title, api_name, underline = true }) { 3 | const menuButtonInfo = wx.getMenuButtonBoundingClientRect(); 4 | let goBack, logo, logoName, desc; 5 | 6 | goBack = p_goBackBtn(PIXI, 'navigateBack'); 7 | 8 | title && 9 | (title = p_text(PIXI, { 10 | content: title, 11 | fontSize: 36 * PIXI.ratio, 12 | fill: 0x353535, 13 | // y: 52 * Math.ceil(PIXI.ratio) + 22 * PIXI.ratio, 14 | y: menuButtonInfo.top * PIXI.ratio * 2, 15 | relative_middle: { containerWidth: obj.width } 16 | })); 17 | 18 | api_name && 19 | (api_name = p_text(PIXI, { 20 | content: api_name, 21 | fontSize: 32 * PIXI.ratio, 22 | fill: 0xbebebe, 23 | y: title.height + title.y + 78 * PIXI.ratio, 24 | relative_middle: { containerWidth: obj.width } 25 | })); 26 | 27 | underline && 28 | (underline = p_line( 29 | PIXI, 30 | { 31 | width: PIXI.ratio | 0, 32 | color: 0xd8d8d8 33 | }, 34 | [(obj.width - 150 * PIXI.ratio) / 2, api_name.y + api_name.height + 23 * PIXI.ratio], 35 | [150 * PIXI.ratio, 0] 36 | )); 37 | 38 | logo = p_img(PIXI, { 39 | width: 36 * PIXI.ratio, 40 | x: 288 * PIXI.ratio, 41 | y: obj.height - 66 * PIXI.ratio, 42 | src: 'images/logo.png' 43 | }); 44 | 45 | logoName = p_text(PIXI, { 46 | content: '小游戏示例', 47 | fontSize: 26 * PIXI.ratio, 48 | fill: 0x576b95, 49 | y: (obj.height - 62 * PIXI.ratio) | 0, 50 | relative_middle: { point: 401 * PIXI.ratio } 51 | }); 52 | 53 | return { 54 | goBack, 55 | title, 56 | api_name, 57 | underline, 58 | logo, 59 | logoName, 60 | }; 61 | }; 62 | -------------------------------------------------------------------------------- /miniprogram/sub/PCHandoff.js: -------------------------------------------------------------------------------- 1 | const Layout = requirePlugin('Layout').default; 2 | 3 | export function bindCheckHandoffEnabled(type) { 4 | const button = Layout.getElementsByClassName(type.className)[0]; 5 | 6 | button.on('click', () => { 7 | try { 8 | wx.checkHandoffEnabled({ 9 | success: type.success, 10 | fail: type.fail, 11 | }); 12 | } catch (error) { 13 | type.fail(error); 14 | } 15 | }); 16 | } 17 | 18 | export function bindStartHandoff(type) { 19 | const button = Layout.getElementsByClassName(type.className)[0]; 20 | 21 | button.on('click', () => { 22 | wx.startHandoff(); 23 | }); 24 | } 25 | -------------------------------------------------------------------------------- /miniprogram/sub/data/index.js: -------------------------------------------------------------------------------- 1 | export function getGroupMembersInfo(members) { 2 | console.log('[WX OpenData] getGroupMembersInfo with members: ', members); 3 | return new Promise((resolve, reject) => { 4 | // @ts-ignore 声明未更新临时处理 5 | wx.getGroupMembersInfo({ 6 | members, 7 | success: (res) => { 8 | console.log('[WX OpenData] getGroupMembersInfo success: ', res); 9 | resolve(res); // 成功时返回 res 10 | }, 11 | fail: (err) => { 12 | console.error('[WX OpenData] getGroupMembersInfo fail: ', err); 13 | reject(err); // 失败时返回 err 14 | }, 15 | }); 16 | }); 17 | } 18 | -------------------------------------------------------------------------------- /miniprogram/sub/data/index.ts: -------------------------------------------------------------------------------- 1 | export function getGroupMembersInfo(members: string[]): Promise { 2 | console.log('[WX OpenData] getGroupMembersInfo with members: ', members); 3 | return new Promise((resolve, reject) => { 4 | // @ts-ignore 声明未更新临时处理 5 | wx.getGroupMembersInfo({ 6 | members, 7 | success: (res: any) => { 8 | console.log('[WX OpenData] getGroupMembersInfo success: ', res); 9 | resolve(res); // 成功时返回 res 10 | }, 11 | fail: (err: any) => { 12 | console.error('[WX OpenData] getGroupMembersInfo fail: ', err); 13 | reject(err); // 失败时返回 err 14 | }, 15 | }); 16 | }); 17 | } 18 | -------------------------------------------------------------------------------- /miniprogram/sub/img/loading.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-demo/de1c8edf16cf8bf3d9432f83e1f0d397598e70a3/miniprogram/sub/img/loading.png -------------------------------------------------------------------------------- /miniprogram/sub/img/refresh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-demo/de1c8edf16cf8bf3d9432f83e1f0d397598e70a3/miniprogram/sub/img/refresh.png -------------------------------------------------------------------------------- /miniprogram/sub/loading.js: -------------------------------------------------------------------------------- 1 | // 通过插件的方式引用 Layout 2 | const Layout = requirePlugin('Layout').default; 3 | const sharedCanvas = wx.getSharedCanvas(); 4 | const sharedContext = sharedCanvas.getContext("2d"); 5 | const style = { 6 | container: { 7 | width: '100%', 8 | height: '100%', 9 | justifyContent: "center", 10 | alignItems: "center", 11 | }, 12 | loading: { 13 | width: 150, 14 | height: 150, 15 | borderRadius: 75, 16 | }, 17 | }; 18 | const tpl = ` 19 | 20 | 21 | 22 | `; 23 | export function showLoading() { 24 | Layout.clear(); 25 | Layout.init(tpl, style); 26 | Layout.layout(sharedContext); 27 | const image = Layout.getElementById('loading'); 28 | let degrees = 0; 29 | Layout.ticker.add(() => { 30 | degrees = (degrees + 2) % 360; 31 | image.style.transform = `rotate(${degrees}deg)`; 32 | }); 33 | } 34 | -------------------------------------------------------------------------------- /miniprogram/sub/loading.ts: -------------------------------------------------------------------------------- 1 | // 通过插件的方式引用 Layout 2 | const Layout = requirePlugin('Layout').default; 3 | const sharedCanvas = wx.getSharedCanvas(); 4 | const sharedContext = sharedCanvas.getContext("2d"); 5 | const style = { 6 | container: { 7 | width: '100%', 8 | height: '100%', 9 | justifyContent: "center", 10 | alignItems: "center", 11 | }, 12 | loading: { 13 | width: 150, 14 | height: 150, 15 | borderRadius: 75, 16 | }, 17 | }; 18 | 19 | const tpl = ` 20 | 21 | 22 | 23 | `; 24 | 25 | export function showLoading() { 26 | Layout.clear(); 27 | Layout.init(tpl, style); 28 | Layout.layout(sharedContext); 29 | const image = Layout.getElementById('loading'); 30 | let degrees = 0; 31 | Layout.ticker.add(() => { 32 | degrees = (degrees + 2) % 360; 33 | image.style.transform = `rotate(${degrees}deg)`; 34 | }); 35 | } 36 | -------------------------------------------------------------------------------- /miniprogram/sub/pushMessage.js: -------------------------------------------------------------------------------- 1 | const Layout = requirePlugin('Layout').default; 2 | 3 | export function interactive(data, selfData) { 4 | const buttonList = Layout.getElementsByClassName('itemButton'); 5 | 6 | buttonList.forEach((item, index) => { 7 | item.on('click', () => { 8 | if ((selfData, data[index].nickname === selfData.nickname)) return; 9 | wx.modifyFriendInteractiveStorage({ 10 | key: '1', // 需要修改的数据的 key,目前可以为 '1' - '50' 11 | opNum: 1, // 需要修改的数值,目前只能为 1 12 | operation: 'add', // 修改类型,目前只能是add 13 | toUser: data[index].openid, // 好友的 openId 14 | title: '送你 1 个金币,赶快打开游戏看看吧',// 2.9.0 支持 15 | imageUrl: 'images/miniGame.png' 16 | }); 17 | }); 18 | }); 19 | } 20 | 21 | export function directional(data) { 22 | const buttonList = Layout.getElementsByClassName('itemButton'); 23 | 24 | buttonList.forEach((item, index) => { 25 | item.on('click', () => { 26 | wx.shareMessageToFriend({ 27 | openId: data[index].openid, 28 | title: '小游戏示例', 29 | imageUrl: 'images/miniGame.png' 30 | }); 31 | }); 32 | }); 33 | } 34 | 35 | export function refreshDirected(fn) { 36 | const button = Layout.getElementsByClassName('captionRight')[0]; 37 | 38 | button.on('click', () => { 39 | fn && fn() 40 | }) 41 | } -------------------------------------------------------------------------------- /miniprogram/sub/render/styles/groupTaskFriendList.js: -------------------------------------------------------------------------------- 1 | export default function getStyle(data) { 2 | const { left, top, width, height, scale } = data; 3 | function r(value) { 4 | return value * scale; 5 | } 6 | return { 7 | container: { 8 | top: r(top), 9 | left: r(left), 10 | width: r(width), 11 | height: r(height), 12 | }, 13 | rankList: { 14 | width: r(width), 15 | height: r(height), 16 | }, 17 | list: { 18 | width: r(width), 19 | height: r(height), 20 | flexDirection: 'column', 21 | justifyContent: 'flex-start', 22 | alignItems: 'center', 23 | }, 24 | listItem: { 25 | position: 'relative', 26 | width: r(width), 27 | height: r(67), 28 | flexDirection: 'row', 29 | justifyContent: 'flex-start', 30 | alignItems: 'center', 31 | }, 32 | rankAvatar: { 33 | position: 'relative', 34 | marginLeft: r(10), 35 | width: r(52), 36 | height: r(52), 37 | }, 38 | rankName: { 39 | position: 'relative', 40 | verticalAlign: 'middle', 41 | marginLeft: r(10), 42 | width: r(220), 43 | fontSize: r(17), 44 | textOverflow: 'ellipsis', 45 | color: '#000000', 46 | }, 47 | countText: { 48 | position: 'relative', 49 | verticalAlign: 'middle', 50 | marginLeft: r(10), 51 | fontSize: r(17), 52 | textOverflow: 'ellipsis', 53 | color: '#000000', 54 | }, 55 | participantTips: { 56 | width: r(width), 57 | whiteSpace: 'normal', 58 | position: 'relative', 59 | marginTop: r(16), 60 | height: r(50), 61 | verticalAlign: 'middle', 62 | textAlign: 'center', 63 | fontSize: r(14), 64 | color: '#000000', 65 | opacity: 0.3, 66 | }, 67 | }; 68 | } 69 | -------------------------------------------------------------------------------- /miniprogram/sub/render/styles/groupTaskFriendList.ts: -------------------------------------------------------------------------------- 1 | export default function getStyle(data: { 2 | left: number, 3 | top: number, 4 | width: number, 5 | height: number, 6 | scale: number, 7 | }) { 8 | const { left, top, width, height, scale } = data; 9 | function r(value: number) { 10 | return value * scale; 11 | } 12 | return { 13 | container: { 14 | top: r(top), 15 | left: r(left), 16 | width: r(width), 17 | height: r(height), 18 | }, 19 | 20 | rankList: { 21 | width: r(width), 22 | height: r(height), 23 | }, 24 | 25 | list: { 26 | width: r(width), 27 | height: r(height), 28 | flexDirection: 'column', 29 | justifyContent: 'flex-start', 30 | alignItems: 'center', 31 | }, 32 | 33 | listItem: { 34 | position: 'relative', 35 | width: r(width), 36 | height: r(67), 37 | flexDirection: 'row', 38 | justifyContent: 'flex-start', 39 | alignItems: 'center', 40 | }, 41 | 42 | rankAvatar: { 43 | position: 'relative', 44 | marginLeft: r(10), 45 | width: r(52), 46 | height: r(52), 47 | }, 48 | 49 | rankName: { 50 | position: 'relative', 51 | verticalAlign: 'middle', 52 | marginLeft: r(10), 53 | width: r(220), 54 | fontSize: r(17), 55 | textOverflow: 'ellipsis', 56 | color: '#000000', 57 | }, 58 | 59 | countText: { 60 | position: 'relative', 61 | verticalAlign: 'middle', 62 | marginLeft: r(10), 63 | fontSize: r(17), 64 | textOverflow: 'ellipsis', 65 | color: '#000000', 66 | }, 67 | 68 | participantTips: { 69 | width: r(width), 70 | whiteSpace: 'normal', 71 | position: 'relative', 72 | marginTop: r(16), 73 | height: r(50), 74 | verticalAlign: 'middle', 75 | textAlign: 'center', 76 | fontSize: r(14), 77 | color: '#000000', 78 | opacity: 0.3, 79 | }, 80 | }; 81 | } 82 | -------------------------------------------------------------------------------- /miniprogram/sub/render/styles/tips.js: -------------------------------------------------------------------------------- 1 | export default function getStyle(data) { 2 | const { left, top, width, height, scale } = data; 3 | function r(value) { 4 | return value * scale; 5 | } 6 | return { 7 | container: { 8 | left: r(left), 9 | top: r(top), 10 | width: r(width), 11 | height: r(height), 12 | flexDirection: 'column', 13 | justifyContent: 'center', 14 | alignItems: 'center', 15 | }, 16 | tips: { 17 | margin: r(3), 18 | color: '#a9a9a9', 19 | fontSize: r(16), 20 | textAlign: 'center', 21 | verticalAlign: 'middle', 22 | }, 23 | subTips: { 24 | margin: r(5), 25 | marginTop: r(16), 26 | color: '#a9a9a9', 27 | fontSize: r(16), 28 | textAlign: 'center', 29 | width: r(width), 30 | verticalAlign: 'middle', 31 | }, 32 | }; 33 | } 34 | -------------------------------------------------------------------------------- /miniprogram/sub/render/styles/tips.ts: -------------------------------------------------------------------------------- 1 | export default function getStyle(data: { 2 | left: number, 3 | top: number, 4 | width: number, 5 | height: number, 6 | scale: number, 7 | }) { 8 | const { left, top, width, height, scale } = data; 9 | function r(value: number) { 10 | return value * scale; 11 | } 12 | return { 13 | container: { 14 | left: r(left), 15 | top: r(top), 16 | width: r(width), 17 | height: r(height), 18 | flexDirection: 'column', 19 | justifyContent: 'center', 20 | alignItems: 'center', 21 | }, 22 | tips: { 23 | margin: r(3), 24 | color: '#a9a9a9', 25 | fontSize: r(16), 26 | textAlign: 'center', 27 | verticalAlign: 'middle', 28 | }, 29 | subTips: { 30 | margin: r(5), 31 | marginTop: r(16), 32 | color: '#a9a9a9', 33 | fontSize: r(16), 34 | textAlign: 'center', 35 | width: r(width), 36 | verticalAlign: 'middle', 37 | }, 38 | }; 39 | } 40 | -------------------------------------------------------------------------------- /miniprogram/sub/render/template.js: -------------------------------------------------------------------------------- 1 | const template = ` 2 | 3 | 4 | 5 | 6 | 7 | 8 | {{~it.data :item:index}} 9 | {{? index % 2 === 1 }} 10 | 11 | {{?}} 12 | {{? index % 2 === 0 }} 13 | 14 | {{?}} 15 | 16 | 17 | 18 | {{? it.hideScore}} 19 | 20 | 21 | {{?}} 22 | 23 | {{~}} 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | `; 37 | 38 | -------------------------------------------------------------------------------- /miniprogram/sub/render/tpls/groupTaskFriendList.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 下面的内容分成两部分,第一部分是一个模板,模板的好处是能够有一定的语法 3 | * 坏处是模板引擎一般都依赖 new Function 或者 eval 能力,小游戏下面是没有的 4 | * 所以模板的编译需要在外部完成,可以将注释内的模板贴到下面的页面内,点击 "run"就能够得到编译后的模板函数 5 | * https://wechat-miniprogram.github.io/minigame-canvas-engine/playground.html 6 | * 如果觉得模板引擎使用过于麻烦,也可以手动拼接字符串,本文件对应函数的目标仅仅是为了创建出 xml 节点数 7 | */ 8 | /* 9 | 10 | 11 | 12 | {{~it.data :item:index}} 13 | 14 | 15 | 16 | 17 | 18 | {{~}} 19 | 20 | 21 | 22 | 23 | */ 24 | /** 25 | * xml经过doT.js编译出的模板函数 26 | * 因为小游戏不支持new Function,模板函数只能外部编译 27 | * 可直接拷贝本函数到小游戏中使用 28 | */ 29 | export default function tplFunc(it) { 30 | var out = ' '; 31 | var arr1 = it.data; 32 | if (arr1) { 33 | var item, index = -1, l1 = arr1.length - 1; 34 | while (index < l1) { 35 | item = arr1[index += 1]; 36 | out += ' '; 37 | } 38 | } 39 | out += ' '; 40 | return out; 41 | } 42 | -------------------------------------------------------------------------------- /miniprogram/sub/render/tpls/groupTaskFriendList.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * 下面的内容分成两部分,第一部分是一个模板,模板的好处是能够有一定的语法 3 | * 坏处是模板引擎一般都依赖 new Function 或者 eval 能力,小游戏下面是没有的 4 | * 所以模板的编译需要在外部完成,可以将注释内的模板贴到下面的页面内,点击 "run"就能够得到编译后的模板函数 5 | * https://wechat-miniprogram.github.io/minigame-canvas-engine/playground.html 6 | * 如果觉得模板引擎使用过于麻烦,也可以手动拼接字符串,本文件对应函数的目标仅仅是为了创建出 xml 节点数 7 | */ 8 | 9 | /* 10 | 11 | 12 | 13 | {{~it.data :item:index}} 14 | 15 | 16 | 17 | 18 | 19 | {{~}} 20 | 21 | 22 | 23 | 24 | */ 25 | 26 | /** 27 | * xml经过doT.js编译出的模板函数 28 | * 因为小游戏不支持new Function,模板函数只能外部编译 29 | * 可直接拷贝本函数到小游戏中使用 30 | */ 31 | export default function tplFunc(it) { 32 | var out = ' '; 33 | var arr1 = it.data; 34 | if (arr1) { 35 | var item, index = -1, 36 | l1 = arr1.length - 1; 37 | while (index < l1) { 38 | item = arr1[index += 1]; 39 | out += ' '; 40 | } 41 | } 42 | out += ' '; 43 | return out; 44 | } -------------------------------------------------------------------------------- /miniprogram/sub/render/tpls/tips.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 下面的内容分成两部分,第一部分是一个模板,模板的好处是能够有一定的语法 3 | * 坏处是模板引擎一般都依赖 new Function 或者 eval 能力,小游戏下面是没有的 4 | * 所以模板的编译需要在外部完成,可以将注释内的模板贴到下面的页面内,点击 "run"就能够得到编译后的模板函数 5 | * https://wechat-miniprogram.github.io/minigame-canvas-engine/playground.html 6 | * 如果觉得模板引擎使用过于麻烦,也可以手动拼接字符串,本文件对应函数的目标仅仅是为了创建出 xml 节点数 7 | */ 8 | /** 9 | 10 | 11 | 12 | 13 | 14 | 15 | */ 16 | /** 17 | * xml经过doT.js编译出的模板函数 18 | * 因为小游戏不支持new Function,模板函数只能外部编译 19 | * 可直接拷贝本函数到小游戏中使用 20 | */ 21 | export default function anonymous(it) { 22 | var out = ' '; 23 | return out; 24 | } 25 | -------------------------------------------------------------------------------- /miniprogram/sub/render/tpls/tips.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * 下面的内容分成两部分,第一部分是一个模板,模板的好处是能够有一定的语法 3 | * 坏处是模板引擎一般都依赖 new Function 或者 eval 能力,小游戏下面是没有的 4 | * 所以模板的编译需要在外部完成,可以将注释内的模板贴到下面的页面内,点击 "run"就能够得到编译后的模板函数 5 | * https://wechat-miniprogram.github.io/minigame-canvas-engine/playground.html 6 | * 如果觉得模板引擎使用过于麻烦,也可以手动拼接字符串,本文件对应函数的目标仅仅是为了创建出 xml 节点数 7 | */ 8 | 9 | /** 10 | 11 | 12 | 13 | 14 | 15 | 16 | */ 17 | 18 | /** 19 | * xml经过doT.js编译出的模板函数 20 | * 因为小游戏不支持new Function,模板函数只能外部编译 21 | * 可直接拷贝本函数到小游戏中使用 22 | */ 23 | export default function anonymous(it) { 24 | var out = ' '; 25 | return out; 26 | } 27 | -------------------------------------------------------------------------------- /miniprogram/test.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-demo/de1c8edf16cf8bf3d9432f83e1f0d397598e70a3/miniprogram/test.zip -------------------------------------------------------------------------------- /miniprogram/workers/index.js: -------------------------------------------------------------------------------- 1 | worker.onMessage(res=>{ 2 | function fabonacci(n) { 3 | return n < 2 ? n : fabonacci(n - 1) + fabonacci(n - 2); 4 | } 5 | worker.postMessage({ 6 | msg: fabonacci(res.msg) 7 | }) 8 | }) -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "scripts": { 3 | "build": "tsc", 4 | "watch": "tsc -w", 5 | "lint": "eslint \"**/*.ts\" --fix" 6 | }, 7 | "devDependencies": { 8 | "@typescript-eslint/eslint-plugin": "^7.4.0", 9 | "@typescript-eslint/parser": "^7.4.0", 10 | "eslint": "^8.57.0", 11 | "eslint-config-prettier": "^9.1.0", 12 | "eslint-plugin-prettier": "^5.1.3", 13 | "minigame-api-typings": "^3.8.4", 14 | "prettier": "^3.2.5", 15 | "typescript": "^5.4.2" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /project.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "项目配置文件。", 3 | "setting": { 4 | "urlCheck": false, 5 | "es6": true, 6 | "enhance": false, 7 | "postcss": true, 8 | "preloadBackgroundData": false, 9 | "minified": false, 10 | "newFeature": true, 11 | "coverView": true, 12 | "nodeModules": false, 13 | "autoAudits": false, 14 | "showShadowRootInWxmlPanel": false, 15 | "scopeDataCheck": false, 16 | "uglifyFileName": false, 17 | "checkInvalidKey": true, 18 | "checkSiteMap": true, 19 | "uploadWithSourceMap": true, 20 | "compileHotReLoad": false, 21 | "lazyloadPlaceholderEnable": false, 22 | "useMultiFrameRuntime": true, 23 | "useApiHook": true, 24 | "useApiHostProcess": true, 25 | "babelSetting": { 26 | "ignore": [], 27 | "disablePlugins": [], 28 | "outputPath": "" 29 | }, 30 | "enableEngineNative": false, 31 | "useIsolateContext": true, 32 | "userConfirmedBundleSwitch": true, 33 | "packNpmManually": false, 34 | "packNpmRelationList": [], 35 | "minifyWXSS": true, 36 | "disableUseStrict": false, 37 | "showES6CompileOption": false, 38 | "useCompilerPlugins": false 39 | }, 40 | "compileType": "game", 41 | "libVersion": "2.21.0", 42 | "appid": "wx20afc706a711eefc", 43 | "projectname": "miniGameExample", 44 | "miniprogramRoot": "miniprogram/", 45 | "cloudfunctionRoot": "cloudfunction/", 46 | "simulatorType": "wechat", 47 | "simulatorPluginLibVersion": {}, 48 | "cloudfunctionTemplateRoot": "cloudfunctionTemplate/", 49 | "jsserverRoot": "jsserver/", 50 | "condition": {}, 51 | "srcMiniprogramRoot": "miniprogram/", 52 | "packOptions": { 53 | "ignore": [], 54 | "include": [] 55 | }, 56 | "editorSetting": { 57 | "tabIndent": "insertSpaces", 58 | "tabSize": 2 59 | } 60 | } -------------------------------------------------------------------------------- /readmeImages/15656998217946.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-demo/de1c8edf16cf8bf3d9432f83e1f0d397598e70a3/readmeImages/15656998217946.png -------------------------------------------------------------------------------- /readmeImages/1565703421184.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-demo/de1c8edf16cf8bf3d9432f83e1f0d397598e70a3/readmeImages/1565703421184.png -------------------------------------------------------------------------------- /readmeImages/15657051222936.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-demo/de1c8edf16cf8bf3d9432f83e1f0d397598e70a3/readmeImages/15657051222936.png -------------------------------------------------------------------------------- /readmeImages/15657051644791.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-demo/de1c8edf16cf8bf3d9432f83e1f0d397598e70a3/readmeImages/15657051644791.png -------------------------------------------------------------------------------- /readmeImages/15657830373446.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-demo/de1c8edf16cf8bf3d9432f83e1f0d397598e70a3/readmeImages/15657830373446.png -------------------------------------------------------------------------------- /readmeImages/15657831706742.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-demo/de1c8edf16cf8bf3d9432f83e1f0d397598e70a3/readmeImages/15657831706742.png -------------------------------------------------------------------------------- /readmeImages/15657834069152.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-demo/de1c8edf16cf8bf3d9432f83e1f0d397598e70a3/readmeImages/15657834069152.png -------------------------------------------------------------------------------- /readmeImages/15657835833394.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-demo/de1c8edf16cf8bf3d9432f83e1f0d397598e70a3/readmeImages/15657835833394.png -------------------------------------------------------------------------------- /readmeImages/15657837079883.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-demo/de1c8edf16cf8bf3d9432f83e1f0d397598e70a3/readmeImages/15657837079883.png -------------------------------------------------------------------------------- /readmeImages/15657839753823.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-demo/de1c8edf16cf8bf3d9432f83e1f0d397598e70a3/readmeImages/15657839753823.png -------------------------------------------------------------------------------- /readmeImages/15657842591339.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-demo/de1c8edf16cf8bf3d9432f83e1f0d397598e70a3/readmeImages/15657842591339.png -------------------------------------------------------------------------------- /readmeImages/QR code.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-demo/de1c8edf16cf8bf3d9432f83e1f0d397598e70a3/readmeImages/QR code.jpg -------------------------------------------------------------------------------- /readmeImages/samplePlate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechat-miniprogram/minigame-demo/de1c8edf16cf8bf3d9432f83e1f0d397598e70a3/readmeImages/samplePlate.png -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "esnext", // 目标 ECMAScript 版本 4 | "module": "esnext", // 使用 CommonJS 模块 5 | "allowJs": false, // 允许编译 JavaScript 文件(方便逐步迁移) 6 | "checkJs": false, // 设置为 true 可检查并报告纯 JavaScript 文件中的错误 7 | "declaration": false, // 生成 ".d.ts" 声明文件 8 | "sourceMap": false, // 生成源映射以便调试 9 | "strict": true, // 启用所有严格类型检查选项 10 | "esModuleInterop": true, // 启用 ES6 模块与 CommonJS 模块的交互 11 | "moduleResolution": "node", 12 | "forceConsistentCasingInFileNames": true, // 禁止对同一文件使用不同的大小写引用 13 | "typeRoots": ["./node_modules/@types", "./node_modules/minigame-api-typings/types"], 14 | "skipLibCheck": true, 15 | "noImplicitAny": false 16 | }, 17 | "include": ["miniprogram"], 18 | "exclude": ["*.js"] 19 | } --------------------------------------------------------------------------------