【订单详情】

1. 初步接入详情 API 接口
This commit is contained in:
YunaiV committed 2023-06-06 19:12:07 +08:00
1 parent 4a9c829d6f
commit 4e465b7e72
11 files changed
+280 -97

No files matched your search

+70
View File
@@ -0,0 +1,70 @@
// ========== 商品相关的 Util ==========
/**
* 从商品 SKU 数组中,转换出商品属性的数组
*
* 类似结构:[{
* id: // 属性的编号
* name: // 属性的名字
* values: [{
* id: // 属性值的编号
* name: // 属性值的名字
* }]
* }]
*
* @param skus 商品 SKU 数组
*/
export function convertProductPropertyList(skus) {
let result = [];
for (const sku of skus) {
if (!sku.properties) {
continue
}
for (const property of sku.properties) {
// ① 先处理属性
let resultProperty = result.find(item => item.id === property.propertyId)
if (!resultProperty) {
resultProperty = {
id: property.propertyId,
name: property.propertyName,
values: []
}
result.push(resultProperty)
}
// ② 再处理属性值
let resultValue = resultProperty.values.find(item => item.id === property.valueId)
if (!resultValue) {
resultProperty.values.push({
id: property.valueId,
name: property.valueName
})
}
}
}
return result;
}
/**
* 从商品 SKU 数组中,转换出商品 SKU Map
*
* key: 属性值的拼接,使用 , 间隔,例如说 黑色,CH510
*
* @param skus 商品 SKU Map
*/
export function convertProductSkuMap(skus) {
let result = {};
for (const sku of skus) {
let key = '';
if (!sku.properties) {
continue
}
for (const property of sku.properties) {
if (key !== '') {
key += ','
}
key += property.valueName
}
result[key] = sku
}
return result
}
+13 -2
View File
@@ -31,17 +31,28 @@ function baseRequest(url, method, data, {
});
}
}
// TODO 补个 header 多租户
if (url.indexOf('app-api') >= 0) {
header = {
...header
}
header['tenant-id'] = 1
header['Authorization'] = 'Bearer test247'
}
if (store.state.app.token) header[TOKENNAME] = store.state.app.token;
return new Promise((reslove, reject) => {
uni.request({
url: Url + '/api/front/' + url,
url: url.indexOf('app-api') < 0 ? Url + '/api/front/' + url
: 'http://127.0.0.1:48080/' + url, // TODO 芋艿:搞个 url 的配置
method: method || 'GET',
header: header,
data: data || {},
success: (res) => {
if (noVerify)
reslove(res.data, res);
else if (res.data.code == 200)
else if (res.data.code === 200 || res.data.code === 0)
reslove(res.data, res);
else if ([410000, 410001, 410002, 401].indexOf(res.data.code) !== -1) {
toLogin();
+24 -16
View File
@@ -108,7 +108,7 @@ export default {
* @param int index 需要移除的数组的键值
* @param string | int 值
* @return array
*
*
*/
ArrayRemove: function(array, index, value) {
const valueArray = [];
@@ -127,7 +127,7 @@ export default {
* 生成海报获取文字
* @param string text 为传入的文本
* @param int num 为单行显示的字节长度
* @return array
* @return array
*/
textByteLength: function(text, num) {
@@ -164,8 +164,8 @@ export default {
* @param string price 价格
* @param string ot_price 原始价格
* @param function successFn 回调函数
*
*
*
*
*/
PosterCanvas: function(arr2, store_name, price, ot_price, successFn) {
let that = this;
@@ -173,7 +173,7 @@ export default {
ctx.clearRect(0, 0, 0, 0);
/**
* 只能获取合法域名下的图片信息,本地调试无法获取
*
*
*/
ctx.fillStyle = '#fff';
ctx.fillRect(0, 0, 750, 1150);
@@ -331,7 +331,7 @@ export default {
context.clearRect(0, 0, 0, 0);
/**
* 只能获取合法域名下的图片信息,本地调试无法获取
*
*
*/
context.fillStyle = '#fff';
context.fillRect(0, 0, 594, 850);
@@ -425,8 +425,8 @@ export default {
/*
* 单图上传
* @param object opt
* @param callable successCallback 成功执行方法 data
* @param callable errorCallback 失败执行方法
* @param callable successCallback 成功执行方法 data
* @param callable errorCallback 失败执行方法
*/
uploadImageOne: function(opt, successCallback, errorCallback) {
let that = this;
@@ -445,11 +445,11 @@ export default {
model = opt.model;
uni.chooseImage({
count: count, //最多可以选择的图片总数
sizeType: sizeType, // 可以指定是原图还是压缩图,默认二者都有
sourceType: sourceType, // 可以指定来源是相册还是相机,默认二者都有
count: count, //最多可以选择的图片总数
sizeType: sizeType, // 可以指定是原图还是压缩图,默认二者都有
sourceType: sourceType, // 可以指定来源是相册还是相机,默认二者都有
success: function(res) {
//启动上传等待中...
//启动上传等待中...
uni.showLoading({
title: '图片上传中',
});
@@ -509,7 +509,7 @@ export default {
* @param string k 整体分割符 默认为:&
* @param string p 单个分隔符 默认为:=
* @return object
*
*
*/
// #ifdef MP
getUrlParams: function(param, k, p) {
@@ -781,13 +781,21 @@ export default {
else return url.replace('http://', 'https://');
},
/**
* 姓名除了姓显示其他
*/
formatName: function(str) {
return str.substr(0, 1) + new Array(str.length).join('*');
}
},
}
/**
* 将分转成元
*
* @param price 分,例如说 100 分
* @returns {string} 元,例如说 1.00 元
*/
export function fen2yuan(price) {
return (price / 100.0).toFixed(2)
}