123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273 |
- <template>
- <!-- #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="showLongContent" @change="showLongContentChange" />
- </view>
- <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="illegalColorSelect" @change="illegalColorChange" />
- </view>
- <view class="uni-list-cell uni-list-cell-pd">
- <view class="uni-list-cell-db">测试超长的按钮文本</view>
- <switch :checked="illegalButtonTextSelect" @change="illegalButtonTextChange" />
- </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">
- <text>complete 执行结果:{{ timesShowRet }}</text>
- <view class="uni-btn-v">
- <button class="uni-btn-v" type="primary" @tap="modalTap" id="btn-modal-show">
- modal单次弹出
- </button>
- </view>
- <view class="uni-btn-v">
- <button class="uni-btn-v" type="default" @tap="modalTapTimes" id="btn-modal-show-multitime">
- modal多次弹出
- </button>
- </view>
- <!-- #ifndef MP -->
- <view class="uni-btn-v">
- <button class="uni-btn-v" type="default" @tap="closeAllModal" id="btn-modal-hide-all">
- 延迟3s关闭全部弹窗
- </button>
- </view>
- <view class="uni-btn-v">
- <button class="uni-btn-v" type="default" @tap="closeLastModal" id="btn-modal-hide-last">
- 延迟3s关闭最后一个弹窗
- </button>
- </view>
- <!-- #endif -->
- <text>
- success/fail 执行结果:{{ exeRet }}
- </text>
- </view>
- </view>
- <!-- #ifdef APP -->
- </scroll-view>
- <!-- #endif -->
- </template>
- <script>
- type ItemType = {
- value : string,
- name : string,
- }
- export default {
- data() {
- return {
- title: 'modal',
- showCancelSelect: false,
- showLongContent: false,
- illegalColorSelect:false,
- illegalButtonTextSelect:false,
- cancelTextSelect: false,
- confirmTextSelect: false,
- editableSelect: false,
- placeholderTextSelect: false,
- exeRet: "",
- lastModal : null as UniPage | null,
- items: [{
- value: '标题',
- name: '有标题'
- },
- {
- value: '',
- name: '无标题'
- },
- {
- value: '超长标题测试内容,测试超过显示最大范围之后的样式-超长标题测试内容,测试超过显示最大范围之后的样式',
- name: '超长标题'
- }
- ] as ItemType[],
- current: 0,
- timesShowRet:[] as Array<any>,
- }
- },
- onLoad() {
- uni.showModal({
- title: "onLoad 调用示例,请手动取消"
- })
- },
- methods: {
- showLongContentChange: function (e : UniSwitchChangeEvent) {
- this.showLongContent = e.detail.value
- },
- illegalColorChange: function (e : UniSwitchChangeEvent) {
- this.illegalColorSelect = e.detail.value
- },
- illegalButtonTextChange: function (e : UniSwitchChangeEvent) {
- this.illegalButtonTextSelect = e.detail.value
- },
- showCancelChange: function (e : UniSwitchChangeEvent) {
- this.showCancelSelect = e.detail.value
- },
- cancelTextChange: function (e : UniSwitchChangeEvent) {
- this.cancelTextSelect = e.detail.value
- },
- confirmTextChange: function (e : UniSwitchChangeEvent) {
- this.confirmTextSelect = e.detail.value
- },
- editableChange: function (e : UniSwitchChangeEvent) {
- this.editableSelect = e.detail.value
- },
- placeholderTextChange: function (e : UniSwitchChangeEvent) {
- this.editableSelect = e.detail.value
- this.placeholderTextSelect = e.detail.value
- },
- radioChange(e : UniRadioGroupChangeEvent) {
- for (let i = 0; i < this.items.length; i++) {
- if (this.items[i].value === e.detail.value) {
- this.current = i;
- break;
- }
- }
- },
- closeLastModal: function () {
- let that = this
- setTimeout(function(){
- uni.hideModal({
- modalPage:that.lastModal,
- success: (res) => {
- that.exeRet = JSON.stringify(res)
- },
- fail: (res) => {
- that.exeRet = JSON.stringify(res)
- },
- complete: (res) => {
- that.timesShowRet.push(res)
- }
- })
- },3000)
- },
- closeAllModal: function () {
- let that = this
- setTimeout(function(){
- uni.hideModal({
- modalPage:null,
- success: (res) => {
- that.exeRet = JSON.stringify(res)
- },
- fail: (res) => {
- that.exeRet = JSON.stringify(res)
- },
- complete: (res) => {
- that.timesShowRet.push(res)
- }
- })
- },3000)
- },
- modalTapTimes: function () {
- // 多次弹出前清空结果集合
- this.timesShowRet = []
- this.modalTap()
- this.modalTap()
- let that = this
- setTimeout(function(){
- that.modalTap()
- },200)
- },
- modalTap: function () {
- // 单次弹出前清空多次结果集合
- this.timesShowRet = []
- let cancelTextVal : string|null = null
- let cancelColorVal = ''
- if (this.cancelTextSelect) {
- cancelTextVal = "修改后的取消文本"
- cancelColorVal = "#ff00ff"
- }else{
- //#ifdef MP
- cancelTextVal = "取消"
- //#endif
- }
- let confirmTextVal : string|null = null
- let confirmColorVal = ''
- if (this.confirmTextSelect) {
- confirmTextVal = "修改后的确定文本"
- confirmColorVal = "#0ff"
- }else{
- //#ifdef MP
- confirmTextVal = "确定"
- //#endif
- }
- let placeholderTextVal = ''
- let contentVal = "弹窗内容,告知当前状态、信息和解决方法,描述文字尽量控制在三行内"
- if (this.showLongContent) {
- contentVal = "弹窗内容,告知当前状态、信息和解决方法,描述文字原则上可以无限多!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
- }
- if (this.placeholderTextSelect) {
- placeholderTextVal = "定制提示信息"
- }
- if (this.illegalColorSelect) {
- cancelColorVal = "#WW00ff"
- confirmColorVal = "#0ffff"
- }
- if (this.illegalButtonTextSelect) {
- confirmTextVal = "超长版文字-修改后的确定文本-超长版本文字"
- cancelTextVal = "超长版文字-修改后的取消文本-超长版本文字"
- }
- let op = {
- 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: (res) => {
- this.exeRet = JSON.stringify(res)
- },
- fail: (res) => {
- this.exeRet = JSON.stringify(res)
- },
- complete: (res) => {
- this.timesShowRet.push(res)
- }
- } as ShowModalOptions
- // console.log(op)
- this.lastModal = uni.showModal(op)
- }
- }
- }
- </script>
|