modal.uvue 4.5 KB
Newer Older
Y
yurj26 已提交
1
<template>
DCloud-WZF's avatar
DCloud-WZF 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
	<!-- #ifdef APP -->
	<scroll-view style="flex: 1">
		<!-- #endif -->
		<view>
			<page-head :title="title"></page-head>
			<view class="uni-list">
				<radio-group @change="radioChange">
					<radio class="uni-list-cell uni-list-cell-pd" v-for="(item, index) in items" :key="item.value"
						:class="index < items.length - 1 ? 'uni-list-cell-line' : ''" :value="item.value"
						:checked="index === current">
						{{ item.name }}
					</radio>
				</radio-group>
			</view>
			<view class="uni-list">
				<view class="uni-list-cell uni-list-cell-pd">
					<view class="uni-list-cell-db">是否显示取消按钮</view>
					<switch :checked="showCancelSelect" @change="showCancelChange" />
				</view>
				<view class="uni-list-cell uni-list-cell-pd">
					<view class="uni-list-cell-db">定制取消文案</view>
					<switch :checked="cancelTextSelect" @change="cancelTextChange" />
				</view>
				<view class="uni-list-cell uni-list-cell-pd">
					<view class="uni-list-cell-db">定制确认文案</view>
					<switch :checked="confirmTextSelect" @change="confirmTextChange" />
				</view>
				<view class="uni-list-cell uni-list-cell-pd">
					<view class="uni-list-cell-db">是否显示输入框</view>
					<switch :checked="editableSelect" @change="editableChange" />
				</view>
				<view class="uni-list-cell uni-list-cell-pd">
					<view class="uni-list-cell-db">是否定制输入提示词</view>
					<switch :checked="placeholderTextSelect" @change="placeholderTextChange" />
				</view>
			</view>
			<view class="uni-padding-wrap uni-common-mt">
				<view class="uni-btn-v">
					<button class="uni-btn-v" type="default" @tap="modalTap">
						modal测试
					</button>
				</view>
				<text>{{ exeRet }}</text>
			</view>
杜庆泉's avatar
杜庆泉 已提交
46
		</view>
DCloud-WZF's avatar
DCloud-WZF 已提交
47 48 49
		<!-- #ifdef APP -->
	</scroll-view>
	<!-- #endif -->
Y
yurj26 已提交
50
</template>
51
<script lang="uts">
杜庆泉's avatar
杜庆泉 已提交
52
	type ItemType = {
DCloud-WZF's avatar
DCloud-WZF 已提交
53 54
		value : string,
		name : string,
杜庆泉's avatar
杜庆泉 已提交
55
	}
DCloud-WZF's avatar
DCloud-WZF 已提交
56 57 58 59 60 61 62 63 64 65
	export default {
		data() {
			return {
				title: 'modal',
				showCancelSelect: false,
				cancelTextSelect: false,
				confirmTextSelect: false,
				editableSelect: false,
				placeholderTextSelect: false,
				exeRet: "",
杜庆泉's avatar
杜庆泉 已提交
66
				items: [{
DCloud-WZF's avatar
DCloud-WZF 已提交
67 68
					value: '标题',
					name: '有标题'
杜庆泉's avatar
杜庆泉 已提交
69 70
				},
				{
DCloud-WZF's avatar
DCloud-WZF 已提交
71 72
					value: '',
					name: '无标题'
杜庆泉's avatar
杜庆泉 已提交
73 74
				},
				{
DCloud-WZF's avatar
DCloud-WZF 已提交
75 76
					value: '超长标题测试内容,测试超过显示最大范围之后的样式-超长标题测试内容,测试超过显示最大范围之后的样式',
					name: '超长标题'
杜庆泉's avatar
杜庆泉 已提交
77 78 79
				}
				] as ItemType[],
				current: 0
DCloud-WZF's avatar
DCloud-WZF 已提交
80 81 82
			}
		},
		methods: {
杜庆泉's avatar
杜庆泉 已提交
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
			showCancelChange: function (e : SwitchChangeEvent) {
				this.showCancelSelect = e.detail.value
			},
			cancelTextChange: function (e : SwitchChangeEvent) {
				this.cancelTextSelect = e.detail.value
			},
			confirmTextChange: function (e : SwitchChangeEvent) {
				this.confirmTextSelect = e.detail.value
			},
			editableChange: function (e : SwitchChangeEvent) {
				this.editableSelect = e.detail.value
			},
			placeholderTextChange: function (e : SwitchChangeEvent) {
				this.placeholderTextSelect = e.detail.value
			},
			radioChange(e : RadioGroupChangeEvent) {
DCloud-WZF's avatar
DCloud-WZF 已提交
99 100 101 102 103 104
				for (let i = 0; i < this.items.length; i++) {
					if (this.items[i].value === e.detail.value) {
						this.current = i;
						break;
					}
				}
杜庆泉's avatar
杜庆泉 已提交
105
			},
DCloud-WZF's avatar
DCloud-WZF 已提交
106 107
			modalTap: function () {
				let cancelTextVal : string
杜庆泉's avatar
杜庆泉 已提交
108
				let cancelColorVal = ''
DCloud-WZF's avatar
DCloud-WZF 已提交
109
				if (this.cancelTextSelect) {
杜庆泉's avatar
杜庆泉 已提交
110 111
					cancelTextVal = "修改后的取消文本"
					cancelColorVal = "#ff00ff"
DCloud-WZF's avatar
DCloud-WZF 已提交
112
				} else {
113
					cancelTextVal = "取消"
杜庆泉's avatar
杜庆泉 已提交
114
				}
DCloud-WZF's avatar
DCloud-WZF 已提交
115

杜庆泉's avatar
杜庆泉 已提交
116 117
				let confirmTextVal = '确定'
				let confirmColorVal = ''
DCloud-WZF's avatar
DCloud-WZF 已提交
118
				if (this.confirmTextSelect) {
杜庆泉's avatar
杜庆泉 已提交
119 120 121
					confirmTextVal = "修改后的确定文本"
					confirmColorVal = "#00ffff"
				}
DCloud-WZF's avatar
DCloud-WZF 已提交
122

杜庆泉's avatar
杜庆泉 已提交
123 124
				let placeholderTextVal = ''
				let contentVal = "弹窗内容,告知当前状态、信息和解决方法,描述文字尽量控制在三行内"
DCloud-WZF's avatar
DCloud-WZF 已提交
125
				if (this.placeholderTextSelect) {
杜庆泉's avatar
杜庆泉 已提交
126 127 128 129
					placeholderTextVal = "定制提示信息"
					contentVal = ""
				}
				uni.showModal({
DCloud-WZF's avatar
DCloud-WZF 已提交
130 131 132 133 134 135 136 137 138 139
					title: this.items[this.current].value,
					editable: this.editableSelect,
					placeholderText: placeholderTextVal,
					content: contentVal,
					showCancel: this.showCancelSelect,
					cancelText: cancelTextVal,
					cancelColor: cancelColorVal,
					confirmText: confirmTextVal,
					confirmColor: confirmColorVal,
					success: function (res) {
杜庆泉's avatar
杜庆泉 已提交
140 141
						this.exeRet = JSON.stringify(res)
					},
DCloud-WZF's avatar
DCloud-WZF 已提交
142
					fail: function (res) {
杜庆泉's avatar
杜庆泉 已提交
143 144 145
						this.exeRet = JSON.stringify(res)
					}
				})
DCloud-WZF's avatar
DCloud-WZF 已提交
146 147 148 149 150

			}

		}
	}
Y
yurj26 已提交
151
</script>