Commit 68be8798 authored by wildfirecode's avatar wildfirecode

1

parent 29979edb
page {
background: #f7f7f7;
flex: 1;
display: flex;
}
import cloud from '@tbmp/mp-cloud-sdk';
cloud.init({
env: 'test'//'online' test
});
App({
cloud,
cloudName: "aaaa",//待修改
onLaunch(options) {
// 第一次打开
// options.query == {number:1}///"enableSkia": "true"
console.info('App onLaunch');
const { activityId } = options.query || {};
console.log(activityId)
this.activityId = activityId || '5ec5f960f5d6906095de717e';
},
onShow(options) {
// 从后台被 scheme 重新打开
// options.query == {number:1}
},
});
{
"pages": [
"pages/index/index",
"pages/index2/index2"
],
"window": {
"navigationBarForceEnable": true,
"defaultTitle": "My App",
"gpuAccelerate": "true",
"enableSkia": "true"
}
}
\ No newline at end of file
declare namespace SvgaPlayer{
export enum Event {
/**
* 每帧的监听
*/
ENTER_FRAME = "onEnterFrame",
/**
* 最后一帧的监听
*/
END_FRAME = "onEndFrame"
}
export class EventDispatcher {
protected eventTypes: any;
constructor();
addEventListener(type: string, listener: Function, context?: any): this;
/**
* 监听一次
* @param type
* @param listener
* @param context
* @param useCapture
*/
once(type: string, listener: Function, context?: any): this;
dispatchEvent(event: string, data?: any): boolean;
/**
* 移除对应类型的侦听
* @method removeEventListener
* @public
* @since 1.0.0
* @param {string} type 要移除的侦听类型
* @param {Function} listener 及侦听时绑定的回调方法
* @param context listener和context都相等的才移除,默认自身
*/
removeEventListener(type: string, listener: Function, context?: any): this;
/**
* 移除对象中所有的侦听
* @method removeAllEventListener
* @public
* @since 1.0.0
*/
removeAllEventListener(): void;
hasEventListener(type: string): boolean;
destroy(): void;
}
export class MovieClip extends EventDispatcher {
private transform;
private dirty;
x: number;
y: number;
scaleX: number;
scaleY: number;
/**
* 角度制
*/
rotation: number;
anchorX: number;
anchorY: number;
/**
* 锁步将按时间间隔来执行动画
*/
lockStep: boolean;
/**
* mc的当前帧,从1开始
* @property currentFrame
* @public
* @since 1.0.0
* @type {number}
* @default 1
* @readonly
*/
readonly currentFrame: number;
/**
* @property _curFrame
* @type {number}
* @private
* @since 2.0.0
* @default 1
*/
private _curFrame;
/**
* 当前动画是否处于播放状态
* @property isPlaying
* @readOnly
* @public
* @since 1.0.0
* @type {boolean}
* @default true
* @readonly
*/
readonly isPlaying: boolean;
/**
* @property _isPlaying
* @type {boolean}
* @private
* @since 2.0.0
* @default true
*/
private _isPlaying;
/**
* 动画的播放方向,是顺着播还是在倒着播
* @property isFront
* @public
* @since 1.0.0
* @type {boolean}
* @default true
* @readonly
*/
readonly isFront: boolean;
/**
* @property _isFront
* @type {boolean}
* @private
* @default true
*/
private _isFront;
/**
* 当前动画的总帧数
* @property totalFrames
* @public
* @since 1.0.0
* @type {number}
* @default 1
* @readonly
*/
readonly totalFrames: number;
readonly videoWidth: number;
readonly videoHeight: number;
/**
* 锁步的时间间隔,按fps定,毫秒
*/
private timeInterval;
/**
* 前提引擎按60设置
*/
private deltaFrame;
/**
* 中间帧计时
*/
private frameCount;
/**
* 动画数据
*/
videoItem: SvgaParser.VideoEntity;
/**
* 构造函数
* @method MovieClip
* @public
* @param mv VideoEntity格式,这里不给了
*/
constructor(mv: SvgaParser.VideoEntity);
/**
* 可以手动用init,
* @param mv
*/
init(mv: SvgaParser.VideoEntity): void;
/**
* 调用止方法将停止当前帧
* @method stop
* @public
* @since 1.0.0
*/
stop(): void;
/**
* 将播放头向后移一帧并停在下一帧,如果本身在最后一帧则不做任何反应
* @method nextFrame
* @since 1.0.0
* @public
*/
nextFrame(): void;
/**
* 将播放头向前移一帧并停在下一帧,如果本身在第一帧则不做任何反应
* @method prevFrame
* @since 1.0.0
* @public
*/
prevFrame(): void;
/**
* 将播放头跳转到指定帧并停在那一帧,如果本身在第一帧则不做任何反应
* @method gotoAndStop
* @public
* @since 1.0.0
* @param {number} frameIndex 批定帧的帧数或指定帧的标签名
*/
gotoAndStop(frameIndex: number): void;
/**
* 如果当前时间轴停在某一帧,调用此方法将继续播放.
* @method play
* @public
* @since 1.0.0
*/
play(isFront?: boolean): void;
/**
* @property _lastFrame
* @type {number}
* @private
* @default 0
*/
private _lastFrame;
/**
* 刚执行到的帧数,用于帧监听时判断用,刚好执行到当前帧,而不是之前保留的状态
* 不是60fps的videoItem的中间有几帧curFrame会不变,判断只执行一次监听时会出错,刚好动画满帧60fps时就无所谓
*/
readonly isInTimeFrame: boolean;
/**
* 将播放头跳转到指定帧并从那一帧开始继续播放
* @method gotoAndPlay
* @public
* @since 1.0.0
* @param {number} frameIndex 批定帧的帧数或指定帧的标签名
* @param {boolean} isFront 跳到指定帧后是向前播放, 还是向后播放.不设置些参数将默认向前播放
*/
gotoAndPlay(frameIndex: number, isFront?: boolean): void;
/**
* 记录的startAniRange对应的fun
*/
private startAniRangeFun;
/**
* 优先级最高,会覆盖
* @param beginFrame 默认1
* @param endFrame 默认 this.totalFrames
* @param loops 默认1 0
*/
startAniRange(beginFrame?: number, endFrame?: number, loops?: number, callback?: Function): void;
/**
* 开始时间,每次有play的时候就需要重置now
* 锁步思想,设置开始时间,后面每帧实际时间与开始时间相减,得到当前帧数
*
*/
private startTime;
/**
* 开始时的frame
*/
private startFrame;
/**
* 与startFrame相间隔的帧数量,绝对值
*/
private lastDeltaFrame;
/**
* 锁步时的每次end的标识
*/
private _endMark;
commonDeltaTime: number;
updateFrame(): void;
private getCurFrameWhenLockStep;
/**
* 修改自身位置
*/
updateTransform(): void;
destroy(): void;
}
export const _bitmapCache: {};
export class SvgaStage extends EventDispatcher {
/**
* 用于 requestAnimationFrame,cancelAnimationFrame ,createImage
*/
private canvas;
private context;
private children;
resolution: number;
/**
*
* @param canvas 渲染的canvas
* @param resolution canvas和显示对象的尺寸比例
*/
constructor(canvas: any, resolution?: number);
addChild(mv: MovieClip): MovieClip;
addChildAt(mv: MovieClip, index?: number): MovieClip;
removeChild(mv: MovieClip): MovieClip;
removeChildAt(index: number): any;
removeAllChildren(): MovieClip[];
/**
* 将所有MovieClip画到canvas上
*/
render(): void;
private drawSprite;
flush(): void;
}
export const loadSvga: typeof SvgaParser.loadSvga;}
declare module "svga-player" {export = SvgaPlayer;}
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
# SvgaParser
1.0.2版本支持web版本解析,包体小,web应用尽量用这个
1.1.0及以后版本同时支持web和微信小程序及淘宝小程序解析
(淘宝小程序使用,链接必须使用阿里系的白名单域名,或者云存储cloud://链接)
其他版本都是坏的
单纯将svga文件解析成动画图片及动画数据。
### 网页使用
```html
<script type="text/javascript" src="../build/svgaParser.min.js"></script>
<script>
SvgaParser.loadSvga("./svga/step1-1.svga", (v) => {
console.log(v)
}, (err) => { console.log(err) })
</script>
```
### npm使用
```js
npm install svga-parser
import { loadSvga } from "svga-parser";
loadSvga("./svga/step1-1.svga", (v) => {
console.log(v)
}, (err) => { console.log(err) })
```
declare module SvgaParser {
/**
* 加载方法
* @param url 资源路径
* @param success
* @param failure
*/
export function loadSvga(url: string, success: (videoItem: VideoEntity) => void, failure: (err: string) => void): void;
/**
* 导出只是当作类型接口用
*/
export interface VideoEntity {
/**
* SVGA 文件版本
*/
version: string;
/**
* 影片尺寸
*/
videoSize: {
width: number;
height: number;
};
/**
* 帧率,60,30等每秒
*/
FPS: number;
/**
* 总帧数
*/
frames: number;
/**
* base64图片数据记录
*/
images: {
[key: string]: string
};
/**
* 图片是否已被缓存,缓存全局,注意名字覆盖
*/
hasBeenCached: boolean;
/**
* sprite对象数据
*/
sprites: SpriteEntity[];
}
interface SpriteEntity {
/**
* 标识
*/
matteKey: string;
/**
* 图片key值
*/
imageKey: string;
/**
* 帧数据数组
*/
frames: FrameEntity[];
}
/**
* 还有很多其他数据,暂不需要,比如矢量路径和遮罩路径暂时都无
*/
interface FrameEntity {
/**
* 透明度
*/
alpha: number;
/**
* 2维矩阵数据
*/
transform: {
a: number,
b: number,
c: number,
d: number,
tx: number,
ty: number,
};
}
}
declare module "svga-parser" { export = SvgaParser; }
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
{
"_from": "svga-parser@^1.1.0",
"_id": "svga-parser@1.1.0",
"_inBundle": false,
"_integrity": "sha512-OjjtzPGC1ZdCWSWvldhXcB0CAz4ZOeoWEp0P9l4Lz7UtLM9f+DAYAYXKCXBWnRZvJevgkY/gniO/Bt89X0cKKw==",
"_location": "/@mrkwon/svga-player/svga-parser",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "svga-parser@^1.1.0",
"name": "svga-parser",
"escapedName": "svga-parser",
"rawSpec": "^1.1.0",
"saveSpec": null,
"fetchSpec": "^1.1.0"
},
"_requiredBy": [
"/@mrkwon/svga-player"
],
"_resolved": "https://registry.npmjs.org/svga-parser/-/svga-parser-1.1.0.tgz",
"_shasum": "b17815ac0c1a0e01a86c91bb97f834dad60275e9",
"_spec": "svga-parser@^1.1.0",
"_where": "D:\\duibaGame\\测试项目0527\\taobaominiTest\\client\\node_modules\\@mrkwon\\svga-player",
"author": {
"name": "MrKwon"
},
"bundleDependencies": false,
"dependencies": {},
"deprecated": false,
"description": "1.0.2版本支持web版本解析,包体小,web应用尽量用这个",
"devDependencies": {
"eval5": "^1.4.5",
"protobufjs": "^6.8.0",
"ts-loader": "^4.0.0",
"typescript": "^2.7.2",
"uglifyjs-webpack-plugin": "^2.1.2",
"webpack": "^4.1.0",
"webpack-cli": "^3.3.2"
},
"keywords": [
"svga"
],
"license": "ISC",
"main": "build/svgaParser.min.js",
"name": "svga-parser",
"scripts": {
"build": "webpack",
"dev": "webpack -w",
"test": "echo \"Error: no test specified\" && exit 1",
"watch": "webpack --watch"
},
"types": "build/SvgaParser.d.ts",
"version": "1.1.0"
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<meta name="viewport" content="width=device-width,initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="full-screen" content="true" />
<meta name="screen-orientation" content="portrait" />
<meta name="x5-fullscreen" content="true" />
<meta name="360-fullscreen" content="true" />
<!-- <meta name="viewport" content="width=device-width,minimum-scale=1.0,user-scalable=no"> -->
<style>
html,
body {
padding: 0;
margin: 0;
border: 0;
width: 100%;
height: 100%;
overflow: hidden;
position: absolute;
background-color: white;
}
/* .top {
width: 100%;
height: 100px;
} */
</style>
</head>
<body>
<script type="text/javascript" src="../build/svgaParser.min.js"></script>
<script>
SvgaParser.loadSvga("./svga/step1-1.svga", (v) => {
console.log(v)
}, (err) => { console.log(err) })
</script>
</body>
</html>
\ No newline at end of file
{
"_from": "@mrkwon/svga-player",
"_id": "@mrkwon/svga-player@1.0.0",
"_inBundle": false,
"_integrity": "sha512-CpeV+rP/Xa91CzHEv9WEyu+lXiyWOhLyas8OHYVE0BMGxpzsd39VCOZpXFMHfrw9324VrTvBdXmZnUfbmhYHLQ==",
"_location": "/@mrkwon/svga-player",
"_phantomChildren": {},
"_requested": {
"type": "tag",
"registry": true,
"raw": "@mrkwon/svga-player",
"name": "@mrkwon/svga-player",
"escapedName": "@mrkwon%2fsvga-player",
"scope": "@mrkwon",
"rawSpec": "",
"saveSpec": null,
"fetchSpec": "latest"
},
"_requiredBy": [
"#USER",
"/"
],
"_resolved": "https://registry.npmjs.org/@mrkwon/svga-player/-/svga-player-1.0.0.tgz",
"_shasum": "19cd96b3119893ad3af1b83bb0f32e682f97aa30",
"_spec": "@mrkwon/svga-player",
"_where": "D:\\duibaGame\\测试项目0527\\taobaominiTest\\client",
"author": {
"name": "MrKwon"
},
"bundleDependencies": false,
"dependencies": {
"svga-parser": "^1.1.0"
},
"deprecated": false,
"description": "",
"devDependencies": {
"ts-loader": "^4.0.0",
"typescript": "^2.7.2",
"uglifyjs-webpack-plugin": "^2.1.2",
"webpack": "^4.1.0",
"webpack-cli": "^3.3.2"
},
"keywords": [
"svga",
"player",
"canvas"
],
"license": "ISC",
"main": "build/svgaPlayer.min.js",
"name": "@mrkwon/svga-player",
"scripts": {
"build": "webpack",
"declare": "node scripts/declare.js src/index.ts",
"dev": "webpack -w",
"test": "echo \"Error: no test specified\" && exit 1",
"watch": "webpack --watch"
},
"types": "build/SvgaPlayer.d.ts",
"version": "1.0.0"
}
/**
* 淘宝小程序使用
*/
import { loadSvga, SvgaStage, MovieClip } from "svga-player"
Page({
onCanvasReady() {
this.canvas = my.createCanvas({
id: 'canvas',
success: (canvas) => {
var systemInfo = my.getSystemInfoSync();
//适配尺寸
canvas.width = 750 * systemInfo.pixelRatio;
canvas.height = 500 * systemInfo.pixelRatio;
//创建一个动画容器,一个canvas
var svgaStage = new SvgaStage(canvas);
//加载动画数据
loadSvga("./angel.svga", function (videoItem) {
//实例化动画
var mv = new MovieClip(videoItem);
//添加进动画容器
svgaStage.addChild(mv)
//可设置canvas的尺寸,尽量自行适配,canva实际尺寸和canvas的style尺寸
canvas.width = mv.videoWidth;
canvas.height = mv.videoHeight;
//一些api的方法
mv.stop();
setTimeout(() => {
mv.gotoAndPlay(1, false)
}, 200)
setTimeout(() => {
mv.startAniRange(1, mv.totalFrames / 2, 2, () => {
console.log(112)
})
}, 2000)
}, function (error) {
alert(error);
})
//再加一个
loadSvga("./step1-1.svga", function (videoItem) {
var mv = new MovieClip(videoItem);
svgaStage.addChild(mv)
}, function (error) {
alert(error);
})
}
});
}
})
\ No newline at end of file
<html>
<body style="text-align: center">
<div>
<!-- <div id="testCanvas" style="background-color: #000000; width: 500px; height: 500px; margin: auto"></div> -->
<canvas id="testCanvas" width="500" height="500" style="background-color: #000000; "></canvas>
</div>
<script src="../build/svgaPlayer.min.js"></script>
<script>
window.onload = function () {
var canvas = document.getElementById("testCanvas");
//创建一个动画容器,一个canvas
var svgaStage = new SvgaPlayer.SvgaStage(canvas)
//加载动画数据
SvgaPlayer.loadSvga("./angel.svga", function (videoItem) {
//实例化动画
var mv = new SvgaPlayer.MovieClip(videoItem);
//添加进动画容器
svgaStage.addChild(mv)
//可设置canvas的尺寸,尽量自行适配,canva实际尺寸和canvas的style尺寸
canvas.width = mv.videoWidth;
canvas.height = mv.videoHeight;
//一些api的方法
mv.stop();
setTimeout(() => {
mv.gotoAndPlay(1, false)
}, 200)
setTimeout(() => {
mv.startAniRange(1, mv.totalFrames / 2, 2, () => {
console.log(112)
})
}, 2000)
// mv.rotation = 45
// mv.x= 100
// mv.scaleX=1.5
// mv.y= 200
mv.anchorX= 750/2;
mv.anchorY= 750/2;
setInterval(()=>{
mv.rotation+=1
},16.7)
}, function (error) {
alert(error.message);
})
//再加一个
SvgaPlayer.loadSvga("./step1-1.svga", function (videoItem) {
var mv = new SvgaPlayer.MovieClip(videoItem);
svgaStage.addChild(mv)
}, function (error) {
alert(error);
})
}
</script>
</body>
</html>
\ No newline at end of file
# lottie
lottie 动画库适配小程序的版本。
> lottie 的相关介绍与动画生成方法等请参考 [官方说明](https://github.com/airbnb/lottie-web)
> 依赖手淘版本 >= 9.7.0 的环境
## 使用
可参考该[代码片段](https://gw.alicdn.com/bao/uploaded/TB1In6gDxD1gK0jSZFsXXbldVXa.zip?spm=a1z3i.a4.0.0.cf98eb1dV4rJNg&file=TB1In6gDxD1gK0jSZFsXXbldVXa.zip),大致步骤如下:<br />
1. 通过 npm 安装:
```
npm install --save @tbminiapp/lottie-miniapp
```
2. 传入 canvas 对象用于适配
```
<canvas id="canvas" width="610" height="610" class="canvas" type="webgl" />
```
```javascript
import lottie from "@tbminiapp/lottie-miniapp";
import animationData from "../../json/catrim";
Page({
onReady() {},
init() {
this.canvas = my._createCanvas({
id: "canvas",
success: (canvas) => {
this.canvas = canvas;
console.log("canvas=====", canvas);
lottie.setup(canvas);
this.ani = lottie.loadAnimation({
loop: true,
autoplay: true,
// path:'https://gw.alipayobjects.com/os/lottie-asset/coupon-tip/data.json/data-80154.json',
animationData,
rendererSettings: {
context: canvas.getContext("2d"),
},
});
},
});
},
play() {
this.ani.play();
},
pause() {
this.ani.pause();
},
});
```
3. 使用 lottie 接口
```
lottie.setup(canvas)
lottie.loadAnimation({
...
})
```
## 接口
目前提供两个接口:<br />**lottie.setup(canvas)**<br />需要在任何 lottie 接口调用之前调用,传入 canvas 对象<br />**lottie.loadAnimation(options)**<br />与原来的 [loadAnimation](https://github.com/airbnb/lottie-web/wiki/loadAnimation-options) 有些不同,支持的参数有:
- loop
- autoplay
- animationData
- path (只支持网络地址)
- rendererSettings.context (必填)
## 说明
- 本项目是以 npm 的方式依赖原 lottie-web 项目,若原项目有新版本,可直接改变依赖的版本号。
- 本项目依赖手淘  9.7.0 里性能更好的 canvas 实现,由于还有些小问题没有正式开放,但目前用在此处暂无发现问题。
- 由于小程序本身不支持动态执行脚本,因此 lottie 的 expression 功能也是不支持的。
This source diff could not be displayed because it is too large. You can view the blob instead.
{
"_from": "@tbminiapp/lottie-miniapp",
"_id": "@tbminiapp/lottie-miniapp@0.0.3",
"_inBundle": false,
"_integrity": "sha512-fwkXfLviTdf1aSFp4q1drNRcPv4lx9FBGZ4Gy5qclhBfut146GhLDFERIPOmUWOhwtTfyTCbazYKzMBL4aiGWw==",
"_location": "/@tbminiapp/lottie-miniapp",
"_phantomChildren": {},
"_requested": {
"type": "tag",
"registry": true,
"raw": "@tbminiapp/lottie-miniapp",
"name": "@tbminiapp/lottie-miniapp",
"escapedName": "@tbminiapp%2flottie-miniapp",
"scope": "@tbminiapp",
"rawSpec": "",
"saveSpec": null,
"fetchSpec": "latest"
},
"_requiredBy": [
"#USER",
"/"
],
"_resolved": "https://registry.npmjs.org/@tbminiapp/lottie-miniapp/-/lottie-miniapp-0.0.3.tgz",
"_shasum": "9a569ac8fa71c566bed80846dcd9d1192b33f6fb",
"_spec": "@tbminiapp/lottie-miniapp",
"_where": "D:\\淘宝小程序\\浏览器开发兼容\\client",
"bundleDependencies": false,
"deprecated": false,
"description": "lottie for miniprogram",
"devDependencies": {
"@babel/core": "^7.5.5",
"@babel/plugin-proposal-class-properties": "^7.5.5",
"@babel/preset-env": "^7.5.5",
"babel-eslint": "^10.0.2",
"babel-loader": "^8.0.6",
"eslint": "^6.1.0",
"eslint-loader": "^2.2.1",
"lottie-web": "5.5.7",
"string-replace-loader": "^2.2.0",
"webpack": "^4.39.1",
"webpack-cli": "^3.3.6"
},
"files": [
"miniprogram_dist"
],
"keywords": [
"lottie",
"miniprogram"
],
"license": "MIT",
"main": "miniprogram_dist/index.js",
"miniprogram": "miniprogram_dist",
"name": "@tbminiapp/lottie-miniapp",
"scripts": {
"build": "webpack --mode=production",
"dev": "webpack --mode=development",
"lint": "eslint \"src/**/*.js\""
},
"version": "0.0.3"
}
This diff is collapsed.
{
"_from": "@tbmp/mp-cloud-sdk@*",
"_id": "@tbmp/mp-cloud-sdk@1.3.8",
"_inBundle": false,
"_integrity": "sha512-oEO3/scR66LhUwEdrm9JABi2DIUgbblVc4TyiA2PkLd1TY+nj2o7zKY80qZxnsRqMiFvOjBidp4ANlt3I16+/A==",
"_location": "/@tbmp/mp-cloud-sdk",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "@tbmp/mp-cloud-sdk@*",
"name": "@tbmp/mp-cloud-sdk",
"escapedName": "@tbmp%2fmp-cloud-sdk",
"scope": "@tbmp",
"rawSpec": "*",
"saveSpec": null,
"fetchSpec": "*"
},
"_requiredBy": [
"#USER",
"/"
],
"_resolved": "https://registry.npmjs.org/@tbmp/mp-cloud-sdk/-/mp-cloud-sdk-1.3.8.tgz",
"_shasum": "f4aecf78ba5cf7d37690d26adec45fcbdaa1785d",
"_spec": "@tbmp/mp-cloud-sdk@*",
"_where": "D:\\duibaGame\\测试项目0527\\taobaominiTest\\client",
"author": "",
"bundleDependencies": false,
"deprecated": false,
"description": "",
"gitHead": "e3a5de54cabae149d2d58ead97f8c68d56b59f55",
"license": "ISC",
"main": "index.js",
"name": "@tbmp/mp-cloud-sdk",
"publishConfig": {
"access": "public"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"types": "./types/platforms/mp/index.d.ts",
"version": "1.3.8"
}
import { Db } from "./db";
export interface IFindOptions {
/**
* 查询的文档数量限制
*/
limit?: number;
/**
* 跳过的文档数量
*/
skip?: number;
/**
* 排序规则
*/
sort?: object;
/**
* 查询后过滤的字段
*/
projection?: object;
}
export declare class CollectionReference {
/**
* 初始化
*
* @internal
*
* @param db - 数据库的引用
* @param coll - 集合名称
*/
private _db;
private _coll;
constructor(db: Db, coll: string);
/**
* 读取集合名字
*/
readonly name: string;
/**
* 对集合执行聚合查询
* @param pipeline 聚合查询对象
*/
aggregate(pipeline: object | object[]): Promise<any>;
/**
* 获取集合中复合条件的记录数量
* @param filter 过滤条件
*/
count(filter: object): Promise<any>;
/**
* 删除集合中的一批记录
* @param filter 过滤条件
*/
deleteMany(filter: object): Promise<any>;
/**
* 查找集合中符合条件的所有记录
* @param filter 过滤条件
* @param options 查询配置项
*/
find(filter: any, options?: IFindOptions): Promise<any>;
/**
* 替换一条数据
* @param filter 过滤条件
* @param data 新数据
*/
replaceOne(filter: object, data: object): Promise<any>;
/**
* 在集合中添加一条记录
* @param data 带插入的数据
*/
insertOne(data: object): Promise<any>;
/**
* 在集合中添加一批记录
* @param data 待插入的数据,只能为数组
*/
insertMany(data: object[]): Promise<any>;
/**
*
* @param filter 过滤条件
* @param data 更新规则
*
*/
updateMany(filter: object, data: object): Promise<any>;
}
import { CollectionReference } from "./collection";
import { IAsyncInvokeOptions } from "../../shared/types";
import { ICloudService } from "../interface/cloudService";
export declare class Db extends ICloudService {
/**
* 获取集合的引用
*
* @param collName - 集合名称
*/
collection(collName: string): CollectionReference;
/**
* 创建集合
*/
createCollection(name: string, options: {
collName: string;
} & IAsyncInvokeOptions): Promise<any>;
dbRequest(action?: string, params?: any): Promise<any>;
}
import { Db } from "./db";
export default Db;
import { IAsyncInvokeOptions } from '../../shared/types';
import { ICloudService } from '../interface/cloudService';
export interface ICallFunctionOptions extends IAsyncInvokeOptions {
name: string;
data: any;
}
export interface IInvokeMethod {
(IAsyncInvokeOptions: any): void;
}
export default class CloudFunction extends ICloudService {
invoke(name: string, data?: object, handler?: string): Promise<any>;
private fcRequest;
}
import { Request } from "../../shared/request";
export interface ICloudServiceOptions {
env?: 'test' | 'online' | 'pre';
}
export declare abstract class ICloudService {
options: ICloudServiceOptions;
request: Request;
constructor(options: ICloudServiceOptions, request: Request);
init?(): void;
}
import Powermsg from '@ali/lib-powermsg-sdk';
import { Env } from '../../shared/types';
export default class Client {
env: Env;
pmg: Powermsg;
deviceId: string;
initing: boolean;
queue: (() => void)[];
config: any;
constructor(env: Env);
init: () => Promise<any>;
onMessage: (callback: any) => Promise<() => void>;
private createPwgInstance;
}
import { ICloudService, ICloudServiceOptions } from "../interface/cloudService";
import Client from './client';
import Server from './server';
export default class Message extends ICloudService {
server: Server;
client: Client;
constructor(options: ICloudServiceOptions);
}
import { Request } from '../../shared/request';
import { Env } from "../../../packages/mp-cloud-node-sdk/types/shared/types";
interface IPushOptions {
subType: number;
deviceId?: string;
data: object;
pushType: string;
}
export default class Server {
env: Env;
request: Request;
constructor(env: Env, request: Request);
push(options: IPushOptions): Promise<any>;
}
export {};
import {ICloudService} from "../../interface/cloudService";
export default class Application extends ICloudService {
httpRequest(options: {path: string, params?: any, body?: any, headers?: any, method?: string, exts?: any}): Promise<any>;
}
import {ICloudService} from "../../interface/cloudService";
export default class Process extends ICloudService {
invoke(options: { api: string, data?: any, headers?: any }): Promise<any>;
private topRequest;
}
import {ICloudService} from "../../interface/cloudService";
export default class Qimen extends ICloudService {
invoke(options: { api: string, data?: any, targetAppKey?: any, headers?: any }): Promise<any>;
private topRequest;
}
import {ICloudService} from "../../interface/cloudService";
export default class Top extends ICloudService {
invoke(options: { api: string, data?: any, headers?: any, authScope?: string }): Promise<any>;
private topRequest;
}
import { IRequestOptions } from "../../../shared/request";
export default class Top {
client: any;
context: IRequestOptions;
constructor(context: IRequestOptions);
invoke(apiName: string, data?: any, httpHeaders?: any): Promise<any>;
}
import { IAsyncInvokeOptions } from "../../shared/types";
import { ICloudService } from "../interface/cloudService";
export interface IUploadFileOptions extends IAsyncInvokeOptions {
/**
* 选择到的本地文件路径
*/
filePath: string;
/**
* 文件类型, image/audio/video
*/
fileType: FileTypes;
/**
* 云存储文件名可带路径, 如a/xxx.jpg
*/
fileName?: string;
/**
* web环境上传 file对象
*/
file?: any;
}
export interface IDownloadFileOptions extends IAsyncInvokeOptions {
fileType?: FileTypes;
fileId: string;
}
export interface ITempFileURLOptions extends IAsyncInvokeOptions {
fileList: string[];
}
export declare type IDeleteFileOptions = IDownloadFileOptions;
export declare type FileTypes = "image" | "video" | "audio";
export default class CloudStorage extends ICloudService {
private parseUploadResult;
private parsePostUploadResult;
private parseAusUploadResult;
/**
* 文件上传
* 1.获取上传配置
* 2.调用my.api上传
* 3.建立存储关系
* @param options
*/
uploadFile(options: IUploadFileOptions): Promise<any>;
/**
* 删除文件
* @param options
*/
deleteFile(options: IDeleteFileOptions): Promise<boolean>;
/**
* 根据文件id(cloud://)获取授权的url
* @param options
*/
getTempFileURL(options: IAsyncInvokeOptions & {
fileType: string;
fileId: string | string[];
}): Promise<any>;
/**
* 从服务端获取文件并在本地读取
* @param options
*/
readRemoteFile(options: IAsyncInvokeOptions & {
url: string;
}): Promise<ArrayBuffer>;
/**
* 存储的请求代理, 统一sdk环境和存储环境
* @param action
* @param data
* @param requestType
*/
private storageRequest;
}
import { Cloud } from '../mp';
declare const cloudInstance: Cloud;
export default cloudInstance;
import { Cloud as MpCloud } from '../mp';
import { ICloudOptions } from '../../shared/types';
import Client from '../../core/message/client';
import { IProxy } from '../../shared/request';
export declare class Cloud extends MpCloud {
message: {
client: Client;
};
init(options: ICloudOptions, proxy: IProxy): Promise<boolean>;
}
declare const _default: Cloud;
export default _default;
import {IProxy} from '../../shared/request';
import {ICloudOptions} from '../../shared/types';
import CloudFunction from '../../core/functions';
import CloudStorage from '../../core/storage';
import Db from '../../core/db';
import Top from '../../core/openApi/client/top';
import Qimen from '../../core/openApi/client/qimen';
import Process from '../../core/openApi/client/process';
import Application from '../../core/openApi/client/application';
export declare class Cloud {
function: CloudFunction;
file: CloudStorage;
db: Db;
topApi: Top;
qimenApi: Qimen;
processApi: Process;
application: Application;
init(options: ICloudOptions, proxy?: IProxy): Promise<boolean>;
}
declare const _default: Cloud;
export default _default;
import { IProxy, IRequestOptions } from '../../shared/request';
import { ICloudOptions } from '../../shared/types';
import CloudFunction from '../../core/functions';
import Database from '../../core/db';
import Server from '../../core/message/server';
import Top from '../../core/openApi/server/top';
export declare class Cloud {
private _options;
db: Database;
function: CloudFunction;
message: {
server: Server;
};
private request;
topApi: Top;
setEnv(env: any): void;
init(options: ICloudOptions & IRequestOptions, proxy: IProxy): void;
}
export declare function cloud(context: any, options: ICloudOptions): Cloud;
export declare const BASE_APIS: {
GET_SESSION: string;
GET_SECRET: string;
};
export declare const STORAGE_KEYS: {
SECRET: string;
};
export declare const ENV_CONFIG: {
pre: {
gw: string;
};
online: {
gw: string;
};
};
import { IAsyncInvokeOptions } from "./types";
export declare function invokeCallback(options: IAsyncInvokeOptions, asyncTask: Promise<any>): Promise<void>;
export declare function myApiPromisify(method: (options: any) => void, options?: any): Promise<any>;
export declare function getUserId(): Promise<string>;
export declare function noop(): void;
export declare function invokeTaskCallback(): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
export declare function safeAccess(props: any, keys: string[] | string, def?: any): any;
export declare function getValue(key: string): Promise<any>;
export declare function setValue(key: string, data: any): Promise<any>;
export interface IRequestOptions {
appKey?: string,
sourceAppKey?: string,
requestAppKey?:string,
miniappId?: string,
sourceMiniAppId?: string,
appOwnerOpenId?: string,
signSecret?: string;
sessionKey?: string;
requestId?: string;
cloudId?: string;
openId?: string;
unionId?: string;
userNick?: string,
mixNick?: string,
session?: string;
accessToken?: string;
env?: string;
}
export declare enum RequestTypes {
MTOP = 1,
MY = 2,
GATEWAY = 3
}
export interface IGatewayResponse {
error_response: {
code: string;
};
}
export interface IRequestDetail {
url: string;
data?: any;
rawData?: any;
method?: string;
headers?: any;
dataType?: string;
v?: string;
__is_retry_task__?: boolean;
env?: string;
mtopOptions?: any;
}
export interface IProxyOptions {
gatewayUrl?: string;
dataProxyGatewayUrl?: string;
}
export declare abstract class IProxy {
options: IProxyOptions;
abstract apply(task: IRequestDetail, requestType?: RequestTypes): Promise<any>;
constructor(options?: IProxyOptions);
}
export declare class Request {
networkType?: string;
options: IRequestOptions;
tasks: {
detail: IRequestDetail;
success?: (res: any) => void;
fail?: (res: any) => void;
}[];
proxy: IProxy;
inited: boolean;
pauseExecTask: boolean;
init(options: IRequestOptions, proxy: IProxy): Promise<void>;
listenNetworkChange(): Promise<void>;
static getRequestType(url: string): RequestTypes;
/**
* 验证响应结果, 特定情况下重试请求
* @param res
*/
private verifyResponse;
private tryThrowError;
private sendGatewayRequest;
flushGatewayRequestQueue(reject?: boolean): void;
exec(detail: IRequestDetail, requestType?: RequestTypes): Promise<any>;
/**
*
* @param url 网关请求
* @param method 请求方法
* @param queryString
* @param headers mc_开头的http header
* @param content json body
*/
private getHttpRequestSign;
/**
* 对网关请求签名
* @param detail
*/
private createGatewayRequest;
}
export declare const request: Request;
export interface ICallback {
(res: any): void;
}
export interface IHttpRequestOptions extends IAsyncInvokeOptions {
url: string;
method?: string;
headers?: any;
data?: any;
dataType?: string;
}
export declare type Env = 'test' | 'pre' | 'online';
export declare type Envs = {
database: Env;
file: Env;
function: Env;
message: Env;
};
export interface ICloudOptions {
env?: Env | Envs;
appKey?: string;
}
declare global {
interface Window {
}
var my: {
httpRequest: (options: IHttpRequestOptions) => void;
sendMtop: (options: any) => void;
alert: (options: {
title?: string;
content?: string;
}) => void;
};
var NODE_PLATFORM: boolean;
var SDK_VERSION: string;
}
export interface IAsyncInvokeOptions {
success?: ICallback;
fail?: ICallback;
complete?: ICallback;
}
export declare type AsyncInvokeResult = Promise<any> | void;
export declare type Constructor<T = {}> = new (...args: any[]) => T;
import { IAsyncInvokeOptions, Env, Envs } from "./types";
export declare function noop(): void;
export declare function invokeTaskCallback(): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
export declare function safeAccess(props: any, keys: string[] | string, def?: any): any;
export declare function invokeCallback(options: IAsyncInvokeOptions, asyncTask: Promise<any>): Promise<void>;
export declare function myApiPromisify(method: (options: any) => void, options?: any): Promise<any>;
export declare function getUserId(): Promise<string>;
export declare function getEnvs(env: Env | Envs): Envs;
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
{
"_from": "fyge-tbmini@^1.0.7",
"_id": "fyge-tbmini@1.0.7",
"_inBundle": false,
"_integrity": "sha512-SCJZHp1YhzTiC+i0r89JSaNAfFQkeD+8LKoBEMMfK7kqht1sqsmbh90WPMVN2rgbMYig+tld9cyNWZyHgHX2cg==",
"_location": "/fyge-tbmini",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "fyge-tbmini@^1.0.7",
"name": "fyge-tbmini",
"escapedName": "fyge-tbmini",
"rawSpec": "^1.0.7",
"saveSpec": null,
"fetchSpec": "^1.0.7"
},
"_requiredBy": [
"#USER",
"/"
],
"_resolved": "https://registry.npmjs.org/fyge-tbmini/-/fyge-tbmini-1.0.7.tgz",
"_shasum": "f941978581d0a5b10caf3e9f9ef10c2ed70db88b",
"_spec": "fyge-tbmini@^1.0.7",
"_where": "D:\\duibaGame\\测试项目0527\\taobaominiTest\\client",
"author": {
"name": "MrKwon"
},
"bundleDependencies": false,
"dependencies": {},
"deprecated": false,
"description": "淘宝小程序canvas渲染引擎",
"devDependencies": {
"ts-loader": "^4.0.0",
"typescript": "^2.7.2",
"uglifyjs-webpack-plugin": "^2.1.2",
"webpack": "^4.1.0",
"webpack-cli": "^3.3.2"
},
"keywords": [
"淘宝小程序,canvas,webgl"
],
"license": "ISC",
"main": "./build/fyge.min.js",
"name": "fyge-tbmini",
"scripts": {
"build": "webpack",
"declare": "node scripts/declare.js src/index.ts",
"dev": "webpack -w",
"test": "echo \"Error: no test specified\" && exit 1",
"watch": "webpack --watch"
},
"types": "./build/FYGE.d.ts",
"version": "1.0.7"
}
1.0.2版本支持web版本解析,包体小
1.0.8版本同时支持web和微信小程序及淘宝小程序解析
\ No newline at end of file
declare module SvgaParser {
/**
* 加载方法
* @param url 资源路径
* @param success
* @param failure
*/
export function loadSvga(url: string, success: (videoItem: VideoEntity) => void, failure: (err: string) => void): void;
/**
* 导出只是当作类型接口用
*/
export interface VideoEntity {
/**
* SVGA 文件版本
*/
version: string;
/**
* 影片尺寸
*/
videoSize: {
width: number;
height: number;
};
/**
* 帧率,60,30等每秒
*/
FPS: number;
/**
* 总帧数
*/
frames: number;
/**
* base64图片数据记录
*/
images: {
[key: string]: string
};
/**
* 图片是否已被缓存,缓存全局,注意名字覆盖
*/
hasBeenCached: boolean;
/**
* sprite对象数据
*/
sprites: SpriteEntity[];
}
interface SpriteEntity {
/**
* 标识
*/
matteKey: string;
/**
* 图片key值
*/
imageKey: string;
/**
* 帧数据数组
*/
frames: FrameEntity[];
}
/**
* 还有很多其他数据,暂不需要,比如矢量路径和遮罩路径暂时都无
*/
interface FrameEntity {
/**
* 透明度
*/
alpha: number;
/**
* 2维矩阵数据
*/
transform: {
a: number,
b: number,
c: number,
d: number,
tx: number,
ty: number,
};
}
}
declare module "svga-parser" { export = SvgaParser; }
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
{
"_from": "svga-parser@^1.0.7",
"_id": "svga-parser@1.0.8",
"_inBundle": false,
"_integrity": "sha512-xEj8YdNhm11KmV9rIiKkLOrMGlhrs9qmaGO+j8tNCZ1L9omXBTqmRc3xX6SJXOjUx47cS9tVMaYrBbYKPask3g==",
"_location": "/svga-parser",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "svga-parser@^1.0.7",
"name": "svga-parser",
"escapedName": "svga-parser",
"rawSpec": "^1.0.7",
"saveSpec": null,
"fetchSpec": "^1.0.7"
},
"_requiredBy": [
"#USER",
"/"
],
"_resolved": "https://registry.npmjs.org/svga-parser/-/svga-parser-1.0.8.tgz",
"_shasum": "7c8d13b96227c91bd82c1243a0826b16e6a22194",
"_spec": "svga-parser@^1.0.7",
"_where": "D:\\淘宝小程序\\浏览器开发兼容\\client",
"author": {
"name": "MrKwon"
},
"bundleDependencies": false,
"dependencies": {},
"deprecated": false,
"description": "1.0.2版本支持web版本解析,包体小\r 1.0.8版本同时支持web和微信小程序及淘宝小程序解析",
"devDependencies": {
"eval5": "^1.4.5",
"protobufjs": "^6.8.0",
"ts-loader": "^4.0.0",
"typescript": "^2.7.2",
"uglifyjs-webpack-plugin": "^2.1.2",
"webpack": "^4.1.0",
"webpack-cli": "^3.3.2"
},
"keywords": [
"svga"
],
"license": "ISC",
"main": "build/svgaParser.min.js",
"name": "svga-parser",
"scripts": {
"build": "webpack",
"dev": "webpack -w",
"test": "echo \"Error: no test specified\" && exit 1",
"watch": "webpack --watch"
},
"types": "build/SvgaParser.d.ts",
"version": "1.0.8"
}
{
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"@mrkwon/svga-player": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/@mrkwon/svga-player/-/svga-player-1.0.0.tgz",
"integrity": "sha512-CpeV+rP/Xa91CzHEv9WEyu+lXiyWOhLyas8OHYVE0BMGxpzsd39VCOZpXFMHfrw9324VrTvBdXmZnUfbmhYHLQ==",
"requires": {
"svga-parser": "^1.1.0"
},
"dependencies": {
"svga-parser": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/svga-parser/-/svga-parser-1.1.0.tgz",
"integrity": "sha512-OjjtzPGC1ZdCWSWvldhXcB0CAz4ZOeoWEp0P9l4Lz7UtLM9f+DAYAYXKCXBWnRZvJevgkY/gniO/Bt89X0cKKw=="
}
}
},
"@tbminiapp/lottie-miniapp": {
"version": "0.0.3",
"resolved": "https://registry.npmjs.org/@tbminiapp/lottie-miniapp/-/lottie-miniapp-0.0.3.tgz",
"integrity": "sha512-fwkXfLviTdf1aSFp4q1drNRcPv4lx9FBGZ4Gy5qclhBfut146GhLDFERIPOmUWOhwtTfyTCbazYKzMBL4aiGWw=="
},
"@tbmp/mp-cloud-sdk": {
"version": "1.3.8",
"resolved": "https://registry.npmjs.org/@tbmp/mp-cloud-sdk/-/mp-cloud-sdk-1.3.8.tgz",
"integrity": "sha512-oEO3/scR66LhUwEdrm9JABi2DIUgbblVc4TyiA2PkLd1TY+nj2o7zKY80qZxnsRqMiFvOjBidp4ANlt3I16+/A=="
},
"fyge-tbmini": {
"version": "1.0.7",
"resolved": "https://registry.npmjs.org/fyge-tbmini/-/fyge-tbmini-1.0.7.tgz",
"integrity": "sha512-SCJZHp1YhzTiC+i0r89JSaNAfFQkeD+8LKoBEMMfK7kqht1sqsmbh90WPMVN2rgbMYig+tld9cyNWZyHgHX2cg=="
},
"svga-parser": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/svga-parser/-/svga-parser-1.0.8.tgz",
"integrity": "sha512-xEj8YdNhm11KmV9rIiKkLOrMGlhrs9qmaGO+j8tNCZ1L9omXBTqmRc3xX6SJXOjUx47cS9tVMaYrBbYKPask3g=="
}
}
}
{
"name": "",
"version": "1.0.0",
"main": "",
"license": "MIT",
"dependencies": {
"@mrkwon/svga-player": "^1.0.3",
"@tbminiapp/lottie-miniapp": "0.0.3",
"@tbmp/mp-cloud-sdk": "^1.3.8",
"fyge-tbmini": "^1.0.9",
"svga-parser": "^1.1.0"
}
}
.canvas {
width:100%;
height:100%;
}
.page-game {
/* position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
min-height: 100vh; */
flex: 1;
display: flex;
flex-direction: column;
}
\ No newline at end of file
<!-- <view class="page" disable-scroll="true" style="padding-top: 0px;-ms-touch-action: none; touch-action: none;background: #888888;
padding: 0;
border: 0;
margin: 0;
height: 100%;" > -->
<!-- 备用的canvas用于绘制文本,尺寸对内存影响很大 -->
<!-- <canvas
id="backupCanvas"
style="width:750;height:750;position:absolute;left:0;top:0;opacity:1;display:block"
width="750"
height="750"
disable-scroll="true"
class="canvas"
onTouchStart=""
onTouchMove=""
onTouchEnd=""
/> -->
<!-- <canvas
id="canvas"
type="webgl"
width="{{canWidth}}"
height= "{{canHeight}}"
disable-scroll="true"
class="canvas"
onTouchStart="log"
onTouchMove="log"
onTouchEnd="log"
style="width:{{divWidth}}px;height:{{divHeight}}px;position:absolute;left:0;top:0;display:block;background: #ff0000"
/> -->
<!-- <canvas
id="canva4stats"
type="webgl"
style="width:80;height:48;position:absolute;right:0;top:0;opacity:0.9;z-index:10000;display:block;"
width="80"
height="48"
class="canvas"
disable-scroll="true" /> -->
<!-- </view> -->
<!-- <view a:if="{{my.getSystemInfoSync().pixelRatio === 2}}"> 1 </view>
<view a:elif="{{1 > 2}}"> 2 </view>
<view a:else> 3 </view> pointer-events: none;-->
<view class="page-game">
<canvas id="canvas" type="2d" class="canvas" disable-scroll="true"
onTouchStart="onMouseEvent"
onTouchMove="onMouseEvent"
onTouchEnd="onMouseEvent"
onReady="onCanvasReady"
></canvas>
<!-- <canvas
id="canva4stats"
type="webgl"
style="width:80;height:48;position:absolute;right:0;top:0;opacity:0.9;z-index:10000;display:block;"
width="80"
height="48"
class="canvas"
disable-scroll="true" /> -->
</view>
This diff is collapsed.
{}
\ No newline at end of file
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
<view class="page" disable-scroll="true" style="padding-top: 0px;-ms-touch-action: none; touch-action: none;background: #888888;
padding: 0;
border: 0;
margin: 0;
height: 100%;">
<form onReset="onReset">
<button form-type="reset">2222</button>
</form>
</view>
<!--<view a:if="{{my.getSystemInfoSync().pixelRatio === 2}}"> 1</view><view a:elif="{{1 > 2}}"> 2</view><view a:else> 3</view> pointer-events: none;-->
\ No newline at end of file
Page({
//暂时先不用吧,有问题
data: {
},
onLoad(query) {
// 页面加载
console.info(`Page onLoad with query: ${JSON.stringify(query)}`);
},
onReady() {
},
onShow() {
// 页面显示
},
onHide() {
// 页面隐藏
},
onUnload() {
// 页面被关闭
// Stage.stop()
},
onTitleClick() {
// 标题被点击
},
onPullDownRefresh() {
// 页面被下拉
},
onReachBottom() {
// 页面被拉到底部
},
onShareAppMessage() {
// 返回自定义分享信息
return {
title: 'My App',
desc: 'My App description',
path: 'pages/index/index',
};
},
onReset(e) {
console.log(111)
// my.navigateTo({
// url: '/pages/index1/index1'
// })
},
});
{}
\ No newline at end of file
/**
* 通用toast
* @param {string} content toast内容
* @param {number} duration 显示时长
*/
export const commonToast = (content, duration = 3000) => {
my.showToast({
content: content || '换个姿势再试一次~',
duration
});
};
/**
* 获取授权用户信息
* @returns {object} 用户登录信息
*/
export const getAuthUserInfo = () => {
return new Promise((resolve, reject) => {
my.authorize({
scopes: 'scope.userInfo',
success: res => {
my.getAuthUserInfo({
success: userInfo => { resolve(userInfo); }
});
},
fail: err => {
reject(err);
}
});
});
};
//例子
// async function getAuth() {
// const userInfo = await getAuthUserInfo().catch(() => {
// commonToast('未授权成功')
// })
// if (!userInfo) return
// const { nickName, avatar } = userInfo
// var app =getApp()//挂到app上
// app.nickName = nickName
// app.avatar = avatar
// }
/**
* 执行关注店铺
* @param {number} sellerId 店铺归属的卖家Id
* @returns {boolean} 关注状态
*/
export const favorShop = (sellerId) => {
return new Promise((resolve, reject) => {
my.tb.favorShop({
id: sellerId,
success: res => {
resolve(res);
},
fail: err => {
// error code 11 为用户取消操作不认作失败场景
if (err.error !== 11) {
reject(err);
}
}
});
})
};
//例子
// async function doFavorShop() {
// const { sellerId } = getApp()//这种id最好挂getApp();
// const success = await favorShop(sellerId).catch(err => {
// commonToast(err.errorMessage || '活动太火爆,请稍后重试')
// console.log("关注失败")
// })
// if (success) {
// console.log("关注成功")
// }
// }
/**
* 判断是否关注店铺
* @param {number} sellerId 店铺归属的卖家Id
* @returns {boolean} 关注状态
*/
export const checkShopFavoredStatus = (sellerId) => {
return new Promise((resolve, reject) => {
my.tb.checkShopFavoredStatus({
id: sellerId,
success: res => {
resolve(res.isFavor);
},
fail: err => {
reject(err);
}
});
});
};
/**
* 跳转到外部链接
* @param {string} url 跳转链接
*/
export const navigateToOutside = (url) => {
my.call("navigateToOutside", { url })
};
/**
* 跳转到内部链接(新开窗口)
* @param {string} url 跳转链接
*/
export const navigateTo = (url) => {
my.navigateTo({ url })
};
/**
* 跳转到内部链接(不新开窗口)
* @param {string} url 跳转链接
*/
export const redirectTo = (url) => {
my.redirectTo({ url })
};
/**
* 获取服务器时间
* @returns {number} 服务器时间戳
*/
export const getServerTime = () => {
return new Promise((resolve, reject) => {
my.getServerTime({
success: (res) => {
resolve(res.time);
},
fail: err => {
reject(err);
}
});
});
};
/**
* 收藏商品
* @param {number} 商品id
* @returns {object} 收藏结果
*/
export const collectGoods = (id) => {
return new Promise((resolve, reject) => {
my.tb.collectGoods({
id,
success: res => {
resolve(res);
},
fail: err => {
if (err.errorMessage === '该商品已收藏') {
// 已收藏没有给到errorCode,只能通过message判断
// 返回收藏成功,并且给到标记代表是已收藏的
resolve({ success: true, hasCollected: true, errorMessage: err.errorMessage });
} else if (err.error !== 11) {
// error code 11 为用户取消操作不认作失败场景
reject(err);
}
}
});
});
};
/**
* 查询商品收藏状态
* @param {number} 商品id
* @returns {boolean} 商品收场状态
*/
export const checkGoodsCollectedStatus = (id) => {
return new Promise((resolve) => {
my.tb.checkGoodsCollectedStatus({
id,
success: res => {
resolve(res.isCollect);
}
});
});
};
/**
* 获取淘宝用户收货地址
*/
export const getUserAddress = (opts = {}) => {
let defaults = {
addAddress: 'show',
searchAddress: 'hide',
locateAddress: 'hide',
joinTag: '' // 分割收货地址符号(淘宝商家有特定发货需求)
};
let _opts = Object.assign({}, defaults, opts);
return new Promise((resolve, reject) => {
my.authorize({
scopes: 'scope.addressList',
success: () => {
const { addAddress, searchAddress, locateAddress, joinTag } = _opts;
if (!my.tb.chooseAddress) {
reject({ support: false, errorMessage: '当前版本不支持选择收货地址,请升级到最新版本' });
return false;
}
my.tb.chooseAddress({
addAddress,
searchAddress,
locateAddress
}, res => {
const { error, provinceName, countyName, cityName, streetName, detailInfo, name, telNumber } = res;
// 如果有error为用户取消操作不做操作
if (error) {
resolve(false);
} else {
resolve({//格式还要修改
...res,
duibaAddress: {
name,
phone: telNumber,
address: [provinceName, cityName, countyName, streetName, detailInfo].join(joinTag)
}
});
}
}, res => {
reject(res);
})
},
});
});
};
//例子
// async function getUserAddress11(prizeId) {
// const userAddress = await getUserAddress().catch(res => {
// commonToast(res.errorMessage)
// })
// if (userAddress) {
// const { name, phone, address } = userAddress.duibaAddress
// my.confirm({
// title: '提示',
// content: '确认使用该收货地址:' + name + phone + address,
// confirmButtonText: '确定',
// cancelButtonText: '取消',
// success: (result) => {
// const { confirm } = result
// if (confirm) {
// //发接口提交地址
// const { cloud, activityId, cloudName } = getApp()
// cloud.function.invoke(cloudName, {
// activityId,
// _id: prizeId,
// address,
// name,
// phone,
// // address: JSON.stringify(userAddress.duibaAddress)
// }, "receiveObjectPrize")
// .then(res => {
// if (res && res.success) {
// console.log("提交成功")
// } else {
// console.log("提交失败1")
// }
// })
// .catch(() => {
// console.log("云函数调用失败")
// })
// } else {
// console.log("用户取消")
// }
// },
// })
// }
// }
\ No newline at end of file
This diff is collapsed.
{
"cloud": {
"type": "CLOUDAPP"
},
"miniprogramRoot": "./client"
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment