Browse Source

add vite plugin

dev
刘嘉炜 1 week ago
parent
commit
c729ff24aa
  1. 8
      src/subpackage/groupon/pages/confirm_order/ticket.vue
  2. 5
      src/subpackage/groupon/pages/list.vue
  3. 27
      tools/generate-package-plugin.js
  4. 11
      vite.config.js

8
src/subpackage/groupon/pages/confirm_order/ticket.vue

@ -29,16 +29,20 @@ onMounted(() =>{
encrypted_codes: ticket?.encrypted_codes ?? '', encrypted_codes: ticket?.encrypted_codes ?? '',
douyin_merchant_pay_amount: ticket?.douyin_merchant_pay_amount ?? '', douyin_merchant_pay_amount: ticket?.douyin_merchant_pay_amount ?? '',
certificate_id: ticket?.certificate_id ?? '', certificate_id: ticket?.certificate_id ?? '',
certificate: ticket?.certificates ?? null,
}) })
}) })
}) })
function pvc_func({ function pvc_func({
appid, brand_id, stadium_id, encrypted_codes, douyin_merchant_pay_amount, certificate_id
appid, brand_id, stadium_id,
encrypted_codes, douyin_merchant_pay_amount,
certificate_id, certificate
}){ }){
jsapiPreVerifyCertificates({ jsapiPreVerifyCertificates({
data: { data: {
appid, brand_id, stadium_id, appid, brand_id, stadium_id,
encrypted_codes, douyin_merchant_pay_amount, certificate_id
encrypted_codes, douyin_merchant_pay_amount,
certificate_id, certificate
}, },
}) })
.then(res=>{ .then(res=>{

5
src/subpackage/groupon/pages/list.vue

@ -77,13 +77,16 @@ function ticketClick(e){
// //
encrypted_codes: certificates?.encrypted_code ?? '', encrypted_codes: certificates?.encrypted_code ?? '',
douyin_merchant_pay_amount: certificates?.amount?.pay_amount ?? 0, douyin_merchant_pay_amount: certificates?.amount?.pay_amount ?? 0,
certificates,
} }
uni.navigateTo({ uni.navigateTo({
url: `/subpackage/groupon/pages/stadiums`, url: `/subpackage/groupon/pages/stadiums`,
success: res => { success: res => {
// eventChannel // eventChannel
res.eventChannel.emit('dataForGrouponStadiums', { ticket: _ticketInfo });
res.eventChannel.emit('dataForGrouponStadiums', {
ticket: _ticketInfo
});
} }
}); });
} }

27
tools/generate-package-plugin.js

@ -0,0 +1,27 @@
import path from 'path';
import fs from 'fs';
/**
* 在构建完成后自动生成 package.json 文件 配置行业 SDK
*
* @param {string} outputDir - 输出目录通常是构建平台对应的输出路径 dist/dev/mp-toutiao
* @param {object} packageContent - 要写入 package.json 的内容对象
* @returns {object} - 一个符合 Vite 插件规范的插件对象
*/
function generatePackageJsonPlugin(outputDir, packageContent) {
return {
name: 'custom-generate-package-json',
apply: 'build',
generateBundle() {
const outputPackageJsonPath = path.resolve(outputDir, 'package.json');
try {
fs.mkdirSync(path.dirname(outputPackageJsonPath), { recursive: true });
fs.writeFileSync(outputPackageJsonPath, JSON.stringify(packageContent, null, 2), 'utf-8');
} catch (error) {
console.error('[package.json] Failed to generate:', error);
}
},
};
}
module.exports = { generatePackageJsonPlugin };

11
vite.config.js

@ -2,6 +2,7 @@ import { defineConfig, 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 { updateJsonFileField } from './tools/json-editor.js'; import { updateJsonFileField } from './tools/json-editor.js';
import { generatePackageJsonPlugin } from './tools/generate-package-plugin.js';
// https://vitejs.dev/config/ // https://vitejs.dev/config/
/** /**
* @param {String} mode development/production * @param {String} mode development/production
@ -9,12 +10,16 @@ import { updateJsonFileField } from './tools/json-editor.js';
export default defineConfig(({ mode = 'development' }) =>{ export default defineConfig(({ mode = 'development' }) =>{
const env = loadEnv(mode, './envs'); const env = loadEnv(mode, './envs');
console.log('current mode:', mode); console.log('current mode:', mode);
const plugins = [ uni() ];
if (process.env.UNI_PLATFORM === 'mp-toutiao'){
// 根据配置文件配置 appid
const manifestPath = path.resolve(__dirname, 'src/manifest.json'); const manifestPath = path.resolve(__dirname, 'src/manifest.json');
updateJsonFileField(manifestPath, ['mp-toutiao', 'appid'], env.VITE_TOUTIAO_APPID); updateJsonFileField(manifestPath, ['mp-toutiao', 'appid'], env.VITE_TOUTIAO_APPID);
// 配置行业sdk
plugins.push(generatePackageJsonPlugin(process.env.UNI_OUTPUT_DIR, { industrySDK: true }));
}
return { return {
plugins: [
uni(),
],
plugins,
define: { define: {
// 抖音小程序不支持该参数 __VUE_OPTIONS_API__ // 抖音小程序不支持该参数 __VUE_OPTIONS_API__
// 会导致 [TMA] TypeError: this.$vm.$callCreatedHook is not a function // 会导致 [TMA] TypeError: this.$vm.$callCreatedHook is not a function

Loading…
Cancel
Save