!26 接口层兼容

Merge pull request !26 from Bluemark/vue3_tmp
pull/28/head
芋道源码 2023-12-13 03:17:05 +00:00 committed by Gitee
commit 82407aa87c
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
28 changed files with 3467 additions and 3409 deletions

20
.env
View File

@ -1,20 +0,0 @@
# 版本号
SHOPRO_VERSION = v1.8.3
# 正式环境接口域名
SHOPRO_BASE_URL = https://api.shopro.sheepjs.com
# 开发环境接口域名
SHOPRO_DEV_BASE_URL = https://api.shopro.sheepjs.com
# 开发环境运行端口
SHOPRO_DEV_PORT = 3000
# 接口地址前缀
SHOPRO_API_PATH = /shop/api/
# 客户端静态资源地址 空=默认使用服务端指定的CDN资源地址前缀 | local=本地 | http(s)://xxx.xxx=自定义静态资源地址前缀
SHOPRO_STATIC_URL = https://file.sheepjs.com
# 是否开启直播 1 开启直播 | 0 关闭直播 (小程序官方后台未审核开通直播权限时请勿开启)
SHOPRO_MPLIVE_ON = 0

View File

@ -148,11 +148,20 @@
}); });
if (res.code === 0) { if (res.code === 0) {
// //
let obj2 = {
2: '折扣',
1: '满减'
}
let obj = { let obj = {
1: '可用', 1: '可用',
2: '已用', 2: '已用',
3: '过期' 3: '过期'
} }
let obj3 = {
1: '已领取',
2: '已使用',
3: '已过期'
}
res.data.list = res.data.list.map(item => { res.data.list = res.data.list.map(item => {
return { return {
...item, ...item,
@ -160,7 +169,8 @@
amount: (item.discountPrice / 100).toFixed(2), amount: (item.discountPrice / 100).toFixed(2),
use_start_time: sheep.$helper.timeFormat(item.validStartTime, 'yyyy-mm-dd hh:MM:ss'), use_start_time: sheep.$helper.timeFormat(item.validStartTime, 'yyyy-mm-dd hh:MM:ss'),
use_end_time: sheep.$helper.timeFormat(item.validEndTime, 'yyyy-mm-dd hh:MM:ss'), use_end_time: sheep.$helper.timeFormat(item.validEndTime, 'yyyy-mm-dd hh:MM:ss'),
status_text: obj[item.status] status_text: obj[item.status],
type_text: obj2[item.discountType]
} }
}); });
if (page >= 2) { if (page >= 2) {

View File

@ -2,50 +2,29 @@
<su-fixed bottom placeholder bg="bg-white"> <su-fixed bottom placeholder bg="bg-white">
<view class="ui-tabbar-box"> <view class="ui-tabbar-box">
<view class="ui-tabbar ss-flex ss-col-center ss-row-between"> <view class="ui-tabbar ss-flex ss-col-center ss-row-between">
<view <view v-if="collectIcon" class="detail-tabbar-item ss-flex ss-flex-col ss-row-center ss-col-center"
v-if="collectIcon" @tap="onFavorite">
class="detail-tabbar-item ss-flex ss-flex-col ss-row-center ss-col-center"
@tap="onFavorite"
>
<block v-if="modelValue.favorite"> <block v-if="modelValue.favorite">
<image <image class="item-icon" :src="sheep.$url.static('/static/img/shop/goods/collect_1.gif')"
class="item-icon" mode="aspectFit"></image>
:src="sheep.$url.static('/static/img/shop/goods/collect_1.gif')"
mode="aspectFit"
></image>
<view class="item-title">已收藏</view> <view class="item-title">已收藏</view>
</block> </block>
<block v-else> <block v-else>
<image <image class="item-icon" :src="sheep.$url.static('/static/img/shop/goods/collect_0.png')"
class="item-icon" mode="aspectFit"></image>
:src="sheep.$url.static('/static/img/shop/goods/collect_0.png')"
mode="aspectFit"
></image>
<view class="item-title">收藏</view> <view class="item-title">收藏</view>
</block> </block>
</view> </view>
<view <view v-if="serviceIcon" class="detail-tabbar-item ss-flex ss-flex-col ss-row-center ss-col-center"
v-if="serviceIcon" @tap="onChat">
class="detail-tabbar-item ss-flex ss-flex-col ss-row-center ss-col-center" <image class="item-icon" :src="sheep.$url.static('/static/img/shop/goods/message.png')"
@tap="onChat" mode="aspectFit"></image>
>
<image
class="item-icon"
:src="sheep.$url.static('/static/img/shop/goods/message.png')"
mode="aspectFit"
></image>
<view class="item-title">客服</view> <view class="item-title">客服</view>
</view> </view>
<view <view v-if="shareIcon" class="detail-tabbar-item ss-flex ss-flex-col ss-row-center ss-col-center"
v-if="shareIcon" @tap="showShareModal">
class="detail-tabbar-item ss-flex ss-flex-col ss-row-center ss-col-center" <image class="item-icon" :src="sheep.$url.static('/static/img/shop/goods/share.png')"
@tap="showShareModal" mode="aspectFit"></image>
>
<image
class="item-icon"
:src="sheep.$url.static('/static/img/shop/goods/share.png')"
mode="aspectFit"
></image>
<view class="item-title">分享</view> <view class="item-title">分享</view>
</view> </view>
<slot></slot> <slot></slot>
@ -67,9 +46,14 @@
* *
*/ */
import { computed, reactive } from 'vue'; import {
computed,
reactive
} from 'vue';
import sheep from '@/sheep'; import sheep from '@/sheep';
import { showShareModal } from '@/sheep/hooks/useModal'; import {
showShareModal
} from '@/sheep/hooks/useModal';
// //
const state = reactive({}); const state = reactive({});
@ -78,7 +62,7 @@
const props = defineProps({ const props = defineProps({
modelValue: { modelValue: {
type: Object, type: Object,
default() {}, default () {},
}, },
bg: { bg: {
type: String, type: String,
@ -86,7 +70,7 @@
}, },
bgStyles: { bgStyles: {
type: Object, type: Object,
default() {}, default () {},
}, },
ui: { ui: {
type: String, type: String,
@ -126,13 +110,22 @@
uni.setStorageSync('tabbar', e); uni.setStorageSync('tabbar', e);
}; };
async function onFavorite() { async function onFavorite() {
const { error } = await sheep.$api.user.favorite.do(props.modelValue.id); // const { error } = await sheep.$api.user.favorite.do(props.modelValue.id);
if (error === 0) { // if (error === 0) {
// if (props.modelValue.favorite) {
// props.modelValue.favorite = 0;
// } else {
// props.modelValue.favorite = 1;
// }
// }
let data;
if (props.modelValue.favorite) { if (props.modelValue.favorite) {
props.modelValue.favorite = 0; data = await sheep.$api.user.favorite.dos(props.modelValue.id);
} else { } else {
props.modelValue.favorite = 1; data = await sheep.$api.user.favorite.do(props.modelValue.id);
} }
if (data.data) {
props.modelValue.favorite = !props.modelValue.favorite;
} }
} }
@ -147,6 +140,7 @@
.ui-tabbar-box { .ui-tabbar-box {
box-shadow: 0px -6px 10px 0px rgba(51, 51, 51, 0.2); box-shadow: 0px -6px 10px 0px rgba(51, 51, 51, 0.2);
} }
.ui-tabbar { .ui-tabbar {
display: flex; display: flex;
height: 50px; height: 50px;

View File

@ -12,9 +12,7 @@
<block v-else> <block v-else>
<view class="detail-swiper-selector"> <view class="detail-swiper-selector">
<!-- 商品轮播图 --> <!-- 商品轮播图 -->
<su-swiper class="ss-m-b-14" isPreview :list="formatGoodsSwiper(state.goodsInfo.sliderPicUrls)" <su-swiper class="ss-m-b-14" isPreview :list="formatGoodsSwiper(state.goodsInfo.sliderPicUrls)" dotStyle="tag" imageMode="widthFix" dotCur="bg-mask-40" :seizeHeight="750" />
dotStyle="tag" imageMode="widthFix" dotCur="bg-mask-40" :seizeHeight="750" />
<!-- 价格+标题 --> <!-- 价格+标题 -->
<view class="title-card detail-card ss-p-y-40 ss-p-x-20"> <view class="title-card detail-card ss-p-y-40 ss-p-x-20">
<view class="ss-flex ss-row-between ss-col-center ss-m-b-26"> <view class="ss-flex ss-row-between ss-col-center ss-m-b-26">
@ -32,6 +30,8 @@
</view> </view>
<view class="discounts-box ss-flex ss-row-between ss-m-b-28"> <view class="discounts-box ss-flex ss-row-between ss-m-b-28">
<!-- 满减送/限时折扣活动的提示 TODO 芋艿promos 未写 --> <!-- 满减送/限时折扣活动的提示 TODO 芋艿promos 未写 -->
<div class="tag-content">
<!-- 满减送/限时折扣活动的提示 TODO 芋艿promos 未写 -->
<div class="tag-content"> <div class="tag-content">
<view class="tag-box ss-flex"> <view class="tag-box ss-flex">
<view class="tag ss-m-r-10" v-for="promos in state.goodsInfo.promos" :key="promos.id" @tap="onActivity"> <view class="tag ss-m-r-10" v-for="promos in state.goodsInfo.promos" :key="promos.id" @tap="onActivity">
@ -39,7 +39,6 @@
</view> </view>
</view> </view>
</div> </div>
<!-- 优惠劵 --> <!-- 优惠劵 -->
<view class="get-coupon-box ss-flex ss-col-center ss-m-l-20" @tap="state.showModel = true" <view class="get-coupon-box ss-flex ss-col-center ss-m-l-20" @tap="state.showModel = true"
v-if="state.couponInfo.length"> v-if="state.couponInfo.length">
@ -87,12 +86,13 @@
<button class="ss-reset-button disabled-btn" disabled> 已售罄 </button> <button class="ss-reset-button disabled-btn" disabled> 已售罄 </button>
</view> </view>
</detail-tabbar> </detail-tabbar>
<!-- 优惠劵弹窗 --> <!-- 优惠劵弹窗 -->
<s-coupon-get v-model="state.couponInfo" :show="state.showModel" @close="state.showModel = false" <s-coupon-get v-model="state.couponInfo" :show="state.showModel" @close="state.showModel = false" @get="onGet" />
@get="onGet" />
<!-- 满减送/限时折扣活动弹窗 --> <!-- 满减送/限时折扣活动弹窗 -->
<!-- 优惠劵弹窗 -->
<s-coupon-get v-model="state.couponInfo" :show="state.showModel" @close="state.showModel = false" @get="onGet" />
<!-- 满减送/限时折扣活动弹窗 -->
<s-activity-pop v-model="state.activityInfo" :show="state.showActivityModel" <s-activity-pop v-model="state.activityInfo" :show="state.showActivityModel"
@close="state.showActivityModel = false" /> @close="state.showActivityModel = false" />
</block> </block>
@ -106,6 +106,13 @@
import sheep from '@/sheep'; import sheep from '@/sheep';
import CouponApi from '@/sheep/api/promotion/coupon'; import CouponApi from '@/sheep/api/promotion/coupon';
import ActivityApi from '@/sheep/api/promotion/activity'; import ActivityApi from '@/sheep/api/promotion/activity';
import {
formatSales,
formatGoodsSwiper,
fen2yuan,
} from '@/sheep/hooks/useGoods';
import CouponApi from '@/sheep/api/promotion/coupon';
import ActivityApi from '@/sheep/api/promotion/activity';
import { formatSales, formatGoodsSwiper, fen2yuan, } from '@/sheep/hooks/useGoods'; import { formatSales, formatGoodsSwiper, fen2yuan, } from '@/sheep/hooks/useGoods';
import detailNavbar from './components/detail/detail-navbar.vue'; import detailNavbar from './components/detail/detail-navbar.vue';
import detailCellSku from './components/detail/detail-cell-sku.vue'; import detailCellSku from './components/detail/detail-cell-sku.vue';
@ -138,8 +145,9 @@
state.selectedSku = e; state.selectedSku = e;
} }
// // TODO
function onAddCart(e) { function onAddCart(e) {
console.log(e, '加入购物车');
sheep.$store('cart').add(e); sheep.$store('cart').add(e);
} }
@ -166,10 +174,10 @@
// TODO // TODO
async function onGet(id) { async function onGet(id) {
const { const {
error, code,
msg msg
} = await sheep.$api.coupon.get(id); } = await sheep.$api.coupon.get(id);
if (error === 0) { if (code === 0) {
uni.showToast({ uni.showToast({
title: msg, title: msg,
}); });
@ -180,6 +188,7 @@
} }
// TODO // TODO
const shareInfo = computed(() => { const shareInfo = computed(() => {
if (isEmpty(state.goodsInfo)) return {}; if (isEmpty(state.goodsInfo)) return {};
return sheep.$platform.share.getShareInfo({ return sheep.$platform.share.getShareInfo({
@ -207,6 +216,75 @@
} }
state.goodsId = options.id; state.goodsId = options.id;
// 1. // 1.
sheep.$api.goods.detail(state.goodsId).then(async (res) => {
//
if (res.code !== 0 || !res.data) {
state.goodsInfo = null;
return;
}
//
state.skeletonLoading = false;
//
let dasa = await sheep.$api.goods.exits(options.id);
res.data.favorite = dasa.data;
state.goodsInfo = res.data;
console.log(state.goodsInfo, '商品信息');
//
// 2.
CouponApi.getCouponTemplateList({
price: state.goodsInfo.price,
spuIds: [state.goodsInfo.id],
skuIds: state.goodsInfo.skus.map(item => item.id),
//
categoryIds: [52]
}).then((res) => {
console.log(res, '优惠券信息进行对接')
if (res.code !== 0) {
return;
}
//
let obj2 = {
2: '折扣',
1: '满减'
}
let obj = {
1: '可用',
2: '已用',
3: '过期'
}
let obj3 = {
1: '已领取',
2: '已使用',
3: '已过期'
}
res.data = res.data.map(item => {
return {
...item,
enough: (item.usePrice / 100).toFixed(2),
amount: (item.discountPrice / 100).toFixed(2),
use_start_time: sheep.$helper.timeFormat(item
.validStartTime,
'yyyy-mm-dd hh:MM:ss'),
use_end_time: sheep.$helper.timeFormat(item.validEndTime,
'yyyy-mm-dd hh:MM:ss'),
status_text: obj[item.status],
type_text: obj2[item.discountType],
get_status_text: obj3[item.status],
type_text: obj2[item.discountType]
}
});
state.couponInfo = res.data;
});
});
// return;
// 3.
ActivityApi.getActivityListBySpuId(state.goodsId).then((res) => {
if (res.code !== 0) {
return;
}
state.activityList = res.data;
});
sheep.$api.goods.detail(state.goodsId).then((res) => { sheep.$api.goods.detail(state.goodsId).then((res) => {
// //
if (res.code !== 0 || !res.data) { if (res.code !== 0 || !res.data) {

View File

@ -1,12 +1,7 @@
<template> <template>
<s-layout
title="我的" <s-layout title="我的" tabbar="/pages/index/user" navbar="custom" :bgStyle="template.page"
tabbar="/pages/index/user" :navbarStyle="template.style?.navbar" onShareAppMessage>
navbar="custom"
:bgStyle="template.page"
:navbarStyle="template.style?.navbar"
onShareAppMessage
>
<s-block v-for="(item, index) in template.components" :key="index" :styles="item.property.style"> <s-block v-for="(item, index) in template.components" :key="index" :styles="item.property.style">
<s-block-item :type="item.id" :data="item.property" :styles="item.property.style" /> <s-block-item :type="item.id" :data="item.property" :styles="item.property.style" />
</s-block> </s-block>
@ -14,8 +9,14 @@
</template> </template>
<script setup> <script setup>
import { computed } from 'vue'; import {
import { onShow, onPageScroll, onPullDownRefresh } from '@dcloudio/uni-app'; computed
} from 'vue';
import {
onShow,
onPageScroll,
onPullDownRefresh
} from '@dcloudio/uni-app';
import sheep from '@/sheep'; import sheep from '@/sheep';
// tabBar // tabBar
@ -30,7 +31,7 @@
onPullDownRefresh(() => { onPullDownRefresh(() => {
sheep.$store('user').updateUserData(); sheep.$store('user').updateUserData();
setTimeout(function () { setTimeout(function() {
uni.stopPullDownRefresh(); uni.stopPullDownRefresh();
}, 800); }, 800);
}); });

View File

@ -1,10 +1,9 @@
import request from '@/sheep/request'; import request from '@/sheep/request';
import request2 from '@/sheep/request2';
export default { export default {
list: (data) => list: (data) =>
request2({ request({
url: 'trade/cart/list', url: '/app-api/trade/cart/list',
method: 'GET', method: 'GET',
custom: { custom: {
showLoading: false, showLoading: false,
@ -13,7 +12,7 @@ export default {
}), }),
append: (data) => append: (data) =>
request({ request({
url: 'cart', url: '/app-api/trade/cart/add',
method: 'POST', method: 'POST',
// TODO 芋艿:这里没提示 // TODO 芋艿:这里没提示
custom: { custom: {
@ -22,18 +21,31 @@ export default {
}, },
data: { data: {
...data, ...data,
type: 'inc', // type: 'inc',
}, },
}), }),
// append: (data) =>
// request({
// url: 'cart',
// method: 'POST',
// custom: {
// showSuccess: true,
// successMsg: '已添加到购物车~',
// },
// data: {
// ...data,
// type: 'inc',
// },
// }),
// 删除购物车 // 删除购物车
delete: (ids) => delete: (ids) =>
request2({ request({
url: 'trade/cart/delete?ids=' + ids, url: '/app-api/trade/cart/delete?ids=' + ids,
method: 'DELETE', method: 'DELETE',
}), }),
update: (data) => update: (data) =>
request2({ request({
url: 'trade/cart/update-count', url: '/app-api/trade/cart/update-count',
method: 'PUT', method: 'PUT',
data: { data: {
...data, ...data,

View File

@ -1,9 +1,7 @@
import request2 from '@/sheep/request2';
export default { export default {
list: (params) => list: (params) =>
request2({ request({
url: 'product/category/list', url: '/app-api/product/category/list',
method: 'GET', method: 'GET',
params, params,
}), }),

View File

@ -1,5 +1,4 @@
import request from '@/sheep/request'; import request from '@/sheep/request';
import request2 from '@/sheep/request2';
export default { export default {
// 我的拼团 // 我的拼团
@ -13,8 +12,8 @@ export default {
}, },
}), }),
userCoupon: (params) => userCoupon: (params) =>
request2({ request({
url: 'promotion/coupon/page', url: '/app-api/promotion/coupon/page',
method: 'GET', method: 'GET',
params, params,
}), }),
@ -34,9 +33,20 @@ export default {
}), }),
get: (id) => get: (id) =>
request({ request({
url: 'coupon/get/' + id, url: '/app-api/promotion/coupon/take',
method: 'POST', method: 'POST',
data: {
templateId: id
},
params: {
templateId: id
},
}), }),
// get: (id) =>
// request({
// url: 'coupon/get/' + id,
// method: 'POST',
// }),
listByGoods: (id) => listByGoods: (id) =>
request({ request({
url: 'coupon/listByGoods/' + id, url: 'coupon/listByGoods/' + id,

View File

@ -1,10 +1,9 @@
import request from '@/sheep/request'; import request from '@/sheep/request';
import request2 from '@/sheep/request2';
export default { export default {
area: () => area: () =>
request2({ request({
url: 'system/area/tree', url: '/app-api/system/area/tree',
method: 'GET', method: 'GET',
}), }),
// area: () => // area: () =>

View File

@ -1,11 +1,10 @@
import request from '@/sheep/request'; import request from '@/sheep/request';
import request2 from '@/sheep/request2';
export default { export default {
// 商品详情 // 商品详情
detail: (id, params = {}) => detail: (id, params = {}) =>
request2({ request({
url: 'product/spu/get-detail?id=' + id, url: '/app-api/product/spu/get-detail?id=' + id,
method: 'GET', method: 'GET',
params, params,
custom: { custom: {
@ -16,8 +15,8 @@ export default {
// 商品列表 // 商品列表
list: (params) => list: (params) =>
request2({ request({
url: 'product/spu/page', url: '/app-api/product/spu/page',
method: 'GET', method: 'GET',
params, params,
custom: { custom: {
@ -37,11 +36,10 @@ export default {
showError: false, showError: false,
}, },
}), }),
// 商品评价列表 // 商品评价列表
comment: (id, params = {}) => comment: (id, params = {}) =>
request2({ request({
url: 'product/comment/list?spuId=' + id, url: '/app-api/product/comment/list?spuId=' + id,
method: 'GET', method: 'GET',
params, params,
custom: { custom: {
@ -77,4 +75,10 @@ export default {
method: 'GET', method: 'GET',
params, params,
}), }),
// 检查是否收藏商品
exits: (id) =>
request({
url: '/app-api/product/favorite/exits?spuId=' + id,
method: 'GET',
}),
}; };

View File

@ -1,14 +1,14 @@
import request2 from '@/sheep/request2'; import request from '@/sheep/request';
export default { export default {
decorate: () => decorate: () =>
request2({ request({
url: 'promotion/decorate/list?page=1', url: '/app-api/promotion/decorate/list?page=1',
method: 'GET', method: 'GET',
}), }),
spids: () => spids: () =>
request2({ request({
url: 'product/spu/page?recommendType=best&pageNo=1&pageSize=10', url: '/app-api/product/spu/page?recommendType=best&pageNo=1&pageSize=10',
method: 'GET', method: 'GET',
}), }),
}; };

View File

@ -1,11 +1,10 @@
import request from '@/sheep/request'; import request from '@/sheep/request';
import request2 from '@/sheep/request2';
export default { export default {
// 订单详情 // 订单详情
detail: (id, params) => detail: (id, params) =>
request2({ request({
url: 'trade/order/get-detail?id=' + id, url: '/app-api/trade/order/get-detail?id=' + id,
method: 'GET', method: 'GET',
params, params,
}), }),
@ -40,8 +39,8 @@ export default {
}), }),
// 订单列表 // 订单列表
list: (params) => list: (params) =>
request2({ request({
url: 'trade/order/page', url: '/app-api/trade/order/page',
method: 'GET', method: 'GET',
params, params,
custom: { custom: {
@ -65,16 +64,25 @@ export default {
// 解决 SpringMVC 接受 List<Item> 参数的问题 // 解决 SpringMVC 接受 List<Item> 参数的问题
delete data2.items delete data2.items
for (let i = 0; i < data.items.length; i++) { for (let i = 0; i < data.items.length; i++) {
// 此处转码问题,待解决方案
data2[encodeURIComponent('items[' + i + '' + '].skuId')] = data.items[i].skuId + ''; data2[encodeURIComponent('items[' + i + '' + '].skuId')] = data.items[i].skuId + '';
data2[encodeURIComponent('items[' + i + '' + '].count')] = data.items[i].count + ''; data2[encodeURIComponent('items[' + i + '' + '].count')] = data.items[i].count + '';
if (data.items[i].cartId) {
data2[encodeURIComponent('items[' + i + '' + '].cartId')] = data.items[i].cartId + ''; data2[encodeURIComponent('items[' + i + '' + '].cartId')] = data.items[i].cartId + '';
// data2['items' + `[${i}]` + '.skuId'] = data.items[i].skuId + '';
// data2['items' + `[${i}]` + '.count'] = data.items[i].count + '';
// data2['items' + `[${i}]` + '.cartId'] = data.items[i].cartId + '';
// data2['items' + `%5B${i}%5D` + '.skuId'] = data.items[i].skuId + '';
// data2['items' + `%5B${i}%5D` + '.count'] = data.items[i].count + '';
// data2['items' + `%5B${i}%5D` + '.cartId'] = data.items[i].cartId + '';
} }
} console.log(data2, '手动转码的参数')
const queryString= Object.keys(data2).map(key => key + '=' + data2[key]).join('&') return request({
return request2({ url: '/app-api/trade/order/settlement',
url: `trade/order/settlement?${queryString}`, method: 'GET',
method: 'GET' // data: data2,
params: data2
}) })
}, },
// 创建订单 // 创建订单
@ -99,8 +107,8 @@ export default {
}), }),
// 评价订单 // 评价订单
comment: (data) => comment: (data) =>
request2({ request({
url: 'trade/order/item/create-comment', url: '/app-api/trade/order/item/create-comment',
method: 'POST', method: 'POST',
data, data,
}), }),
@ -138,8 +146,8 @@ export default {
data, data,
}), }),
list: (params) => list: (params) =>
request2({ request({
url: 'trade/after-sale/page', url: '/app-api/trade/after-sale/page',
method: 'GET', method: 'GET',
params, params,
custom: { custom: {
@ -169,8 +177,8 @@ export default {
}), }),
// 售后详情 // 售后详情
detail: (id) => detail: (id) =>
request2({ request({
url: 'trade/after-sale/get?id=' + id, url: '/app-api/trade/after-sale/get?id=' + id,
method: 'GET', method: 'GET',
}), }),
}, },

View File

@ -1,6 +1,7 @@
import request from '@/sheep/request'; import request from '@/sheep/request';
const CommentApi = { const CommentApi = {
// 获得商品评价分页 // 获得商品评价分页
getCommentPage: (spuId, pageNo, pageSize, type) => { getCommentPage: (spuId, pageNo, pageSize, type) => {
return request({ return request({

View File

@ -1,9 +1,9 @@
import request2 from '@/sheep/request2'; import request from '@/sheep/request';
const ActivityApi = { const ActivityApi = {
// 获得单个商品,近期参与的每个活动 // 获得单个商品,近期参与的每个活动
getActivityListBySpuId: (spuId) => { getActivityListBySpuId: (spuId) => {
return request2({ return request({
url: '/app-api/promotion/activity/list-by-spu-id', url: '/app-api/promotion/activity/list-by-spu-id',
method: 'GET', method: 'GET',
params: { params: {

View File

@ -1,20 +1,22 @@
import request2 from "@/sheep/request2"; import request from "@/sheep/request";
// 拼团 API // 拼团 API
const CombinationApi = { const CombinationApi = {
// 获得拼团活动列表 // 获得拼团活动列表
getCombinationActivityList: (count) => { getCombinationActivityList: (count) => {
return request2({ return request({
url: "promotion/combination-activity/list", url: "/app-api/promotion/combination-activity/list",
method: 'GET', method: 'GET',
params: {count} params: {
count
}
}); });
}, },
// 获得拼团活动分页 // 获得拼团活动分页
getCombinationActivityPage: (params) => { getCombinationActivityPage: (params) => {
return request2({ return request({
url: "promotion/combination-activity/page", url: "/app-api/promotion/combination-activity/page",
method: 'GET', method: 'GET',
params params
}); });
@ -22,8 +24,8 @@ const CombinationApi = {
// 获得拼团活动明细 // 获得拼团活动明细
getCombinationActivity: (id) => { getCombinationActivity: (id) => {
return request2({ return request({
url: "promotion/combination-activity/get-detail", url: "/app-api/promotion/combination-activity/get-detail",
method: 'GET', method: 'GET',
params: { params: {
id id
@ -33,8 +35,8 @@ const CombinationApi = {
// 获得最近 n 条拼团记录(团长发起的) // 获得最近 n 条拼团记录(团长发起的)
getHeadCombinationRecordList: (activityId, status, count) => { getHeadCombinationRecordList: (activityId, status, count) => {
return request2({ return request({
url: "promotion/combination-record/get-head-list", url: "/app-api/promotion/combination-record/get-head-list",
method: 'GET', method: 'GET',
params: { params: {
activityId, activityId,
@ -46,8 +48,8 @@ const CombinationApi = {
// 获得拼团记录明细 // 获得拼团记录明细
getCombinationRecordDetail: (id) => { getCombinationRecordDetail: (id) => {
return request2({ return request({
url: "promotion/combination-record/get-detail", url: "/app-api/promotion/combination-record/get-detail",
method: 'GET', method: 'GET',
params: { params: {
id id
@ -57,8 +59,8 @@ const CombinationApi = {
// 获得拼团记录的概要信息 // 获得拼团记录的概要信息
getCombinationRecordSummary: () => { getCombinationRecordSummary: () => {
return request2({ return request({
url: "promotion/combination-record/get-summary", url: "/app-api/promotion/combination-record/get-summary",
method: 'GET', method: 'GET',
}); });
} }

View File

@ -1,19 +1,28 @@
import request2 from "@/sheep/request2"; import request from "@/sheep/request";
const SeckillApi = { const SeckillApi = {
// 获得秒杀时间段列表 // 获得秒杀时间段列表
getSeckillConfigList: () => { getSeckillConfigList: () => {
return request2({ url: 'promotion/seckill-config/list', method: 'GET' }); return request({
url: '/app-api/promotion/seckill-config/list',
method: 'GET'
});
}, },
// 获得当前秒杀活动 // 获得当前秒杀活动
getNowSeckillActivity: () => { getNowSeckillActivity: () => {
return request2({ url: 'promotion/seckill-activity/get-now', method: 'GET' }); return request({
url: '/app-api/promotion/seckill-activity/get-now',
method: 'GET'
});
}, },
// 获得秒杀活动分页 // 获得秒杀活动分页
getSeckillActivityPage: () => { getSeckillActivityPage: () => {
return request2({ url: 'promotion/seckill-activity/page', method: 'GET' }); return request({
url: '/app-api/promotion/seckill-activity/page',
method: 'GET'
});
}, },
/** /**
@ -22,10 +31,12 @@ const SeckillApi = {
* @return {*} * @return {*}
*/ */
getSeckillActivity: (id) => { getSeckillActivity: (id) => {
return request2({ return request({
url: 'promotion/seckill-activity/get-detail', url: '/app-api/promotion/seckill-activity/get-detail',
method: 'GET', method: 'GET',
params: { id } params: {
id
}
}); });
} }
} }

View File

@ -1,11 +1,10 @@
import request from '@/sheep/request'; import request from '@/sheep/request';
import request2 from '@/sheep/request2';
import $platform from '@/sheep/platform'; import $platform from '@/sheep/platform';
export default { export default {
getUnused: () => getUnused: () =>
request2({ request({
url: 'promotion/coupon/get-unused-count', url: '/app-api/promotion/coupon/get-unused-count',
method: 'GET', method: 'GET',
custom: { custom: {
showLoading: false, showLoading: false,
@ -13,8 +12,8 @@ export default {
}, },
}), }),
profile: () => profile: () =>
request2({ request({
url: 'member/user/get', url: '/app-api/member/user/get',
method: 'GET', method: 'GET',
custom: { custom: {
showLoading: false, showLoading: false,
@ -22,7 +21,7 @@ export default {
}, },
}), }),
balance: () => balance: () =>
request2({ request({
url: '/app-api/pay/wallet/get', url: '/app-api/pay/wallet/get',
method: 'GET', method: 'GET',
custom: { custom: {
@ -30,28 +29,9 @@ export default {
auth: true, auth: true,
}, },
}), }),
// profile: () =>
// request({
// url: '/user/api/user/profile',
// method: 'GET',
// custom: {
// showLoading: false,
// auth: true,
// },
// }),
// update: (data) =>
// request({
// url: '/user/api/user/update',
// method: 'POST',
// custom: {
// showSuccess: true,
// auth: true,
// },
// data,
// }),
update: (data) => update: (data) =>
request2({ request({
url: 'member/user/update', url: '/app-api/member/user/update',
method: 'PUT', method: 'PUT',
custom: { custom: {
showSuccess: true, showSuccess: true,
@ -196,90 +176,48 @@ export default {
}), }),
address: { address: {
// default: () =>
// request({
// url: 'user/address/default',
// method: 'GET',
// custom: {
// showError: false,
// },
// }),
default: () => default: () =>
request2({ request({
url: 'member/address/get-default', url: '/app-api/member/address/get-default',
method: 'GET', method: 'GET',
custom: { custom: {
showError: false, showError: false,
}, },
}), }),
list: () => list: () =>
request2({ request({
url: 'member/address/list', url: '/app-api/member/address/list',
method: 'GET', method: 'GET',
custom: {}, custom: {},
}), }),
// list: () =>
// request({
// url: 'user/address',
// method: 'GET',
// custom: {},
// }),
create: (data) => create: (data) =>
request2({ request({
url: 'member/address/create', url: '/app-api/member/address/create',
method: 'POST', method: 'POST',
data, data,
custom: { custom: {
showSuccess: true, showSuccess: true,
}, },
}), }),
// create: (data) =>
// request({
// url: 'user/address',
// method: 'POST',
// data,
// custom: {
// showSuccess: true,
// },
// }),
update: (data) => update: (data) =>
request2({ request({
url: 'member/address/update', url: '/app-api/member/address/update',
method: 'PUT', method: 'PUT',
data, data,
custom: { custom: {
showSuccess: true, showSuccess: true,
}, },
}), }),
// update: (id, data) =>
// request({
// url: 'user/address/' + id,
// method: 'PUT',
// data,
// custom: {
// showSuccess: true,
// },
// }),
detail: (id) => detail: (id) =>
request2({ request({
url: 'member/address/get?id=' + id, url: '/app-api/member/address/get?id=' + id,
method: 'GET', method: 'GET',
}), }),
// detail: (id) =>
// request({
// url: 'user/address/' + id,
// method: 'GET',
// }),
delete: (id) => delete: (id) =>
request2({ request({
url: 'member/address/delete?id=' + id, url: '/app-api/member/address/delete?id=' + id,
method: 'DELETE', method: 'DELETE',
}), }),
// delete: (id) =>
// request({
// url: 'user/address/' + id,
// method: 'DELETE',
// }),
}, },
invoice: { invoice: {
list: () => list: () =>
@ -319,17 +257,29 @@ export default {
}, },
favorite: { favorite: {
list: (params) => list: (params) =>
request2({ request({
url: 'product/favorite/page', url: '/app-api/product/favorite/page',
method: 'GET', method: 'GET',
params, params,
}), }),
do: (id) => do: (id) =>
request({ request({
url: 'user/goodsLog/favorite', url: '/app-api/product/favorite/create',
method: 'POST', method: 'POST',
data: { data: {
goods_id: id, spuId: id,
},
custom: {
showSuccess: true,
auth: true,
},
}),
dos: (id) =>
request({
url: '/app-api/product/favorite/delete',
method: 'DELETE',
data: {
spuId: id,
}, },
custom: { custom: {
showSuccess: true, showSuccess: true,
@ -338,8 +288,8 @@ export default {
}), }),
// 取消收藏 // 取消收藏
cancel: (id) => cancel: (id) =>
request2({ request({
url: 'product/favorite/delete-list', url: '/app-api/product/favorite/delete-list',
method: 'DELETE', method: 'DELETE',
data: { data: {
spuIds: id.split(',').map(item => item * 1), spuIds: id.split(',').map(item => item * 1),
@ -350,18 +300,6 @@ export default {
auth: true, auth: true,
}, },
}), }),
// cancel: (id) =>
// request({
// url: 'user/goodsLog/favorite',
// method: 'POST',
// data: {
// goods_ids: id,
// },
// custom: {
// showSuccess: true,
// auth: true,
// },
// }),
}, },
view: { view: {
list: (params) => list: (params) =>
@ -383,28 +321,21 @@ export default {
}, },
wallet: { wallet: {
log: (params) => log: (params) =>
request2({ request({
// url: 'member/point/record/page', // url: 'member/point/record/page',
url: 'pay/wallet-transaction/page', url: '/app-api/pay/wallet-transaction/page',
method: 'GET', method: 'GET',
params, params,
custom: {}, custom: {},
}), }),
log2: (params) => log2: (params) =>
request2({ request({
url: 'member/point/record/page', url: '/app-api/member/point/record/page',
// url: 'pay/wallet-transaction/page', // url: 'pay/wallet-transaction/page',
method: 'GET', method: 'GET',
params, params,
custom: {}, custom: {},
}), }),
// log: (params) =>
// request({
// url: '/user/api/walletLog',
// method: 'GET',
// params,
// custom: {},
// }),
}, },
account: { account: {
info: (params) => info: (params) =>
@ -429,18 +360,9 @@ export default {
}), }),
}, },
//数量接口 //数量接口
// data: () =>
// request({
// url: 'user/user/data',
// method: 'GET',
// custom: {
// showLoading: false,
// auth: true,
// },
// }),
data: () => data: () =>
request2({ request({
url: 'trade/order/get-count', url: '/app-api/trade/order/get-count',
method: 'GET', method: 'GET',
custom: { custom: {
showLoading: false, showLoading: false,
@ -448,8 +370,8 @@ export default {
}, },
}), }),
data2: () => data2: () =>
request2({ request({
url: 'trade/after-sale/get-applying-count', url: '/app-api/trade/after-sale/get-applying-count',
method: 'GET', method: 'GET',
custom: { custom: {
showLoading: false, showLoading: false,

View File

@ -1,32 +1,17 @@
<template> <template>
<su-popup <su-popup :show="show" type="bottom" round="20" @close="emits('close')" showClose backgroundColor="#f2f2f2">
:show="show"
type="bottom"
round="20"
@close="emits('close')"
showClose
backgroundColor="#f2f2f2"
>
<view class="model-box"> <view class="model-box">
<view class="title ss-m-t-16 ss-m-l-20 ss-flex">优惠券</view> <view class="title ss-m-t-16 ss-m-l-20 ss-flex">优惠券</view>
<scroll-view <scroll-view class="model-content" scroll-y :scroll-with-animation="false" :enable-back-to-top="true">
class="model-content"
scroll-y
:scroll-with-animation="false"
:enable-back-to-top="true"
>
<view class="subtitle ss-m-l-20">可使用优惠券</view> <view class="subtitle ss-m-l-20">可使用优惠券</view>
<view v-for="item in state.couponInfo" :key="item.id"> <view v-for="item in state.couponInfo" :key="item.id">
<s-coupon-list :data="item"> <s-coupon-list :data="item">
<template #default> <template #default>
<button <button class="ss-reset-button card-btn ss-flex ss-row-center ss-col-center" :class="
class="ss-reset-button card-btn ss-flex ss-row-center ss-col-center"
:class="
item.get_status != 'can_get' && item.get_status != 'can_use' ? 'boder-btn' : '' item.get_status != 'can_get' && item.get_status != 'can_use' ? 'boder-btn' : ''
" " @click.stop="getBuy(item.id)">
@click.stop="getBuy(item.id)" <!-- 此处对接领取优惠券先将限制解除 -->
:disabled="item.get_status != 'can_get' && item.get_status != 'can_use'" <!-- :disabled="item.get_status != 'can_get' && item.get_status != 'can_use'" -->
>
{{ item.get_status_text }} {{ item.get_status_text }}
</button> </button>
</template> </template>
@ -37,11 +22,14 @@
</su-popup> </su-popup>
</template> </template>
<script setup> <script setup>
import { computed, reactive } from 'vue'; import {
computed,
reactive
} from 'vue';
const props = defineProps({ const props = defineProps({
modelValue: { modelValue: {
type: Object, type: Object,
default() {}, default () {},
}, },
show: { show: {
type: Boolean, type: Boolean,
@ -55,6 +43,7 @@
couponId: '', couponId: '',
}); });
const getBuy = (id) => { const getBuy = (id) => {
console.log('应该是详情页领取优惠券')
emits('get', id); emits('get', id);
}; };
// //
@ -62,26 +51,31 @@
<style lang="scss" scoped> <style lang="scss" scoped>
.model-box { .model-box {
height: 60vh; height: 60vh;
.title { .title {
font-size: 36rpx; font-size: 36rpx;
height: 80rpx; height: 80rpx;
font-weight: bold; font-weight: bold;
color: #333333; color: #333333;
} }
.subtitle { .subtitle {
font-size: 26rpx; font-size: 26rpx;
font-weight: 500; font-weight: 500;
color: #333333; color: #333333;
} }
} }
.model-content { .model-content {
height: 54vh; height: 54vh;
} }
.modal-footer { .modal-footer {
width: 100%; width: 100%;
height: 120rpx; height: 120rpx;
background: #fff; background: #fff;
} }
.confirm-btn { .confirm-btn {
width: 710rpx; width: 710rpx;
margin-left: 20rpx; margin-left: 20rpx;
@ -90,6 +84,7 @@
border-radius: 40rpx; border-radius: 40rpx;
color: #fff; color: #fff;
} }
// //
.card-btn { .card-btn {
// width: 144rpx; // width: 144rpx;
@ -101,6 +96,7 @@
font-size: 24rpx; font-size: 24rpx;
font-weight: 400; font-weight: 400;
} }
.boder-btn { .boder-btn {
background: linear-gradient(90deg, var(--ui-BG-Main-opacity-4), var(--ui-BG-Main-light)); background: linear-gradient(90deg, var(--ui-BG-Main-opacity-4), var(--ui-BG-Main-light));
color: #fff !important; color: #fff !important;

View File

@ -1,13 +1,9 @@
<template> <template>
<view class="ss-m-20" :style="{ opacity: disabled ? '0.5' : '1' }"> <view class="ss-m-20" :style="{ opacity: disabled ? '0.5' : '1' }">
<view class="content"> <view class="content">
<!-- <view <view class="tag ss-flex ss-row-center" :class="
class="tag ss-flex ss-row-center"
:class="
data.status == 'expired' || data.status == 'used' ? 'disabled-bg-color' : 'info-bg-color' data.status == 'expired' || data.status == 'used' ? 'disabled-bg-color' : 'info-bg-color'
" ">{{ data.type_text }}</view>
>{{ data.type_text }}</view
> -->
<view class="title ss-m-x-30 ss-p-t-18"> <view class="title ss-m-x-30 ss-p-t-18">
<view class="ss-flex ss-row-between"> <view class="ss-flex ss-row-between">
<view class="value-text ss-flex-1 ss-m-r-10" :class=" <view class="value-text ss-flex-1 ss-m-r-10" :class="

View File

@ -55,7 +55,8 @@ const http = new Request({
method: 'GET', method: 'GET',
header: { header: {
Accept: 'text/json', Accept: 'text/json',
'Content-Type': 'application/json;charset=UTF-8', 'Content-Type': 'application/json',
// ;charset=UTF-8
platform: $platform.name, platform: $platform.name,
}, },
// #ifdef APP-PLUS // #ifdef APP-PLUS
@ -97,6 +98,7 @@ http.interceptors.request.use(
config.header['tenant-id'] = '1'; config.header['tenant-id'] = '1';
config.header['Authorization'] = 'Bearer test247'; config.header['Authorization'] = 'Bearer test247';
} }
// console.log(config, '看参数')
return config; return config;
}, },
(error) => { (error) => {

View File

@ -5,7 +5,9 @@
// 配置 // 配置
const config = { const config = {
// 信任的标签(保持标签名不变) // 信任的标签(保持标签名不变)
trustTags: makeMap('a,abbr,ad,audio,b,blockquote,br,code,col,colgroup,dd,del,dl,dt,div,em,fieldset,h1,h2,h3,h4,h5,h6,hr,i,img,ins,label,legend,li,ol,p,q,ruby,rt,source,span,strong,sub,sup,table,tbody,td,tfoot,th,thead,tr,title,ul,video'), trustTags: makeMap(
'a,abbr,ad,audio,b,blockquote,br,code,col,colgroup,dd,del,dl,dt,div,em,fieldset,h1,h2,h3,h4,h5,h6,hr,i,img,ins,label,legend,li,ol,p,q,ruby,rt,source,span,strong,sub,sup,table,tbody,td,tfoot,th,thead,tr,title,ul,video'
),
// 块级标签(转为 div其他的非信任标签转为 span // 块级标签(转为 div其他的非信任标签转为 span
blockTags: makeMap('address,article,aside,body,caption,center,cite,footer,header,html,nav,pre,section'), blockTags: makeMap('address,article,aside,body,caption,center,cite,footer,header,html,nav,pre,section'),
@ -16,10 +18,14 @@ const config = {
// #endif // #endif
// 要移除的标签 // 要移除的标签
ignoreTags: makeMap('area,base,canvas,embed,frame,head,iframe,input,link,map,meta,param,rp,script,source,style,textarea,title,track,wbr'), ignoreTags: makeMap(
'area,base,canvas,embed,frame,head,iframe,input,link,map,meta,param,rp,script,source,style,textarea,title,track,wbr'
),
// 自闭合的标签 // 自闭合的标签
voidTags: makeMap('area,base,br,col,circle,ellipse,embed,frame,hr,img,input,line,link,meta,param,path,polygon,rect,source,track,use,wbr'), voidTags: makeMap(
'area,base,br,col,circle,ellipse,embed,frame,hr,img,input,line,link,meta,param,path,polygon,rect,source,track,use,wbr'
),
// html 实体 // html 实体
entities: { entities: {
@ -74,7 +80,7 @@ const config = {
repeatdur: 'repeatDur' repeatdur: 'repeatDur'
} }
} }
const tagSelector={} const tagSelector = {}
const { const {
windowWidth, windowWidth,
// #ifdef MP-WEIXIN // #ifdef MP-WEIXIN
@ -99,7 +105,7 @@ config.ignoreTags.style = undefined
* @description 创建 map * @description 创建 map
* @param {String} str 逗号分隔 * @param {String} str 逗号分隔
*/ */
function makeMap (str) { function makeMap(str) {
const map = Object.create(null) const map = Object.create(null)
const list = str.split(',') const list = str.split(',')
for (let i = list.length; i--;) { for (let i = list.length; i--;) {
@ -114,7 +120,7 @@ function makeMap (str) {
* @param {Boolean} amp 要不要解码 &amp; * @param {Boolean} amp 要不要解码 &amp;
* @returns {String} 解码后的字符串 * @returns {String} 解码后的字符串
*/ */
function decodeEntity (str, amp) { function decodeEntity(str, amp) {
let i = str.indexOf('&') let i = str.indexOf('&')
while (i !== -1) { while (i !== -1) {
const j = str.indexOf(';', i + 3) const j = str.indexOf(';', i + 3)
@ -142,10 +148,11 @@ function decodeEntity (str, amp) {
* @description 合并多个块级标签加快长内容渲染 * @description 合并多个块级标签加快长内容渲染
* @param {Array} nodes 要合并的标签数组 * @param {Array} nodes 要合并的标签数组
*/ */
function mergeNodes (nodes) { function mergeNodes(nodes) {
let i = nodes.length - 1 let i = nodes.length - 1
for (let j = i; j >= -1; j--) { for (let j = i; j >= -1; j--) {
if (j === -1 || nodes[j].c || !nodes[j].name || (nodes[j].name !== 'div' && nodes[j].name !== 'p' && nodes[j].name[0] !== 'h') || (nodes[j].attrs.style || '').includes('inline')) { if (j === -1 || nodes[j].c || !nodes[j].name || (nodes[j].name !== 'div' && nodes[j].name !== 'p' && nodes[j]
.name[0] !== 'h') || (nodes[j].attrs.style || '').includes('inline')) {
if (i - j >= 5) { if (i - j >= 5) {
nodes.splice(j + 1, i - j, { nodes.splice(j + 1, i - j, {
name: 'div', name: 'div',
@ -162,7 +169,7 @@ function mergeNodes (nodes) {
* @description html 解析器 * @description html 解析器
* @param {Object} vm 组件实例 * @param {Object} vm 组件实例
*/ */
function Parser (vm) { function Parser(vm) {
this.options = vm || {} this.options = vm || {}
this.tagStyle = Object.assign({}, config.tagStyle, this.options.tagStyle) this.tagStyle = Object.assign({}, config.tagStyle, this.options.tagStyle)
this.imgList = vm.imgList || [] this.imgList = vm.imgList || []
@ -171,14 +178,15 @@ function Parser (vm) {
this.attrs = Object.create(null) this.attrs = Object.create(null)
this.stack = [] this.stack = []
this.nodes = [] this.nodes = []
this.pre = (this.options.containerStyle || '').includes('white-space') && this.options.containerStyle.includes('pre') ? 2 : 0 this.pre = (this.options.containerStyle || '').includes('white-space') && this.options.containerStyle.includes(
'pre') ? 2 : 0
} }
/** /**
* @description 执行解析 * @description 执行解析
* @param {String} content 要解析的文本 * @param {String} content 要解析的文本
*/ */
Parser.prototype.parse = function (content) { Parser.prototype.parse = function(content) {
// 插件处理 // 插件处理
for (let i = this.plugins.length; i--;) { for (let i = this.plugins.length; i--;) {
if (this.plugins[i].onUpdate) { if (this.plugins[i].onUpdate) {
@ -200,7 +208,7 @@ Parser.prototype.parse = function (content) {
/** /**
* @description 将标签暴露出来不被 rich-text 包含 * @description 将标签暴露出来不被 rich-text 包含
*/ */
Parser.prototype.expose = function () { Parser.prototype.expose = function() {
// #ifndef APP-PLUS-NVUE // #ifndef APP-PLUS-NVUE
for (let i = this.stack.length; i--;) { for (let i = this.stack.length; i--;) {
const item = this.stack[i] const item = this.stack[i]
@ -215,7 +223,7 @@ Parser.prototype.expose = function () {
* @param {Object} node 要处理的标签 * @param {Object} node 要处理的标签
* @returns {Boolean} 是否要移除此标签 * @returns {Boolean} 是否要移除此标签
*/ */
Parser.prototype.hook = function (node) { Parser.prototype.hook = function(node) {
for (let i = this.plugins.length; i--;) { for (let i = this.plugins.length; i--;) {
if (this.plugins[i].onParse && this.plugins[i].onParse(node, this) === false) { if (this.plugins[i].onParse && this.plugins[i].onParse(node, this) === false) {
return false return false
@ -229,7 +237,7 @@ Parser.prototype.hook = function (node) {
* @param {String} url 需要拼接的链接 * @param {String} url 需要拼接的链接
* @returns {String} 拼接后的链接 * @returns {String} 拼接后的链接
*/ */
Parser.prototype.getUrl = function (url) { Parser.prototype.getUrl = function(url) {
const domain = this.options.domain const domain = this.options.domain
if (url[0] === '/') { if (url[0] === '/') {
if (url[1] === '/') { if (url[1] === '/') {
@ -238,13 +246,15 @@ Parser.prototype.getUrl = function (url) {
} else if (domain) { } else if (domain) {
// 否则补充整个域名 // 否则补充整个域名
url = domain + url url = domain + url
} /* #ifdef APP-PLUS */ else { } /* #ifdef APP-PLUS */
else {
url = plus.io.convertLocalFileSystemURL(url) url = plus.io.convertLocalFileSystemURL(url)
} /* #endif */ } /* #endif */
} else if (!url.includes('data:') && !url.includes('://')) { } else if (!url.includes('data:') && !url.includes('://')) {
if (domain) { if (domain) {
url = domain + '/' + url url = domain + '/' + url
} /* #ifdef APP-PLUS */ else { } /* #ifdef APP-PLUS */
else {
url = plus.io.convertLocalFileSystemURL(url) url = plus.io.convertLocalFileSystemURL(url)
} /* #endif */ } /* #endif */
} }
@ -256,7 +266,7 @@ Parser.prototype.getUrl = function (url) {
* @param {Object} node 标签 * @param {Object} node 标签
* @returns {Object} * @returns {Object}
*/ */
Parser.prototype.parseStyle = function (node) { Parser.prototype.parseStyle = function(node) {
const attrs = node.attrs const attrs = node.attrs
const list = (this.tagStyle[node.name] || '').split(';').concat((attrs.style || '').split(';')) const list = (this.tagStyle[node.name] || '').split(';').concat((attrs.style || '').split(';'))
const styleObj = {} const styleObj = {}
@ -317,7 +327,7 @@ Parser.prototype.parseStyle = function (node) {
* @param {String} name 标签名 * @param {String} name 标签名
* @private * @private
*/ */
Parser.prototype.onTagName = function (name) { Parser.prototype.onTagName = function(name) {
this.tagName = this.xml ? name : name.toLowerCase() this.tagName = this.xml ? name : name.toLowerCase()
if (this.tagName === 'svg') { if (this.tagName === 'svg') {
this.xml = (this.xml || 0) + 1 // svg 标签内大小写敏感 this.xml = (this.xml || 0) + 1 // svg 标签内大小写敏感
@ -329,7 +339,7 @@ Parser.prototype.onTagName = function (name) {
* @param {String} name 属性名 * @param {String} name 属性名
* @private * @private
*/ */
Parser.prototype.onAttrName = function (name) { Parser.prototype.onAttrName = function(name) {
name = this.xml ? name : name.toLowerCase() name = this.xml ? name : name.toLowerCase()
if (name.substr(0, 5) === 'data-') { if (name.substr(0, 5) === 'data-') {
if (name === 'data-src' && !this.attrs.src) { if (name === 'data-src' && !this.attrs.src) {
@ -353,7 +363,8 @@ Parser.prototype.onAttrName = function (name) {
* @param {String} val 属性值 * @param {String} val 属性值
* @private * @private
*/ */
Parser.prototype.onAttrVal = function (val) { Parser.prototype.onAttrVal = function(val) {
// console.log(val, '解码转码')
const name = this.attrName || '' const name = this.attrName || ''
if (name === 'style' || name === 'href') { if (name === 'style' || name === 'href') {
// 部分属性进行实体解码 // 部分属性进行实体解码
@ -371,7 +382,7 @@ Parser.prototype.onAttrVal = function (val) {
* @param {Boolean} selfClose 是否有自闭合标识 /> * @param {Boolean} selfClose 是否有自闭合标识 />
* @private * @private
*/ */
Parser.prototype.onOpenTag = function (selfClose) { Parser.prototype.onOpenTag = function(selfClose) {
// 拼装 node // 拼装 node
const node = Object.create(null) const node = Object.create(null)
node.name = this.tagName node.name = this.tagName
@ -397,9 +408,11 @@ Parser.prototype.onOpenTag = function (selfClose) {
// #ifndef H5 || APP-PLUS // #ifndef H5 || APP-PLUS
const src = attrs.src || '' const src = attrs.src || ''
// 按照后缀名和 type 将 embed 转为 video 或 audio // 按照后缀名和 type 将 embed 转为 video 或 audio
if (src.includes('.mp4') || src.includes('.3gp') || src.includes('.m3u8') || (attrs.type || '').includes('video')) { if (src.includes('.mp4') || src.includes('.3gp') || src.includes('.m3u8') || (attrs.type || '').includes(
'video')) {
node.name = 'video' node.name = 'video'
} else if (src.includes('.mp3') || src.includes('.wav') || src.includes('.aac') || src.includes('.m4a') || (attrs.type || '').includes('audio')) { } else if (src.includes('.mp3') || src.includes('.wav') || src.includes('.aac') || src.includes('.m4a') || (
attrs.type || '').includes('audio')) {
node.name = 'audio' node.name = 'audio'
} }
if (attrs.autostart) { if (attrs.autostart) {
@ -439,7 +452,9 @@ Parser.prototype.onOpenTag = function (selfClose) {
// 通过 base 标签设置主域名 // 通过 base 标签设置主域名
if (node.name === 'base' && !this.options.domain) { if (node.name === 'base' && !this.options.domain) {
this.options.domain = attrs.href this.options.domain = attrs.href
} /* #ifndef APP-PLUS-NVUE */ else if (node.name === 'source' && parent && (parent.name === 'video' || parent.name === 'audio') && attrs.src) { } /* #ifndef APP-PLUS-NVUE */
else if (node.name === 'source' && parent && (parent.name === 'video' || parent.name === 'audio') &&
attrs.src) {
// 设置 source 标签(仅父节点为 video 或 audio 时有效) // 设置 source 标签(仅父节点为 video 或 audio 时有效)
parent.src.push(attrs.src) parent.src.push(attrs.src)
} /* #endif */ } /* #endif */
@ -476,7 +491,8 @@ Parser.prototype.onOpenTag = function (selfClose) {
} }
// #ifndef H5 || APP-PLUS // #ifndef H5 || APP-PLUS
const style = item.attrs.style || '' const style = item.attrs.style || ''
if (style.includes('flex:') && !style.includes('flex:0') && !style.includes('flex: 0') && (!styleObj.width || parseInt(styleObj.width) > 100)) { if (style.includes('flex:') && !style.includes('flex:0') && !style.includes('flex: 0') && (!
styleObj.width || parseInt(styleObj.width) > 100)) {
styleObj.width = '100% !important' styleObj.width = '100% !important'
styleObj.height = '' styleObj.height = ''
for (let j = i + 1; j < this.stack.length; j++) { for (let j = i + 1; j < this.stack.length; j++) {
@ -485,7 +501,8 @@ Parser.prototype.onOpenTag = function (selfClose) {
} else if (style.includes('flex') && styleObj.width === '100%') { } else if (style.includes('flex') && styleObj.width === '100%') {
for (let j = i + 1; j < this.stack.length; j++) { for (let j = i + 1; j < this.stack.length; j++) {
const style = this.stack[j].attrs.style || '' const style = this.stack[j].attrs.style || ''
if (!style.includes(';width') && !style.includes(' width') && style.indexOf('width') !== 0) { if (!style.includes(';width') && !style.includes(' width') && style.indexOf(
'width') !== 0) {
styleObj.width = '' styleObj.width = ''
break break
} }
@ -548,7 +565,8 @@ Parser.prototype.onOpenTag = function (selfClose) {
if (!isNaN(parseInt(styleObj.width))) { if (!isNaN(parseInt(styleObj.width))) {
node.w = 'T' node.w = 'T'
} }
if (!isNaN(parseInt(styleObj.height)) && (!styleObj.height.includes('%') || (parent && (parent.attrs.style || '').includes('height')))) { if (!isNaN(parseInt(styleObj.height)) && (!styleObj.height.includes('%') || (parent && (parent.attrs
.style || '').includes('height')))) {
node.h = 'T' node.h = 'T'
} }
} else if (node.name === 'svg') { } else if (node.name === 'svg') {
@ -569,7 +587,8 @@ Parser.prototype.onOpenTag = function (selfClose) {
} }
// #endif // #endif
} else { } else {
if ((node.name === 'pre' || ((attrs.style || '').includes('white-space') && attrs.style.includes('pre'))) && this.pre !== 2) { if ((node.name === 'pre' || ((attrs.style || '').includes('white-space') && attrs.style.includes('pre'))) &&
this.pre !== 2) {
this.pre = node.pre = 1 this.pre = node.pre = 1
} }
node.children = [] node.children = []
@ -585,7 +604,7 @@ Parser.prototype.onOpenTag = function (selfClose) {
* @param {String} name 标签名 * @param {String} name 标签名
* @private * @private
*/ */
Parser.prototype.onCloseTag = function (name) { Parser.prototype.onCloseTag = function(name) {
// 依次出栈到匹配为止 // 依次出栈到匹配为止
name = this.xml ? name : name.toLowerCase() name = this.xml ? name : name.toLowerCase()
let i let i
@ -612,7 +631,7 @@ Parser.prototype.onCloseTag = function (name) {
* @description 处理标签出栈 * @description 处理标签出栈
* @private * @private
*/ */
Parser.prototype.popNode = function () { Parser.prototype.popNode = function() {
const node = this.stack.pop() const node = this.stack.pop()
let attrs = node.attrs let attrs = node.attrs
const children = node.children const children = node.children
@ -650,7 +669,7 @@ Parser.prototype.popNode = function () {
return return
} }
// #ifdef APP-PLUS-NVUE // #ifdef APP-PLUS-NVUE
(function traversal (node) { (function traversal(node) {
if (node.name) { if (node.name) {
// 调整 svg 的大小写 // 调整 svg 的大小写
node.name = config.svgDict[node.name] || node.name node.name = config.svgDict[node.name] || node.name
@ -671,7 +690,7 @@ Parser.prototype.popNode = function () {
const style = attrs.style const style = attrs.style
attrs.style = '' attrs.style = ''
attrs.xmlns = 'http://www.w3.org/2000/svg'; attrs.xmlns = 'http://www.w3.org/2000/svg';
(function traversal (node) { (function traversal(node) {
if (node.type === 'text') { if (node.type === 'text') {
src += node.text src += node.text
return return
@ -745,7 +764,9 @@ Parser.prototype.popNode = function () {
} else if (size > 7) { } else if (size > 7) {
size = 7 size = 7
} }
styleObj['font-size'] = ['x-small', 'small', 'medium', 'large', 'x-large', 'xx-large', 'xxx-large'][size - 1] styleObj['font-size'] = ['x-small', 'small', 'medium', 'large', 'x-large', 'xx-large', 'xxx-large'][
size - 1
]
} }
attrs.size = undefined attrs.size = undefined
} }
@ -774,7 +795,8 @@ Parser.prototype.popNode = function () {
if (node.name === 'a' || node.name === 'ad' if (node.name === 'a' || node.name === 'ad'
// #ifdef H5 || APP-PLUS // #ifdef H5 || APP-PLUS
|| node.name === 'iframe' // eslint-disable-line ||
node.name === 'iframe' // eslint-disable-line
// #endif // #endif
) { ) {
this.expose() this.expose()
@ -790,7 +812,8 @@ Parser.prototype.popNode = function () {
} }
} }
if (this.options.pauseVideo) { if (this.options.pauseVideo) {
str += ' onplay="this.dispatchEvent(new CustomEvent(\'vplay\',{bubbles:!0}));for(var e=document.getElementsByTagName(\'video\'),t=0;t<e.length;t++)e[t]!=this&&e[t].pause()"' str +=
' onplay="this.dispatchEvent(new CustomEvent(\'vplay\',{bubbles:!0}));for(var e=document.getElementsByTagName(\'video\'),t=0;t<e.length;t++)e[t]!=this&&e[t].pause()"'
} }
str += '>' str += '>'
for (let i = 0; i < node.src.length; i++) { for (let i = 0; i < node.src.length; i++) {
@ -852,7 +875,7 @@ Parser.prototype.popNode = function () {
const cells = [] // 保存新的单元格 const cells = [] // 保存新的单元格
const map = {}; // 被合并单元格占用的格子 const map = {}; // 被合并单元格占用的格子
(function traversal (nodes) { (function traversal(nodes) {
for (let i = 0; i < nodes.length; i++) { for (let i = 0; i < nodes.length; i++) {
if (nodes[i].name === 'tr') { if (nodes[i].name === 'tr') {
trList.push(nodes[i]) trList.push(nodes[i])
@ -907,7 +930,9 @@ Parser.prototype.popNode = function () {
style += ';justify-content: right' style += ';justify-content: right'
} }
} }
style = (border ? `;border:${border}px ${borderstyle || 'solid'} ${bordercolor || 'gray'}` + (spacing ? '' : ';border-right:0;border-bottom:0') : '') + (padding ? `;padding:${padding}px` : '') + ';' + style style = (border ? `;border:${border}px ${borderstyle || 'solid'} ${bordercolor || 'gray'}` +
(spacing ? '' : ';border-right:0;border-bottom:0') : '') + (padding ?
`;padding:${padding}px` : '') + ';' + style
// 处理列合并 // 处理列合并
if (td.attrs.colspan) { if (td.attrs.colspan) {
style += `;grid-column-start:${col};grid-column-end:${col + parseInt(td.attrs.colspan)}` style += `;grid-column-start:${col};grid-column-end:${col + parseInt(td.attrs.colspan)}`
@ -955,12 +980,13 @@ Parser.prototype.popNode = function () {
} }
if (border || padding) { if (border || padding) {
// 遍历 // 遍历
(function traversal (nodes) { (function traversal(nodes) {
for (let i = 0; i < nodes.length; i++) { for (let i = 0; i < nodes.length; i++) {
const td = nodes[i] const td = nodes[i]
if (td.name === 'th' || td.name === 'td') { if (td.name === 'th' || td.name === 'td') {
if (border) { if (border) {
td.attrs.style = `border:${border}px ${borderstyle || 'solid'} ${bordercolor || 'gray'};${td.attrs.style || ''}` td.attrs.style =
`border:${border}px ${borderstyle || 'solid'} ${bordercolor || 'gray'};${td.attrs.style || ''}`
} }
if (padding) { if (padding) {
td.attrs.style = `padding:${padding}px;${td.attrs.style || ''}` td.attrs.style = `padding:${padding}px;${td.attrs.style || ''}`
@ -1011,12 +1037,13 @@ Parser.prototype.popNode = function () {
} }
} }
} else if (node.c) { } else if (node.c) {
(function traversal (node) { (function traversal(node) {
node.c = 2 node.c = 2
for (let i = node.children.length; i--;) { for (let i = node.children.length; i--;) {
const child = node.children[i] const child = node.children[i]
// #ifdef (MP-WEIXIN || MP-QQ || APP-PLUS || MP-360) && VUE3 // #ifdef (MP-WEIXIN || MP-QQ || APP-PLUS || MP-360) && VUE3
if (child.name && (config.inlineTags[child.name] || ((child.attrs.style || '').includes('inline') && child.children)) && !child.c) { if (child.name && (config.inlineTags[child.name] || ((child.attrs.style || '').includes(
'inline') && child.children)) && !child.c) {
traversal(child) traversal(child)
} }
// #endif // #endif
@ -1037,13 +1064,16 @@ Parser.prototype.popNode = function () {
} }
} }
// flex 布局时部分样式需要提取到 rich-text 外层 // flex 布局时部分样式需要提取到 rich-text 外层
const flex = parent && ((parent.attrs.style || '').includes('flex') || (parent.attrs.style || '').includes('grid')) const flex = parent && ((parent.attrs.style || '').includes('flex') || (parent.attrs.style || '').includes(
'grid'))
// #ifdef MP-WEIXIN // #ifdef MP-WEIXIN
// 检查基础库版本 virtualHost 是否可用 // 检查基础库版本 virtualHost 是否可用
&& !(node.c && wx.getNFCAdapter) // eslint-disable-line &&
!(node.c && wx.getNFCAdapter) // eslint-disable-line
// #endif // #endif
// #ifndef MP-WEIXIN || MP-QQ || MP-BAIDU || MP-TOUTIAO // #ifndef MP-WEIXIN || MP-QQ || MP-BAIDU || MP-TOUTIAO
&& !node.c // eslint-disable-line &&
!node.c // eslint-disable-line
// #endif // #endif
if (flex) { if (flex) {
node.f = ';max-width:100%' node.f = ';max-width:100%'
@ -1058,7 +1088,8 @@ Parser.prototype.popNode = function () {
if (styleObj[key]) { if (styleObj[key]) {
const val = `;${key}:${styleObj[key].replace(' !important', '')}` const val = `;${key}:${styleObj[key].replace(' !important', '')}`
/* #ifndef APP-PLUS-NVUE */ /* #ifndef APP-PLUS-NVUE */
if (flex && ((key.includes('flex') && key !== 'flex-direction') || key === 'align-self' || key.includes('grid') || styleObj[key][0] === '-' || (key.includes('width') && val.includes('%')))) { if (flex && ((key.includes('flex') && key !== 'flex-direction') || key === 'align-self' || key.includes(
'grid') || styleObj[key][0] === '-' || (key.includes('width') && val.includes('%')))) {
node.f += val node.f += val
if (key === 'width') { if (key === 'width') {
attrs.style += ';width:100%' attrs.style += ';width:100%'
@ -1082,7 +1113,7 @@ Parser.prototype.popNode = function () {
* @description 解析到文本 * @description 解析到文本
* @param {String} text 文本内容 * @param {String} text 文本内容
*/ */
Parser.prototype.onText = function (text) { Parser.prototype.onText = function(text) {
if (!this.pre) { if (!this.pre) {
// 合并空白符 // 合并空白符
let trim = '' let trim = ''
@ -1119,7 +1150,8 @@ Parser.prototype.onText = function (text) {
node.text = decodeEntity(text) node.text = decodeEntity(text)
if (this.hook(node)) { if (this.hook(node)) {
// #ifdef MP-WEIXIN // #ifdef MP-WEIXIN
if (this.options.selectable === 'force' && system.includes('iOS') && !uni.canIUse('rich-text.user-select')) { if (this.options.selectable === 'force' && system.includes('iOS') && !uni.canIUse(
'rich-text.user-select')) {
this.expose() this.expose()
} }
// #endif // #endif
@ -1132,7 +1164,7 @@ Parser.prototype.onText = function (text) {
* @description html 词法分析器 * @description html 词法分析器
* @param {Object} handler 高层处理器 * @param {Object} handler 高层处理器
*/ */
function Lexer (handler) { function Lexer(handler) {
this.handler = handler this.handler = handler
} }
@ -1140,7 +1172,7 @@ function Lexer (handler) {
* @description 执行解析 * @description 执行解析
* @param {String} content 要解析的文本 * @param {String} content 要解析的文本
*/ */
Lexer.prototype.parse = function (content) { Lexer.prototype.parse = function(content) {
this.content = content || '' this.content = content || ''
this.i = 0 // 标记解析位置 this.i = 0 // 标记解析位置
this.start = 0 // 标记一个单词的开始位置 this.start = 0 // 标记一个单词的开始位置
@ -1156,7 +1188,7 @@ Lexer.prototype.parse = function (content) {
* @returns {Boolean} 是否闭合 * @returns {Boolean} 是否闭合
* @private * @private
*/ */
Lexer.prototype.checkClose = function (method) { Lexer.prototype.checkClose = function(method) {
const selfClose = this.content[this.i] === '/' const selfClose = this.content[this.i] === '/'
if (this.content[this.i] === '>' || (selfClose && this.content[this.i + 1] === '>')) { if (this.content[this.i] === '>' || (selfClose && this.content[this.i + 1] === '>')) {
if (method) { if (method) {
@ -1184,7 +1216,7 @@ Lexer.prototype.checkClose = function (method) {
* @description 文本状态 * @description 文本状态
* @private * @private
*/ */
Lexer.prototype.text = function () { Lexer.prototype.text = function() {
this.i = this.content.indexOf('<', this.i) // 查找最近的标签 this.i = this.content.indexOf('<', this.i) // 查找最近的标签
if (this.i === -1) { if (this.i === -1) {
// 没有标签了 // 没有标签了
@ -1232,7 +1264,7 @@ Lexer.prototype.text = function () {
* @description 标签名状态 * @description 标签名状态
* @private * @private
*/ */
Lexer.prototype.tagName = function () { Lexer.prototype.tagName = function() {
if (blankChar[this.content[this.i]]) { if (blankChar[this.content[this.i]]) {
// 解析到标签名 // 解析到标签名
this.handler.onTagName(this.content.substring(this.start, this.i)) this.handler.onTagName(this.content.substring(this.start, this.i))
@ -1250,7 +1282,7 @@ Lexer.prototype.tagName = function () {
* @description 属性名状态 * @description 属性名状态
* @private * @private
*/ */
Lexer.prototype.attrName = function () { Lexer.prototype.attrName = function() {
let c = this.content[this.i] let c = this.content[this.i]
if (blankChar[c] || c === '=') { if (blankChar[c] || c === '=') {
// 解析到属性名 // 解析到属性名
@ -1285,7 +1317,7 @@ Lexer.prototype.attrName = function () {
* @description 属性值状态 * @description 属性值状态
* @private * @private
*/ */
Lexer.prototype.attrVal = function () { Lexer.prototype.attrVal = function() {
const c = this.content[this.i] const c = this.content[this.i]
const len = this.content.length const len = this.content.length
if (c === '"' || c === "'") { if (c === '"' || c === "'") {
@ -1315,7 +1347,7 @@ Lexer.prototype.attrVal = function () {
* @returns {String} 结束的标签名 * @returns {String} 结束的标签名
* @private * @private
*/ */
Lexer.prototype.endTag = function () { Lexer.prototype.endTag = function() {
const c = this.content[this.i] const c = this.content[this.i]
if (blankChar[c] || c === '>' || c === '/') { if (blankChar[c] || c === '>' || c === '/') {
this.handler.onCloseTag(this.content.substring(this.start, this.i)) this.handler.onCloseTag(this.content.substring(this.start, this.i))

View File

@ -1,4 +1,6 @@
import { loadEnv } from 'vite'; import {
loadEnv
} from 'vite';
import uni from '@dcloudio/vite-plugin-uni'; import uni from '@dcloudio/vite-plugin-uni';
import path from 'path'; import path from 'path';
// import viteCompression from 'vite-plugin-compression'; // import viteCompression from 'vite-plugin-compression';