Skip to content

Commit fe6baa4

Browse files
authored
chore(picker): add tick demo (#4522)
* chore(picker): add tick demo * chore: add load vconsole
1 parent 7bad41b commit fe6baa4

4 files changed

Lines changed: 89 additions & 4 deletions

File tree

packages/tdesign-uniapp/example/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
},
645 Bytes
Binary file not shown.

packages/tdesign-uniapp/example/vite.config.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,21 @@ import path from 'path';
33
import { defineConfig, loadEnv } from 'vite';
44

55
import uni from '@dcloudio/vite-plugin-uni';
6-
import { genVersionMpVitePlugin } from '@plugin-light/vite-plugin-gen-version';
6+
import {
7+
genVersionMpVitePlugin,
8+
genVersionWebVitePlugin,
9+
} from '@plugin-light/vite-plugin-gen-version';
10+
import { BUILD_NAME_MAP } from 't-comm/lib/v-console/config';
711

812
const diffPlugins: any[] = [];
913
if (process.env.UNI_PLATFORM !== 'h5') {
1014
diffPlugins.push(genVersionMpVitePlugin());
15+
} else {
16+
diffPlugins.push(genVersionWebVitePlugin({
17+
buildName: BUILD_NAME_MAP.build,
18+
commitName: BUILD_NAME_MAP.commit,
19+
delay: 0,
20+
}));
1121
}
1222

1323

@@ -32,7 +42,7 @@ export default ({ mode }: { mode: string }) => {
3242
const result = defineConfig({
3343
plugins: [
3444
uni(),
35-
diffPlugins,
45+
...diffPlugins,
3646
],
3747
resolve: {
3848
alias: {

packages/uniapp-components/picker/_example/area/index.vue

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,29 @@ export default {
7676
this.counties = counties;
7777
},
7878
79+
onPickFeedback() {
80+
try {
81+
if (typeof uni !== 'undefined' && uni.vibrateShort) {
82+
uni.vibrateShort({ type: 'medium', fail: () => {} });
83+
}
84+
} catch (_) { /* noop */ }
85+
86+
// 音效:懒初始化单个音频实例,落点时 seek(0) + play() 重放
87+
// 微信小程序需将 mp3 放到项目静态目录(如 /static/picker-tick.mp3)
88+
try {
89+
if (!this.innerTickAudio && typeof uni !== 'undefined' && uni.createInnerAudioContext) {
90+
const audio = uni.createInnerAudioContext();
91+
audio.src = '/static/picker-tick.mp3';
92+
if ('obeyMuteSwitch' in audio) audio.obeyMuteSwitch = true;
93+
this.innerTickAudio = audio;
94+
}
95+
if (this.innerTickAudio) {
96+
if (typeof this.innerTickAudio.seek === 'function') this.innerTickAudio.seek(0);
97+
this.innerTickAudio.play && this.innerTickAudio.play();
98+
}
99+
} catch (_) { /* noop */ }
100+
},
101+
79102
onColumnChange(e) {
80103
console.log('pick:', e);
81104
const { column, index } = e;
@@ -94,6 +117,8 @@ export default {
94117
if (column === 2) {
95118
// 更改区县
96119
}
120+
121+
this.onPickFeedback();
97122
},
98123
99124
getCities(provinceValue) {

0 commit comments

Comments
 (0)