dialog-3.uvue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <template>
  2. <view id="dialog3" class="dialog-container">
  3. <scroll-view class="dialog-content">
  4. <text>title: {{ title }}</text>
  5. <template v-for="(item, index) in PageStyleArray">
  6. <view class="page-style-item" v-if="currentPageStyle[item.key] != null" :key="index">
  7. <view class="item-text">
  8. <text class="item-text-key">{{ item.key }}:</text>
  9. <text class="item-text-value">{{
  10. currentPageStyle[item.key]
  11. }}</text>
  12. </view>
  13. <view class="mt-10" v-if="item.type == 'boolean'">
  14. <switch :checked="currentPageStyle.getBoolean(item.key)"
  15. @change="switchChange(item.key, $event as UniSwitchChangeEvent)">
  16. </switch>
  17. </view>
  18. <view class="mt-10" v-else-if="item.type == 'number'">
  19. <slider :value="currentPageStyle.getNumber(item.key)" :show-value="true"
  20. @change="sliderChange(item.key, $event as UniSliderChangeEvent)" />
  21. </view>
  22. <view class="mt-10" v-else-if="item.type == 'string'">
  23. <radio-group class="radio-set-value" @change="radioChange(item.key, $event as RadioGroupChangeEvent)">
  24. <radio class="ml-10" v-for="(item2, index2) in item.value" :key="index2" :value="item2"
  25. :checked="currentPageStyle[item.key] == item2">{{ item2 }}
  26. </radio>
  27. </radio-group>
  28. </view>
  29. </view>
  30. </template>
  31. <text class="mt-10 choose-close-animation-type-title">choose close dialogPage animationType</text>
  32. <radio-group class="choose-close-animation-type-radio-group" @change="handleChooseAnimationType">
  33. <radio class="ml-10 mt-10" v-for="item in closeAnimationTypeList" :key="item" :value="item"
  34. :checked="closeAnimationType == item">{{ item }}
  35. </radio>
  36. </radio-group>
  37. <button class="mt-10" @click="closeThisDialog">
  38. closeThisDialog
  39. </button>
  40. </scroll-view>
  41. </view>
  42. </template>
  43. <script>
  44. import { PageStyleItem, PageStyleArray } from './page-style.uts';
  45. type CloseAnimationType =
  46. 'auto' |
  47. 'none' |
  48. 'slide-out-right' |
  49. 'slide-out-left' |
  50. 'slide-out-top' |
  51. 'slide-out-bottom' |
  52. 'fade-out' |
  53. 'zoom-in' |
  54. 'zoom-fade-in'
  55. export default {
  56. data() {
  57. return {
  58. title: 'dialog 3',
  59. PageStyleArray: PageStyleArray as PageStyleItem[],
  60. currentPageStyle: {} as UTSJSONObject,
  61. closeAnimationType: 'auto' as CloseAnimationType,
  62. closeAnimationTypeList: [
  63. 'auto',
  64. 'none',
  65. 'slide-out-right',
  66. 'slide-out-left',
  67. 'slide-out-top',
  68. 'slide-out-bottom',
  69. 'fade-out',
  70. 'zoom-in',
  71. 'zoom-fade-in'
  72. ]
  73. }
  74. },
  75. onLoad(_ : OnLoadOptions) {
  76. this.getPageStyle()
  77. },
  78. methods: {
  79. getPageStyle() {
  80. this.currentPageStyle = this.$page.getPageStyle()
  81. },
  82. radioChange(key : string, e : RadioGroupChangeEvent) {
  83. this.setStyleValue(key, e.detail.value);
  84. },
  85. sliderChange(key : string, e : UniSliderChangeEvent) {
  86. this.setStyleValue(key, e.detail.value);
  87. },
  88. switchChange(key : string, e : UniSwitchChangeEvent) {
  89. this.setStyleValue(key, e.detail.value);
  90. },
  91. setStyleValue(key : string, value : any) {
  92. const style = {}
  93. style[key] = value
  94. this.setPageStyle(style)
  95. this.getPageStyle()
  96. },
  97. setPageStyle(style : UTSJSONObject) {
  98. this.$page.setPageStyle(style);
  99. },
  100. handleChooseAnimationType(e : RadioGroupChangeEvent){
  101. this.closeAnimationType = e.detail.value as CloseAnimationType
  102. },
  103. closeThisDialog() {
  104. uni.closeDialogPage({
  105. dialogPage: this.$page,
  106. animationType: this.closeAnimationType,
  107. success(res) {
  108. console.log('closeDialog success', res)
  109. },
  110. fail(err) {
  111. console.log('closeDialog fail', err)
  112. },
  113. complete(res) {
  114. console.log('closeDialog complete', res)
  115. }
  116. })
  117. }
  118. }
  119. }
  120. </script>
  121. <style>
  122. .dialog-container {
  123. width: 100%;
  124. height: 100%;
  125. background-color: rgba(0, 0, 0, 0.3);
  126. display: flex;
  127. justify-content: center;
  128. align-items: center;
  129. }
  130. .dialog-content {
  131. width: 90%;
  132. height: 500px;
  133. padding: 10px 6px;
  134. background-color: #fff;
  135. border-radius: 6px;
  136. }
  137. .mt-10 {
  138. margin-top: 10px;
  139. }
  140. .ml-10 {
  141. margin-left: 10px;
  142. }
  143. .page-style-item {
  144. padding: 6px 0;
  145. margin-top: 10px;
  146. background-color: #ffffff;
  147. border-radius: 5px;
  148. }
  149. .item-text {
  150. flex-direction: row;
  151. }
  152. .item-text-key {
  153. font-weight: bold;
  154. }
  155. .item-text-value {
  156. margin-left: 5px;
  157. }
  158. .radio-set-value {
  159. flex-direction: row;
  160. }
  161. .choose-close-animation-type-title{
  162. font-weight: bold;
  163. }
  164. .choose-close-animation-type-radio-group{
  165. flex-direction: row;
  166. flex-wrap: wrap;
  167. }
  168. </style