Commit b4c5b919 authored by mqf_0707's avatar mqf_0707

修复getStorage首次返回状态

parents b8663266 09ae4bcf
......@@ -140,8 +140,10 @@ var checkShopFavoredStatus = function (sellerId) { return __awaiter(void 0, void
return [4 /*yield*/, helpers_1.promisifyApiToTb('checkShopFavoredStatus', { id: +sellerId })];
case 1:
result = _a.sent();
if (result === null || result === void 0 ? void 0 : result.isFavor)
if ((result === null || result === void 0 ? void 0 : result.isFavor) !== undefined)
return [2 /*return*/, result.isFavor];
if (result === 'checkShopFavoredStatus 仅支持真机调用,请在手机淘宝中运行')
return [2 /*return*/, true];
return [2 /*return*/, result];
}
});
......
This diff is collapsed.
......@@ -220,10 +220,15 @@ exports.uploadImage = uploadImage;
*/
var getAuthUserInfo = function () {
return new Promise(function (resolve, reject) {
// @ts-ignore
my.getAuthUserInfo({
success: function (userInfo) {
resolve(userInfo);
},
fail: function (err) {
my.authorize({
scopes: 'scope.userInfo',
success: function () {
console.log('执行 my.authorize');
// @ts-ignore
my.getAuthUserInfo({
success: function (userInfo) {
......@@ -238,6 +243,9 @@ var getAuthUserInfo = function () {
reject(err);
}
});
}
});
// @ts-ignore
});
};
exports.getAuthUserInfo = getAuthUserInfo;
......
This diff is collapsed.
/**
* 通用toast
* @param {string} content toast内容
* @param {number} duration 显示时长
* @param {function} successCb 成功回调
*/
export declare const commonToast: (content: any, duration: number, successCb: any) => string;
/**
* 简易alert
* @param {string} content toast内容
*/
export declare const simpleAlert: (content: any) => void;
/**
* 获取授权用户信息
* @returns {object} 用户登录信息
*/
export declare const getAuthUserInfo: () => Promise<{
nickName: string;
avatar: string;
mixNick: string;
}>;
/**
* 获取系统信息
* @returns {object} 小程序系统信息
*/
export declare const getSystemInfo: () => Promise<{
version: string;
}>;
/**
* 执行关注店铺
* @param {number} sellerId 店铺归属的卖家Id
* @returns {boolean} 关注状态
*/
export declare const favorShop: (sellerId: any) => Promise<boolean>;
/**
* 判断是否关注店铺
* @param {number} sellerId 店铺归属的卖家Id
* @returns {boolean} 关注状态
*/
export declare const checkShopFavoredStatus: (sellerId: any) => Promise<boolean>;
/**
* 跳转到外部链接
* @param {string} url 跳转链接
*/
export declare const navigateToOutside: (url: any) => boolean;
/**
* 跳转到内部链接(新开窗口)
* @param {string} url 跳转链接
*/
export declare const navigateTo: (url: any) => boolean;
/**
* 跳转到内部链接(不新开窗口)
* @param {string} url 跳转链接
*/
export declare const redirectTo: (url: any) => boolean;
/**
* 获取服务器时间
* @returns {number} 服务器时间戳
*/
export declare const getServerTime: () => Promise<number>;
/**
* 收藏商品
* @param {number} 商品id
* @returns {object} 收藏结果
*/
export declare const collectGoods: (id: any) => Promise<boolean>;
/**
* 查询商品收藏状态
* @param {number} 商品id
* @returns {boolean} 商品收场状态
*/
export declare const checkGoodsCollectedStatus: (id: any) => Promise<boolean>;
/**
* 跳转到淘宝商品页
* @param {string} itemId 商品ID
*/
export declare const openDetail: (itemId: any) => Promise<boolean>;
/**
* 获取淘宝用户收货地址
*/
export declare const getUserAddress: (opts?: {}) => Promise<{
name: number;
phone: number;
address: number;
}>;
/**
* 分享到群聊卡片
* @param {object} requestInfo 分享到群聊卡片所需请求参数
*/
export declare const chattingSendCard: (requestInfo: any) => Promise<boolean>;
/**
* 分享到群聊卡片
* @param {*} cloud 小程序云
* @param {object} requestInfo 分享到群聊卡片所需请求参数
*/
export declare const textRiskIdentification: (text: any) => Promise<boolean>;
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.textRiskIdentification = exports.chattingSendCard = exports.getUserAddress = exports.openDetail = exports.checkGoodsCollectedStatus = exports.collectGoods = exports.getServerTime = exports.redirectTo = exports.navigateTo = exports.navigateToOutside = exports.checkShopFavoredStatus = exports.favorShop = exports.getSystemInfo = exports.getAuthUserInfo = exports.simpleAlert = exports.commonToast = void 0;
/**
* 通用toast
* @param {string} content toast内容
* @param {number} duration 显示时长
* @param {function} successCb 成功回调
*/
var commonToast = function (content, duration, successCb) {
if (duration === void 0) { duration = 3000; }
return '暂不支持toast';
};
exports.commonToast = commonToast;
/**
* 简易alert
* @param {string} content toast内容
*/
var simpleAlert = function (content) {
alert(content);
};
exports.simpleAlert = simpleAlert;
/**
* 获取授权用户信息
* @returns {object} 用户登录信息
*/
var getAuthUserInfo = function () { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, {
nickName: 'nickName',
avatar: '123',
mixNick: '1234'
}];
});
}); };
exports.getAuthUserInfo = getAuthUserInfo;
/**
* 获取系统信息
* @returns {object} 小程序系统信息
*/
var getSystemInfo = function () { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, {
version: '9.5.0'
}];
});
}); };
exports.getSystemInfo = getSystemInfo;
/**
* 执行关注店铺
* @param {number} sellerId 店铺归属的卖家Id
* @returns {boolean} 关注状态
*/
var favorShop = function (sellerId) { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
if (!sellerId) {
console.error('favorShop: 请传入卖家Id');
return [2 /*return*/, false];
}
return [2 /*return*/, true];
});
}); };
exports.favorShop = favorShop;
/**
* 判断是否关注店铺
* @param {number} sellerId 店铺归属的卖家Id
* @returns {boolean} 关注状态
*/
var checkShopFavoredStatus = function (sellerId) { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
if (!sellerId) {
console.error('checkShopFavoredStatus: 请传入卖家Id');
return [2 /*return*/, false];
}
return [2 /*return*/, true];
});
}); };
exports.checkShopFavoredStatus = checkShopFavoredStatus;
/**
* 跳转到外部链接
* @param {string} url 跳转链接
*/
var navigateToOutside = function (url) {
if (!url) {
console.error('navigateToOutside: 请传入url');
return false;
}
window.location = url;
};
exports.navigateToOutside = navigateToOutside;
/**
* 跳转到内部链接(新开窗口)
* @param {string} url 跳转链接
*/
var navigateTo = function (url) {
if (!url) {
console.error('navigateTo: 请传入url');
return false;
}
window.location = url;
};
exports.navigateTo = navigateTo;
/**
* 跳转到内部链接(不新开窗口)
* @param {string} url 跳转链接
*/
var redirectTo = function (url) {
if (!url) {
console.error('redirectTo: 请传入url');
return false;
}
// @ts-ignore
window.replace(url);
};
exports.redirectTo = redirectTo;
/**
* 获取服务器时间
* @returns {number} 服务器时间戳
*/
var getServerTime = function () { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, +new Date()];
});
}); };
exports.getServerTime = getServerTime;
/**
* 收藏商品
* @param {number} 商品id
* @returns {object} 收藏结果
*/
var collectGoods = function (id) { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
if (!id) {
console.error('collectGoods: 请传入商品id');
return [2 /*return*/, false];
}
return [2 /*return*/, true];
});
}); };
exports.collectGoods = collectGoods;
/**
* 查询商品收藏状态
* @param {number} 商品id
* @returns {boolean} 商品收场状态
*/
var checkGoodsCollectedStatus = function (id) { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
if (!id) {
console.error('checkGoodsCollectedStatus: 请传入商品id');
return [2 /*return*/, false];
}
return [2 /*return*/, true];
});
}); };
exports.checkGoodsCollectedStatus = checkGoodsCollectedStatus;
/**
* 跳转到淘宝商品页
* @param {string} itemId 商品ID
*/
var openDetail = function (itemId) { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
if (!itemId) {
console.error('openDetail: 请传入商品id');
return [2 /*return*/, false];
}
// @ts-ignore
window.location = 'https://item.taobao.com/item.htm?id=' + itemId;
return [2 /*return*/];
});
}); };
exports.openDetail = openDetail;
/**
* 获取淘宝用户收货地址
*/
var getUserAddress = function (opts) {
if (opts === void 0) { opts = {}; }
return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, {
name: 1,
phone: 1,
address: 123
}];
});
});
};
exports.getUserAddress = getUserAddress;
/**
* 分享到群聊卡片
* @param {object} requestInfo 分享到群聊卡片所需请求参数
*/
var chattingSendCard = function (requestInfo) { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
alert('无法模拟');
return [2 /*return*/, false];
});
}); };
exports.chattingSendCard = chattingSendCard;
/**
* 分享到群聊卡片
* @param {*} cloud 小程序云
* @param {object} requestInfo 分享到群聊卡片所需请求参数
*/
var textRiskIdentification = function (text) { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, true];
});
}); };
exports.textRiskIdentification = textRiskIdentification;
//# sourceMappingURL=tbMock.js.map
\ No newline at end of file
{"version":3,"file":"tbMock.js","sourceRoot":"","sources":["../../src/core/tbMock.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;GAKG;AACI,IAAM,WAAW,GAAG,UAAC,OAAO,EAAE,QAAe,EAAE,SAAS;IAA1B,yBAAA,EAAA,eAAe;IAChD,OAAO,WAAW,CAAC;AACvB,CAAC,CAAC;AAFW,QAAA,WAAW,eAEtB;AACF;;;GAGG;AACI,IAAM,WAAW,GAAG,UAAA,OAAO;IAC9B,KAAK,CAAC,OAAO,CAAC,CAAC;AACnB,CAAC,CAAC;AAFW,QAAA,WAAW,eAEtB;AACF;;;GAGG;AACI,IAAM,eAAe,GAAG;;QAC3B,sBAAO;gBACH,QAAQ,EAAE,UAAU;gBACpB,MAAM,EAAE,KAAK;gBACb,OAAO,EAAE,MAAM;aAClB,EAAC;;KACL,CAAC;AANW,QAAA,eAAe,mBAM1B;AAEF;;;GAGG;AACI,IAAM,aAAa,GAAG;;QACzB,sBAAO;gBACH,OAAO,EAAE,OAAO;aACnB,EAAC;;KACL,CAAC;AAJW,QAAA,aAAa,iBAIxB;AACF;;;;GAIG;AACI,IAAM,SAAS,GAAG,UAAM,QAAQ;;QACnC,IAAI,CAAC,QAAQ,EAAE;YACX,OAAO,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC;YACpC,sBAAO,KAAK,EAAC;SAChB;QACD,sBAAO,IAAI,EAAC;;KACf,CAAC;AANW,QAAA,SAAS,aAMpB;AACF;;;;GAIG;AACI,IAAM,sBAAsB,GAAG,UAAM,QAAQ;;QAChD,IAAI,CAAC,QAAQ,EAAE;YAC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MvB;AACF;;;;GAIG;AACI,IAAM,yBAAyB,GAAG,UAAM,EAAE;;QAC7C,IAAI,CAAC,EAAE,EAAE;YACL,OAAO,CAAC,KAAK,CAAC,oCAAoC,CAAC,CAAC;YACpD,sBAAO,KAAK,EAAC;SAChB;QACD,sBAAO,IAAI,EAAC;;KACf,CAAC;AANW,QAAA,yBAAyB,6BAMpC;AACF;;;GAGG;AACI,IAAM,UAAU,GAAG,UAAM,MAAM;;QAClC,IAAI,CAAC,MAAM,EAAE;YACT,OAAO,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC;YACrC,sBAAO,KAAK,EAAC;SAChB;QACD,aAAa;QACb,MAAM,CAAC,QAAQ,GAAG,sCAAsC,GAAG,MAAM,CAAC;;;KACrE,CAAC;AAPW,QAAA,UAAU,cAOrB;AACF;;GAEG;AACI,IAAM,cAAc,GAAG,UAAO,IAAS;IAAT,qBAAA,EAAA,SAAS;;;YAC1C,sBAAO;oBACH,IAAI,EAAE,CAAC;oBACP,KAAK,EAAE,CAAC;oBACR,OAAO,EAAE,GAAG;iBACf,EAAA;;;CACJ,CAAC;AANW,QAAA,cAAc,kBAMzB;AACF;;;GAGG;AACI,IAAM,gBAAgB,GAAG,UAAO,WAAW;;QAC9C,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,sBAAO,KAAK,EAAC;;KAChB,CAAC;AAHW,QAAA,gBAAgB,oBAG3B;AACF;;;;GAIG;AACI,IAAM,sBAAsB,GAAG,UAAO,IAAI;;QAC7C,sBAAO,IAAI,EAAC;;KACf,CAAA;AAFY,QAAA,sBAAsB,0BAElC"}
\ No newline at end of file
{
"name": "tbcc-sdk-ts",
"version": "1.0.3",
"version": "1.0.4",
"description": "",
"main": "lib/index.js",
"scripts": {
......
......@@ -75,7 +75,8 @@ export const checkShopFavoredStatus = async (sellerId: number) => {
return false;
}
let result: { isFavor?: boolean } = await promisifyApiToTb('checkShopFavoredStatus',{ id: +sellerId })
if(result?.isFavor) return result.isFavor
if(result?.isFavor !== undefined) return result.isFavor
if(result === 'checkShopFavoredStatus 仅支持真机调用,请在手机淘宝中运行')return true
return result
};
/**
......
......@@ -149,10 +149,15 @@ export const uploadImage = async (opts = {}) => {
*/
export const getAuthUserInfo = () => {
return new Promise((resolve, reject) => {
// @ts-ignore
my.getAuthUserInfo({
success: userInfo => {
resolve(userInfo);
},
fail: err => {
my.authorize({
scopes: 'scope.userInfo',
success: () => {
console.log('执行 my.authorize')
// @ts-ignore
my.getAuthUserInfo({
success: userInfo => {
......@@ -167,6 +172,10 @@ export const getAuthUserInfo = () => {
reject(err);
}
});
}
});
// @ts-ignore
});
};
/**
......
......@@ -76,3 +76,5 @@ interface ISkuInfo {
skuId: string
quantity: string
}
declare var my: any
\ No newline at end of file
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