123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- <template>
- <view class="mpvue-picker">
- <page-head :title="title"></page-head>
- <view class="uni-padding-wrap uni-common-mt">
- <view class="uni-title">
-
- <uni-icons size="16" type="info"></uni-icons>
-
- 说明 :
- </view>
- <view class="uni-helllo-text">
- <view>
- 在App端可在pages.json里配置buttons,暂不支持动态改变buttons的样式,使用onNavigationBarButtonTap可监听城市选择按钮的点击事件。
- </view>
- </view>
- </view>
- <mpvue-picker
- :themeColor="themeColor"
- ref="mpvuePicker"
- :mode="mode"
- :deepLength="deepLength"
- :pickerValueDefault="pickerValueDefault"
- @onConfirm="onConfirm"
- @onCancel="onCancel"
- :pickerValueArray="pickerValueArray"
- ></mpvue-picker>
- {{pickerValueArray[index].label}}
- </view>
- </template>
- <script>
- import mpvuePicker from '../../../components/mpvue-picker/mpvuePicker.vue';
- export default {
- components: {
- mpvuePicker
- },
- data() {
- return {
- title: 'nav-city-dropdown',
- pickerValueArray: [
- {
- label: '北京市',
- value: 110000
- },
- {
- label: '天津市',
- value: 120000
- },
- {
- label: '广州市',
- value: 440100
- },
- {
- label: '深圳市',
- value: 440300
- }
- ],
- themeColor: '#007AFF',
- mode: '',
- deepLength: 1,
- pickerValueDefault: [0],
- index: 0,
- };
- },
- onReady() {
- this.setStyle(0, '北京市');
- },
- methods: {
- onCancel(e) {
- console.log(e);
- },
-
- showSinglePicker() {
- this.mode = 'selector';
- this.deepLength = 1;
- this.pickerValueDefault = [0];
- this.$refs.mpvuePicker.show();
- },
- onConfirm(e) {
- console.log(e.label);
- this.setStyle(0, e.label);
- },
-
- setStyle(index, text) {
- let pages = getCurrentPages();
- let page = pages[pages.length - 1];
- if (text.length > 3) {
- text = text.substr(0, 3) + '...';
- }
-
- let currentWebview = page.$getAppWebview();
- let titleNView = currentWebview.getStyle().titleNView;
-
- titleNView.buttons[0].text = text;
- currentWebview.setStyle({
- titleNView: titleNView
- });
-
-
-
- document.getElementsByClassName('uni-btn-icon')[1].innerText = text;
-
- }
- },
- onBackPress() {
- if (this.$refs.mpvuePicker.showPicker) {
- this.$refs.mpvuePicker.pickerCancel();
- return true;
- }
- },
- onUnload() {
- if (this.$refs.mpvuePicker.showPicker) {
- this.$refs.mpvuePicker.pickerCancel();
- }
- },
- onNavigationBarButtonTap(e) {
- if (e.index === 0) {
- this.showSinglePicker();
- }
- }
- };
- </script>
- <style></style>
|