show-modal.uvue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. <template>
  2. <!-- #ifdef APP -->
  3. <scroll-view style="flex: 1">
  4. <!-- #endif -->
  5. <view>
  6. <page-head :title="title"></page-head>
  7. <view class="uni-list">
  8. <radio-group @change="radioChange">
  9. <radio class="uni-list-cell uni-list-cell-pd" v-for="(item, index) in items" :key="item.value"
  10. :class="index < items.length - 1 ? 'uni-list-cell-line' : ''" :value="item.value"
  11. :checked="index === current">
  12. {{ item.name }}
  13. </radio>
  14. </radio-group>
  15. </view>
  16. <view class="uni-list">
  17. <view class="uni-list-cell uni-list-cell-pd">
  18. <view class="uni-list-cell-db">是否显示过长文字</view>
  19. <switch :checked="showLongContent" @change="showLongContentChange" />
  20. </view>
  21. <view class="uni-list-cell uni-list-cell-pd">
  22. <view class="uni-list-cell-db">是否显示取消按钮</view>
  23. <switch :checked="showCancelSelect" @change="showCancelChange" />
  24. </view>
  25. <view class="uni-list-cell uni-list-cell-pd">
  26. <view class="uni-list-cell-db">定制取消文案</view>
  27. <switch :checked="cancelTextSelect" @change="cancelTextChange" />
  28. </view>
  29. <view class="uni-list-cell uni-list-cell-pd">
  30. <view class="uni-list-cell-db">定制确认文案</view>
  31. <switch :checked="confirmTextSelect" @change="confirmTextChange" />
  32. </view>
  33. <view class="uni-list-cell uni-list-cell-pd">
  34. <view class="uni-list-cell-db">测试非法的颜色</view>
  35. <switch :checked="illegalColorSelect" @change="illegalColorChange" />
  36. </view>
  37. <view class="uni-list-cell uni-list-cell-pd">
  38. <view class="uni-list-cell-db">测试超长的按钮文本</view>
  39. <switch :checked="illegalButtonTextSelect" @change="illegalButtonTextChange" />
  40. </view>
  41. <view class="uni-list-cell uni-list-cell-pd">
  42. <view class="uni-list-cell-db">是否显示输入框</view>
  43. <switch :checked="editableSelect" @change="editableChange" />
  44. </view>
  45. <view class="uni-list-cell uni-list-cell-pd">
  46. <view class="uni-list-cell-db">是否定制输入提示词</view>
  47. <switch :checked="placeholderTextSelect" @change="placeholderTextChange" />
  48. </view>
  49. </view>
  50. <view class="uni-padding-wrap uni-common-mt">
  51. <text>complete 执行结果:{{ timesShowRet }}</text>
  52. <view class="uni-btn-v">
  53. <button class="uni-btn-v" type="primary" @tap="modalTap" id="btn-modal-show">
  54. modal单次弹出
  55. </button>
  56. </view>
  57. <view class="uni-btn-v">
  58. <button class="uni-btn-v" type="default" @tap="modalTapTimes" id="btn-modal-show-multitime">
  59. modal多次弹出
  60. </button>
  61. </view>
  62. <!-- #ifndef MP -->
  63. <view class="uni-btn-v">
  64. <button class="uni-btn-v" type="default" @tap="closeAllModal" id="btn-modal-hide-all">
  65. 延迟3s关闭全部弹窗
  66. </button>
  67. </view>
  68. <view class="uni-btn-v">
  69. <button class="uni-btn-v" type="default" @tap="closeLastModal" id="btn-modal-hide-last">
  70. 延迟3s关闭最后一个弹窗
  71. </button>
  72. </view>
  73. <!-- #endif -->
  74. <text>
  75. success/fail 执行结果:{{ exeRet }}
  76. </text>
  77. </view>
  78. </view>
  79. <!-- #ifdef APP -->
  80. </scroll-view>
  81. <!-- #endif -->
  82. </template>
  83. <script>
  84. type ItemType = {
  85. value : string,
  86. name : string,
  87. }
  88. export default {
  89. data() {
  90. return {
  91. title: 'modal',
  92. showCancelSelect: false,
  93. showLongContent: false,
  94. illegalColorSelect:false,
  95. illegalButtonTextSelect:false,
  96. cancelTextSelect: false,
  97. confirmTextSelect: false,
  98. editableSelect: false,
  99. placeholderTextSelect: false,
  100. exeRet: "",
  101. lastModal : null as UniPage | null,
  102. items: [{
  103. value: '标题',
  104. name: '有标题'
  105. },
  106. {
  107. value: '',
  108. name: '无标题'
  109. },
  110. {
  111. value: '超长标题测试内容,测试超过显示最大范围之后的样式-超长标题测试内容,测试超过显示最大范围之后的样式',
  112. name: '超长标题'
  113. }
  114. ] as ItemType[],
  115. current: 0,
  116. timesShowRet:[] as Array<any>,
  117. }
  118. },
  119. onLoad() {
  120. uni.showModal({
  121. title: "onLoad 调用示例,请手动取消"
  122. })
  123. },
  124. methods: {
  125. showLongContentChange: function (e : UniSwitchChangeEvent) {
  126. this.showLongContent = e.detail.value
  127. },
  128. illegalColorChange: function (e : UniSwitchChangeEvent) {
  129. this.illegalColorSelect = e.detail.value
  130. },
  131. illegalButtonTextChange: function (e : UniSwitchChangeEvent) {
  132. this.illegalButtonTextSelect = e.detail.value
  133. },
  134. showCancelChange: function (e : UniSwitchChangeEvent) {
  135. this.showCancelSelect = e.detail.value
  136. },
  137. cancelTextChange: function (e : UniSwitchChangeEvent) {
  138. this.cancelTextSelect = e.detail.value
  139. },
  140. confirmTextChange: function (e : UniSwitchChangeEvent) {
  141. this.confirmTextSelect = e.detail.value
  142. },
  143. editableChange: function (e : UniSwitchChangeEvent) {
  144. this.editableSelect = e.detail.value
  145. },
  146. placeholderTextChange: function (e : UniSwitchChangeEvent) {
  147. this.editableSelect = e.detail.value
  148. this.placeholderTextSelect = e.detail.value
  149. },
  150. radioChange(e : UniRadioGroupChangeEvent) {
  151. for (let i = 0; i < this.items.length; i++) {
  152. if (this.items[i].value === e.detail.value) {
  153. this.current = i;
  154. break;
  155. }
  156. }
  157. },
  158. closeLastModal: function () {
  159. let that = this
  160. setTimeout(function(){
  161. uni.hideModal({
  162. modalPage:that.lastModal,
  163. success: (res) => {
  164. that.exeRet = JSON.stringify(res)
  165. },
  166. fail: (res) => {
  167. that.exeRet = JSON.stringify(res)
  168. },
  169. complete: (res) => {
  170. that.timesShowRet.push(res)
  171. }
  172. })
  173. },3000)
  174. },
  175. closeAllModal: function () {
  176. let that = this
  177. setTimeout(function(){
  178. uni.hideModal({
  179. modalPage:null,
  180. success: (res) => {
  181. that.exeRet = JSON.stringify(res)
  182. },
  183. fail: (res) => {
  184. that.exeRet = JSON.stringify(res)
  185. },
  186. complete: (res) => {
  187. that.timesShowRet.push(res)
  188. }
  189. })
  190. },3000)
  191. },
  192. modalTapTimes: function () {
  193. // 多次弹出前清空结果集合
  194. this.timesShowRet = []
  195. this.modalTap()
  196. this.modalTap()
  197. let that = this
  198. setTimeout(function(){
  199. that.modalTap()
  200. },200)
  201. },
  202. modalTap: function () {
  203. // 单次弹出前清空多次结果集合
  204. this.timesShowRet = []
  205. let cancelTextVal : string|null = null
  206. let cancelColorVal = ''
  207. if (this.cancelTextSelect) {
  208. cancelTextVal = "修改后的取消文本"
  209. cancelColorVal = "#ff00ff"
  210. }else{
  211. //#ifdef MP
  212. cancelTextVal = "取消"
  213. //#endif
  214. }
  215. let confirmTextVal : string|null = null
  216. let confirmColorVal = ''
  217. if (this.confirmTextSelect) {
  218. confirmTextVal = "修改后的确定文本"
  219. confirmColorVal = "#0ff"
  220. }else{
  221. //#ifdef MP
  222. confirmTextVal = "确定"
  223. //#endif
  224. }
  225. let placeholderTextVal = ''
  226. let contentVal = "弹窗内容,告知当前状态、信息和解决方法,描述文字尽量控制在三行内"
  227. if (this.showLongContent) {
  228. contentVal = "弹窗内容,告知当前状态、信息和解决方法,描述文字原则上可以无限多!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
  229. }
  230. if (this.placeholderTextSelect) {
  231. placeholderTextVal = "定制提示信息"
  232. }
  233. if (this.illegalColorSelect) {
  234. cancelColorVal = "#WW00ff"
  235. confirmColorVal = "#0ffff"
  236. }
  237. if (this.illegalButtonTextSelect) {
  238. confirmTextVal = "超长版文字-修改后的确定文本-超长版本文字"
  239. cancelTextVal = "超长版文字-修改后的取消文本-超长版本文字"
  240. }
  241. let op = {
  242. title: this.items[this.current].value,
  243. editable: this.editableSelect,
  244. placeholderText: placeholderTextVal,
  245. content: contentVal,
  246. showCancel: this.showCancelSelect,
  247. cancelText: cancelTextVal,
  248. cancelColor: cancelColorVal,
  249. confirmText: confirmTextVal,
  250. confirmColor: confirmColorVal,
  251. success: (res) => {
  252. this.exeRet = JSON.stringify(res)
  253. },
  254. fail: (res) => {
  255. this.exeRet = JSON.stringify(res)
  256. },
  257. complete: (res) => {
  258. this.timesShowRet.push(res)
  259. }
  260. } as ShowModalOptions
  261. // console.log(op)
  262. this.lastModal = uni.showModal(op)
  263. }
  264. }
  265. }
  266. </script>