Skip to content

Commit bc81c9c

Browse files
committed
feat: add vconsole
1 parent dab308b commit bc81c9c

4 files changed

Lines changed: 89 additions & 52 deletions

File tree

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
"@vue/shared": "^3.0.0",
7979
"core-js": "^3.8.3",
8080
"flyio": "^0.6.2",
81-
"t-comm": "^3.1.15",
81+
"t-comm": "^3.3.0",
8282
"vue": ">= 2.6.14 < 2.7",
8383
"vuex": "^3.2.0"
8484
},
@@ -98,6 +98,7 @@
9898
"@novlan/postcss-plugin-remove-selector": "^0.1.6",
9999
"@plugin-light/webpack-plugin-dispatch-script": "^1.0.0",
100100
"@plugin-light/webpack-plugin-dispatch-vue": "^1.0.0",
101+
"@plugin-light/webpack-plugin-gen-version": "^1.0.0",
101102
"@types/webpack-env": "^1.18.8",
102103
"@vue/cli-plugin-babel": "~5.0.0",
103104
"@vue/cli-plugin-typescript": "~5.0.9",

pnpm-lock.yaml

Lines changed: 21 additions & 48 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/pages/home/home.vue

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@
1616
aria-label="TDesign Logo"
1717
/>
1818
</view>
19-
<view class="desc">
19+
<view
20+
class="desc"
21+
@click="onDescTap"
22+
>
2023
TDesign 适配 uni-app 的组件库{{ isSkyline?' (skyline render)':'' }}
2124
<text
2225
v-if="!isSkyline && showTrySkyline"
2326
class="skyline-entry"
24-
@click="goSkyline"
27+
@click.stop="goSkyline"
2528
>
2629
try skyline
2730
</text>
@@ -59,6 +62,8 @@
5962
<script>
6063
import TFooter from '@tdesign/uniapp/footer/footer.vue';
6164
import { themeMixin } from '@tdesign/uniapp/mixins/theme-change';
65+
import { simpleMorse } from 't-comm/lib/morse-pwd/index';
66+
import { toggleVConsole } from 't-comm/lib/v-console/index';
6267
6368
6469
import PullDownList from '../../components/pull-down-list/index.vue';
@@ -94,6 +99,7 @@ export default {
9499
isSkyline: false,
95100
showTrySkyline: false,
96101
winStyle: false,
102+
debugEnabled: false,
97103
};
98104
},
99105
onLoad(options) {
@@ -144,6 +150,50 @@ export default {
144150
});
145151
},
146152
153+
onDescTap() {
154+
// 连续点击 5 次(间隔 < 500ms)唤起调试面板,复用 t-comm simpleMorse
155+
simpleMorse({
156+
target: 5,
157+
timeout: 500,
158+
callback: () => this.toggleDebugConsole(),
159+
});
160+
},
161+
162+
toggleDebugConsole() {
163+
// #ifdef H5
164+
try {
165+
const visible = toggleVConsole();
166+
uni.showToast({
167+
title: visible ? '已开启 vConsole' : '已关闭 vConsole',
168+
icon: 'none',
169+
});
170+
} catch (e) {
171+
console.error('[home] toggleVConsole failed', e);
172+
uni.showToast({ title: '调试面板加载失败', icon: 'none' });
173+
}
174+
// #endif
175+
176+
// #ifndef H5
177+
if (typeof uni !== 'undefined' && typeof uni.setEnableDebug === 'function') {
178+
const enable = !this.debugEnabled;
179+
uni.setEnableDebug({
180+
enableDebug: enable,
181+
success: () => {
182+
this.debugEnabled = enable;
183+
uni.showToast({
184+
title: enable ? '已开启调试模式' : '已关闭调试模式',
185+
icon: 'none',
186+
});
187+
},
188+
fail: () => {
189+
uni.showToast({ title: '当前环境不支持调试面板', icon: 'none' });
190+
},
191+
});
192+
} else {
193+
uni.showToast({ title: '当前环境不支持调试面板', icon: 'none' });
194+
}
195+
// #endif
196+
},
147197
showPrivacyWin() {
148198
this.$refs.trdPrivacy?.showPrivacyWin();
149199
},

vue.config.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
const { DispatchScriptPlugin } = require('@plugin-light/webpack-plugin-dispatch-script');
22
const { DispatchVuePlugin } = require('@plugin-light/webpack-plugin-dispatch-vue');
3-
3+
const {
4+
GenVersionWebPlugin,
5+
GenVersionMpPlugin,
6+
} = require('@plugin-light/webpack-plugin-gen-version');
47

58
const path = require('path');
69

@@ -15,6 +18,15 @@ function resolve(dir) {
1518
// 如果是 用户名.github.io/仓库名 则设置为 '/仓库名/'
1619
const GITHUB_PAGES_PATH = process.env.GITHUB_PAGES_PATH || '/tdesign-uniapp-starter-vue2-cli/';
1720

21+
const plugins = []
22+
23+
if (process.env.VUE_APP_PLATFORM !== 'h5') {
24+
plugins.push(new GenVersionMpPlugin());
25+
} else {
26+
plugins.push(new GenVersionWebPlugin());
27+
}
28+
29+
1830
const isProd = process.env.NODE_ENV === 'production';
1931

2032
module.exports = {
@@ -35,6 +47,7 @@ module.exports = {
3547
plugins: [
3648
// new DispatchScriptPlugin({}),
3749
isProd ? new DispatchVuePlugin({}) : null,
50+
...plugins,
3851
].filter(Boolean),
3952
},
4053
};

0 commit comments

Comments
 (0)