forked from wangziqi/gongxue-base
test: add taro h5 interaction smoke
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
||||
loadSchoolRecommendationReports,
|
||||
type SchoolRecommendationReport,
|
||||
} from '@/services/ai';
|
||||
import { isH5Runtime } from '@/env';
|
||||
import { loadProfile, type StudentProfile } from '@/services/profile';
|
||||
import '../student.css';
|
||||
|
||||
@@ -25,7 +26,7 @@ function recommendationRows(report: SchoolRecommendationReport | null) {
|
||||
}
|
||||
|
||||
function saveExportFile(fileName: string, content: string, mimeType: string) {
|
||||
if (process.env.TARO_ENV === 'h5' && typeof window !== 'undefined' && typeof document !== 'undefined') {
|
||||
if (isH5Runtime() && typeof window !== 'undefined' && typeof document !== 'undefined') {
|
||||
const blob = new Blob([content], { type: mimeType });
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
const link = document.createElement('a');
|
||||
@@ -94,7 +95,7 @@ export default function StudentAiSchoolPage() {
|
||||
const payload = await exportSchoolRecommendationReport(current.id, format);
|
||||
if (!payload.item?.contentText) throw new Error('后端未返回报告内容');
|
||||
saveExportFile(payload.item.fileName, payload.item.contentText, payload.item.mimeType);
|
||||
if (process.env.TARO_ENV === 'h5') Taro.showToast({ title: '报告已导出', icon: 'success' });
|
||||
if (isH5Runtime()) Taro.showToast({ title: '报告已导出', icon: 'success' });
|
||||
} catch (nextError) {
|
||||
setError(nextError instanceof Error ? nextError.message : '导出失败');
|
||||
} finally {
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
type ContentAsset,
|
||||
type SignedAssetLink,
|
||||
} from '@/services/catalog';
|
||||
import { isH5Runtime } from '@/env';
|
||||
import '../student.css';
|
||||
|
||||
type PreviewState = {
|
||||
@@ -20,7 +21,7 @@ type PreviewState = {
|
||||
|
||||
function openUrl(url?: string, copiedText = '签名链接已复制,请在浏览器中打开') {
|
||||
if (!url) return;
|
||||
if (process.env.TARO_ENV === 'h5' && typeof window !== 'undefined') {
|
||||
if (isH5Runtime() && typeof window !== 'undefined') {
|
||||
window.open(url, '_blank', 'noopener,noreferrer');
|
||||
return;
|
||||
}
|
||||
@@ -129,10 +130,10 @@ export default function StudentAssetsPage() {
|
||||
<Text className='row-meta'>下载前请确认页面水印和追踪码。签名 URL 不会长期保存,过期后需要重新申请。</Text>
|
||||
</View>
|
||||
) : null}
|
||||
{previewState.kind === 'preview' && process.env.TARO_ENV === 'h5' ? (
|
||||
{previewState.kind === 'preview' && isH5Runtime() ? (
|
||||
<WebView className='asset-preview-iframe' src={previewState.link.url || ''} />
|
||||
) : null}
|
||||
{previewState.kind === 'preview' && process.env.TARO_ENV !== 'h5' ? (
|
||||
{previewState.kind === 'preview' && !isH5Runtime() ? (
|
||||
<View className='asset-download-confirm'>
|
||||
<Text className='row-main'>已获取预览授权</Text>
|
||||
<Text className='row-meta'>当前小程序容器不直接嵌入私有文件。请先确认水印追踪码,再使用外部打开或复制签名链接。</Text>
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
type PaymentCreateResult,
|
||||
type SvipPlan,
|
||||
} from '@/services/commerce';
|
||||
import { isH5Runtime, isWeappRuntime } from '@/env';
|
||||
import { loadProfile, type StudentProfile } from '@/services/profile';
|
||||
import '../student.css';
|
||||
|
||||
@@ -56,7 +57,7 @@ function buildPaymentUrl(result?: PaymentCreateResult) {
|
||||
|
||||
function tryOpenPaymentUrl(url: string) {
|
||||
if (!url) return false;
|
||||
if (process.env.TARO_ENV === 'h5' && typeof window !== 'undefined') {
|
||||
if (isH5Runtime() && typeof window !== 'undefined') {
|
||||
window.location.href = url;
|
||||
return true;
|
||||
}
|
||||
@@ -167,8 +168,8 @@ export default function StudentCheckoutPage() {
|
||||
const paymentPayload = await createPayment({
|
||||
orderNo: nextOrder.orderNo,
|
||||
provider,
|
||||
returnUrl: process.env.TARO_ENV === 'h5' && typeof window !== 'undefined' ? window.location.href : undefined,
|
||||
quitUrl: process.env.TARO_ENV === 'h5' && typeof window !== 'undefined' ? window.location.href : undefined,
|
||||
returnUrl: isH5Runtime() && typeof window !== 'undefined' ? window.location.href : undefined,
|
||||
quitUrl: isH5Runtime() && typeof window !== 'undefined' ? window.location.href : undefined,
|
||||
});
|
||||
setPayment(paymentPayload.item || null);
|
||||
setMessage(provider === 'manual' ? '已生成线下支付记录,请联系教务或客服确认。' : '支付参数已生成,请继续完成支付。');
|
||||
@@ -181,7 +182,7 @@ export default function StudentCheckoutPage() {
|
||||
|
||||
async function handleOpenPayment() {
|
||||
if (!payment) return;
|
||||
if (payment.provider === 'wechat_pay' && process.env.TARO_ENV === 'weapp') {
|
||||
if (payment.provider === 'wechat_pay' && isWeappRuntime()) {
|
||||
const paramsForWeapp = payment.paymentParams || {};
|
||||
Taro.requestPayment(paramsForWeapp as unknown as Taro.requestPayment.Option)
|
||||
.then(() => order?.orderNo ? pollStatus(order.orderNo) : undefined)
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
type PaymentCreateResult,
|
||||
} from '@/services/commerce';
|
||||
import { getTenantContext } from '@/services/api';
|
||||
import { isH5Runtime } from '@/env';
|
||||
import '../student.css';
|
||||
|
||||
function centsToYuan(value?: number | null) {
|
||||
@@ -94,13 +95,13 @@ export default function StudentOrderDetailPage() {
|
||||
const payload = await createPayment({
|
||||
orderNo,
|
||||
provider: provider || detail?.payProvider || status?.payProvider || 'alipay',
|
||||
returnUrl: process.env.TARO_ENV === 'h5' && typeof window !== 'undefined' ? window.location.href : undefined,
|
||||
quitUrl: process.env.TARO_ENV === 'h5' && typeof window !== 'undefined' ? window.location.href : undefined,
|
||||
returnUrl: isH5Runtime() && typeof window !== 'undefined' ? window.location.href : undefined,
|
||||
quitUrl: isH5Runtime() && typeof window !== 'undefined' ? window.location.href : undefined,
|
||||
});
|
||||
const nextPayment = payload.item || null;
|
||||
setPayment(nextPayment);
|
||||
const url = paymentUrl(nextPayment);
|
||||
if (url && process.env.TARO_ENV === 'h5' && typeof window !== 'undefined') {
|
||||
if (url && isH5Runtime() && typeof window !== 'undefined') {
|
||||
window.location.href = url;
|
||||
} else if (url) {
|
||||
await Taro.setClipboardData({ data: url });
|
||||
|
||||
Reference in New Issue
Block a user