show-loading.uvue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <template>
  2. <view>
  3. <page-head :title="title"></page-head>
  4. <view class="uni-list">
  5. <view class="uni-list-cell uni-list-cell-pd">
  6. <view class="uni-list-cell-db">是否显示透明蒙层-屏蔽点击事件</view>
  7. <switch :checked="maskSelect" @change="maskChange" />
  8. </view>
  9. <view class="uni-padding-wrap">
  10. <view class="uni-title uni-common-mt">
  11. <text class="uni-title-text"> 设置标题 </text>
  12. </view>
  13. </view>
  14. <view class="uni-list uni-common-pl">
  15. <radio-group @change="radioChange">
  16. <radio class="uni-list-cell uni-list-cell-pd radio" v-for="(item, index) in items" :key="item.value"
  17. :class="index < items.length - 1 ? 'uni-list-cell-line' : ''" :value="item.value"
  18. :checked="index === current">
  19. {{ item.name }}
  20. </radio>
  21. </radio-group>
  22. </view>
  23. </view>
  24. <view class="uni-padding-wrap">
  25. <view class="uni-btn-v">
  26. <button class="uni-btn-v" type="primary" @click="showLoading">显示 loading 提示框</button>
  27. <button class="uni-btn-v" @click="hideLoading">隐藏 loading 提示框</button>
  28. <text>为方便演示,loading弹出3秒后自动关闭</text>
  29. </view>
  30. </view>
  31. </view>
  32. </template>
  33. <script lang="uts">
  34. type ItemType = {
  35. value : string
  36. name : string
  37. }
  38. export default {
  39. data() {
  40. return {
  41. title: 'loading',
  42. items: [
  43. {
  44. value: 'null',
  45. name: '无标题',
  46. },
  47. {
  48. value: '三秒后自动关闭',
  49. name: '普通标题',
  50. },
  51. {
  52. value: '超长文本内容,测试超出范围-超长文本内容,测试超出范围-三秒后自动关闭',
  53. name: '长标题',
  54. },
  55. ] as ItemType[],
  56. current: 0,
  57. maskSelect: false,
  58. titleSelect: "null"
  59. }
  60. },
  61. onLoad() {
  62. uni.showLoading({
  63. title: 'onLoad 调用示例,2秒后消失'
  64. })
  65. setTimeout(function () {
  66. uni.hideLoading()
  67. }, 2000);
  68. },
  69. methods: {
  70. //自动化测试例专用
  71. jest_getWindowInfo() : GetWindowInfoResult {
  72. return uni.getWindowInfo();
  73. },
  74. radioChange(e : UniRadioGroupChangeEvent) {
  75. const selected = this.items.find((item) : boolean => {
  76. return item.value == e.detail.value
  77. })
  78. if (selected != null) {
  79. this.titleSelect = selected.value
  80. }
  81. },
  82. maskChange: function (e : UniSwitchChangeEvent) {
  83. this.maskSelect = e.detail.value
  84. },
  85. showLoading: function () {
  86. console.log(this.titleSelect)
  87. if (this.titleSelect == "null") {
  88. uni.showLoading({
  89. title: "",
  90. mask: this.maskSelect
  91. });
  92. } else {
  93. uni.showLoading({
  94. title: this.titleSelect,
  95. mask: this.maskSelect
  96. });
  97. }
  98. setTimeout(() => {
  99. this.hideLoading();
  100. }, 3000);
  101. },
  102. hideLoading: function () {
  103. uni.hideLoading();
  104. }
  105. }
  106. }
  107. </script>