Commit c59b521b authored by 韦凯德's avatar 韦凯德

opt: c_client 模板优化

parent 98440a97
No preview for this file type
...@@ -12,8 +12,9 @@ const request = tbccRequest({ ...@@ -12,8 +12,9 @@ const request = tbccRequest({
// api handle 列表 // api handle 列表
const apiList = { const apiList = {
...capi, ...capi,
getIndex: { getActivityBaseInfoById: {
handle: 'index', handle: 'getActivityBaseInfoById',
method: 'GET',
isShowLoading: true isShowLoading: true
}, },
login: 'login' login: 'login'
......
...@@ -6,7 +6,7 @@ cloud.init({ ...@@ -6,7 +6,7 @@ cloud.init({
}); });
App({ App({
requestType: 'ams', // ams:ams接口,cloud: 云函数 requestType: 'yapi', // cloud: 云函数, yapi: yapi 接口, ams: ams接口,
cloudName: 'CommonToC', // 主云函数项目名 cloudName: 'CommonToC', // 主云函数项目名
cloud, cloud,
tbcc, tbcc,
......
...@@ -24,7 +24,7 @@ Page({ ...@@ -24,7 +24,7 @@ Page({
console.info(`Page onLoad with query: ${JSON.stringify(query)}`); console.info(`Page onLoad with query: ${JSON.stringify(query)}`);
}, },
init() { init() {
this.getIndex(); this.getActivityBaseInfoById();
}, },
onReady() { onReady() {
// 页面加载完成 // 页面加载完成
...@@ -65,8 +65,8 @@ Page({ ...@@ -65,8 +65,8 @@ Page({
/** /**
* 获取主接口 * 获取主接口
*/ */
async getIndex() { async getActivityBaseInfoById() {
const { success, data } = await API.getIndex().catch(res => { const { success, data } = await API.getActivityBaseInfoById().catch(res => {
commonToast(res && res.message); commonToast(res && res.message);
}) || {}; }) || {};
...@@ -80,7 +80,7 @@ Page({ ...@@ -80,7 +80,7 @@ Page({
*/ */
async login() { async login() {
const { nickName, avatar } = app; const { nickName, avatar } = app;
const { success } = await API.login({ nickName, avatar }).catch(res => { const { success } = await API.login({ userNick: nickName, avatar }).catch(res => {
commonToast(res && res.message); commonToast(res && res.message);
}) || {}; }) || {};
......
...@@ -74,6 +74,7 @@ Page({ ...@@ -74,6 +74,7 @@ Page({
this.setData({ this.setData({
myPrizeList: data.list myPrizeList: data.list
}) })
console.log(data.list) console.log(data.list)
this.getEndTime(data.list) this.getEndTime(data.list)
} }
......
const capi = { const capi = {
getMyPrizeList: { getMyPrizeList: {
method: 'GET',
handle: 'getMyPrizeList', handle: 'getMyPrizeList',
isShowLoading: true isShowLoading: true
}, },
receiveObjectPrize: 'receiveObjectPrize', receiveObjectPrize: { method: 'GET', handle: 'receiveObjectPrize' },
receiveEnamePrize: 'receiveEnamePrize', receiveEnamePrize: { method: 'GET', handle: 'receiveObjectPrize' },
getItemListByItemIds: 'getItemListByItemIds', getItemListByItemIds: { method: 'GET', handle: 'getItemListByItemIds' },
getCollectGoodsList: 'getCollectGoodsList', getCollectGoodsList: { method: 'GET', handle: 'getCollectGoodsList' },
doCollectGoodsTask: 'doCollectGoodsTask', doCollectGoodsTask: { method: 'GET', handle: 'doCollectGoodsTask' },
doBrowseGoodsTask: 'doBrowseGoodsTask', doBrowseGoodsTask: { method: 'GET', handle: 'doBrowseGoodsTask' },
doJumpLinkTask: 'doJumpLinkTask', doJumpLinkTask: { method: 'GET', handle: 'doJumpLinkTask' },
doExchangeCreditsTask: 'doExchangeCreditsTask', doExchangeCreditsTask: { method: 'GET', handle: 'doExchangeCreditsTask' },
getVipInfo:'getVipInfo' getVipInfo: { method: 'GET', handle: 'getVipInfo' }
}; };
export default capi; export default capi;
const AMS_URL = 'https://docs.dui88.com/mock/140/'; const request = ({ cloud, cloudName, requestType = 'cloud', mockUrl }) => {
const request = ({ cloud, cloudName, requestType = 'cloud' }) => {
if (!cloud) { if (!cloud) {
console.error('请传入cloud'); console.error('请传入cloud');
return false; return false;
...@@ -28,11 +26,16 @@ const request = ({ cloud, cloudName, requestType = 'cloud' }) => { ...@@ -28,11 +26,16 @@ const request = ({ cloud, cloudName, requestType = 'cloud' }) => {
my.showLoading(); my.showLoading();
} }
const requestAms = () => { const requestMock = () => {
const mockUrlPrefix = {
ams: 'https://ams.dui88.com/server/index.php?g=Web&c=Mock&o=simple&projectID=218&uri=',
yapi: 'https://docs.dui88.com/mock/140/'
};
const requestPrefix = mockUrl || mockUrlPrefix[requestType];
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
my.request({ my.request({
url: AMS_URL + _cloudName + '.' + handle, url: requestPrefix + _cloudName + '.' + handle,
method: "GET", method,
data: params, data: params,
dataType: 'json' dataType: 'json'
}).then(({ data: res }) => { }).then(({ data: res }) => {
...@@ -67,7 +70,7 @@ const request = ({ cloud, cloudName, requestType = 'cloud' }) => { ...@@ -67,7 +70,7 @@ const request = ({ cloud, cloudName, requestType = 'cloud' }) => {
}); });
}; };
return requestType === 'ams' ? requestAms() : requestCloud(); return ['ams', 'yapi'].includes(requestType) ? requestMock() : requestCloud();
}; };
}; };
......
...@@ -336,6 +336,9 @@ export const getUserAddress = async (opts = {}) => { ...@@ -336,6 +336,9 @@ export const getUserAddress = async (opts = {}) => {
reject(res); reject(res);
} }
); );
},
fail: err => {
reject(err)
} }
}); });
}); });
...@@ -356,7 +359,7 @@ export const chooseImage = async (opts = {}) => { ...@@ -356,7 +359,7 @@ export const chooseImage = async (opts = {}) => {
if (!my.chooseImage) { if (!my.chooseImage) {
reject({ reject({
noSupport: true, noSupport: true,
errorMessage: '当前版本不支持选择收货地址,请升级到最新版本' errorMessage: '当前版本不支持选择图片,请升级到最新版本'
}); });
return false; return false;
} }
...@@ -487,9 +490,8 @@ export const chattingSendCard = async (requestInfo) => { ...@@ -487,9 +490,8 @@ export const chattingSendCard = async (requestInfo) => {
}; };
/** /**
* 分享到群聊卡片 * 文本风险校验
* @param {*} cloud 小程序云 * @param {string} text 文本
* @param {object} requestInfo 分享到群聊卡片所需请求参数
*/ */
export const textRiskIdentification = async (text) => { export const textRiskIdentification = async (text) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
......
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