sh-view 2.0.8 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/package.json +9 -13
  2. package/packages/components/global-components/sh-alert/index.vue +175 -173
  3. package/packages/components/global-components/sh-badge/index.vue +57 -43
  4. package/packages/components/global-components/sh-card/index.vue +24 -16
  5. package/packages/components/global-components/sh-code-editor/index.vue +250 -260
  6. package/packages/components/global-components/sh-col/index.vue +44 -36
  7. package/packages/components/global-components/sh-corner/index.vue +230 -228
  8. package/packages/components/global-components/sh-count-to/index.vue +60 -51
  9. package/packages/components/global-components/sh-drawer/index.vue +216 -183
  10. package/packages/components/global-components/sh-drawer/scrollbar.js +44 -42
  11. package/packages/components/global-components/sh-empty/index.vue +0 -1
  12. package/packages/components/global-components/sh-form/form.vue +110 -0
  13. package/packages/components/global-components/sh-form/js/props.js +76 -63
  14. package/packages/components/global-components/sh-form/js/useForm.js +236 -0
  15. package/packages/components/global-components/sh-form/query.vue +70 -0
  16. package/packages/components/global-components/sh-header/index.vue +35 -50
  17. package/packages/components/global-components/sh-icon/css/index.scss +44 -0
  18. package/packages/components/global-components/sh-icon/index.vue +24 -11
  19. package/packages/components/global-components/sh-image/index.vue +47 -38
  20. package/packages/components/global-components/sh-list/index.vue +42 -37
  21. package/packages/components/global-components/sh-loading/index.vue +12 -8
  22. package/packages/components/global-components/sh-modal/index.vue +49 -40
  23. package/packages/components/global-components/sh-noticebar/index.vue +68 -54
  24. package/packages/components/global-components/sh-poptip/index.vue +247 -130
  25. package/packages/components/global-components/sh-progress/index.vue +71 -69
  26. package/packages/components/global-components/sh-pull-refresh/index.vue +156 -157
  27. package/packages/components/global-components/sh-result/index.vue +37 -28
  28. package/packages/components/global-components/sh-row/index.vue +21 -18
  29. package/packages/components/global-components/sh-split/index.vue +115 -109
  30. package/packages/components/global-components/sh-table/components/importModal.vue +95 -86
  31. package/packages/components/global-components/sh-table/components/sh-column.vue +54 -0
  32. package/packages/components/global-components/sh-table/{index.vue → grid.vue} +34 -145
  33. package/packages/components/global-components/sh-table/js/tableMethods.js +175 -0
  34. package/packages/components/global-components/sh-table/js/useTable.js +592 -0
  35. package/packages/components/global-components/sh-table/table.vue +269 -0
  36. package/packages/components/global-components/sh-tabs/index.vue +118 -93
  37. package/packages/components/global-components/sh-tag/index.vue +52 -51
  38. package/packages/components/global-components/sh-toolbar/index.vue +53 -47
  39. package/packages/components/global-components/sh-tree/components/table-tree.vue +152 -139
  40. package/packages/components/global-components/sh-tree/index.vue +218 -195
  41. package/packages/components/global-components/sh-tree/mixin/treeProps.js +118 -120
  42. package/packages/components/global-components/sh-upload/index.vue +308 -51
  43. package/packages/components/global-components/sh-water-fall/index.vue +4 -11
  44. package/packages/components/index.js +5 -3
  45. package/packages/components/other-components/sh-cron-modal/components/cron-content.vue +294 -287
  46. package/packages/components/other-components/sh-cron-modal/css/index.scss +0 -5
  47. package/packages/components/other-components/sh-cron-modal/index.vue +81 -67
  48. package/packages/components/other-components/sh-cron-modal/mixin/cron-emits.js +1 -0
  49. package/packages/components/other-components/sh-cron-modal/mixin/cron-hooks.js +179 -0
  50. package/packages/components/other-components/sh-cron-modal/mixin/cron-props.js +9 -0
  51. package/packages/components/other-components/sh-cron-modal/tabs/cron-day-box.vue +101 -92
  52. package/packages/components/other-components/sh-cron-modal/tabs/cron-hour-box.vue +68 -56
  53. package/packages/components/other-components/sh-cron-modal/tabs/cron-minute-box.vue +68 -56
  54. package/packages/components/other-components/sh-cron-modal/tabs/cron-month-box.vue +68 -56
  55. package/packages/components/other-components/sh-cron-modal/tabs/cron-second-box.vue +68 -56
  56. package/packages/components/other-components/sh-cron-modal/tabs/cron-week-box.vue +126 -115
  57. package/packages/components/other-components/sh-cron-modal/tabs/cron-year-box.vue +59 -46
  58. package/packages/components/other-components/sh-menu/index.vue +75 -60
  59. package/packages/components/other-components/sh-menu/menu-group-content.vue +71 -59
  60. package/packages/components/other-components/sh-menu/menu-item-content.vue +71 -61
  61. package/packages/components/other-components/sh-menu-card/index.vue +81 -59
  62. package/packages/components/other-components/sh-menu-card/menu-box.vue +87 -68
  63. package/packages/components/other-components/sh-preview/components/sh-excel.vue +182 -0
  64. package/packages/components/other-components/sh-preview/components/sh-word.vue +73 -0
  65. package/packages/components/other-components/sh-preview/index.vue +86 -85
  66. package/packages/components/other-components/sh-preview/js/data-hook.js +37 -0
  67. package/packages/components/other-components/sh-preview/js/data-props.js +11 -0
  68. package/packages/components/other-components/sh-system-tip/index.vue +115 -113
  69. package/packages/css/index.js +4 -4
  70. package/packages/{assets/css → css}/main.scss +2 -50
  71. package/packages/{assets/css → css}/theme.scss +35 -16
  72. package/packages/directive/module/prevent-click.js +1 -1
  73. package/packages/directive/module/resize.js +11 -154
  74. package/packages/index.js +39 -39
  75. package/packages/mixin/index.js +86 -87
  76. package/packages/vxeTable/css/index.scss +3 -0
  77. package/packages/vxeTable/render/cell/vxe-render-checkbox.vue +14 -5
  78. package/packages/vxeTable/render/cell/vxe-render-checkgroup.vue +43 -36
  79. package/packages/vxeTable/render/cell/vxe-render-code.vue +14 -5
  80. package/packages/vxeTable/render/cell/vxe-render-goption.vue +34 -24
  81. package/packages/vxeTable/render/cell/vxe-render-href.vue +21 -11
  82. package/packages/vxeTable/render/cell/vxe-render-img.vue +16 -10
  83. package/packages/vxeTable/render/cell/vxe-render-input.vue +83 -67
  84. package/packages/vxeTable/render/cell/vxe-render-money.vue +14 -6
  85. package/packages/vxeTable/render/cell/vxe-render-progress.vue +28 -19
  86. package/packages/vxeTable/render/cell/vxe-render-radio.vue +14 -5
  87. package/packages/vxeTable/render/cell/vxe-render-radiogroup.vue +43 -36
  88. package/packages/vxeTable/render/cell/vxe-render-select.vue +44 -36
  89. package/packages/vxeTable/render/cell/vxe-render-switch.vue +14 -5
  90. package/packages/vxeTable/render/cell/vxe-render-table.vue +51 -78
  91. package/packages/vxeTable/render/cell/vxe-render-textarea.vue +14 -5
  92. package/packages/vxeTable/render/cell/vxe-render-time.vue +23 -13
  93. package/packages/vxeTable/render/cell/vxe-render-tree.vue +23 -27
  94. package/packages/vxeTable/render/cell/vxe-render-upload.vue +11 -7
  95. package/packages/vxeTable/render/filters/vxe-filter-input.vue +25 -43
  96. package/packages/vxeTable/render/footer/vxe-footer-input.vue +23 -13
  97. package/packages/vxeTable/render/footer/vxe-footer-money.vue +30 -20
  98. package/packages/vxeTable/render/globalRenders.jsx +1 -1
  99. package/packages/vxeTable/render/header/vxe-header-money.vue +31 -21
  100. package/packages/vxeTable/render/mixin/cell-hooks.js +162 -0
  101. package/packages/vxeTable/render/mixin/cell-props.js +23 -0
  102. package/packages/vxeTable/render/mixin/filter-hooks.js +28 -0
  103. package/packages/components/global-components/sh-form/components/form-item.vue +0 -25
  104. package/packages/components/global-components/sh-form/css/index.scss +0 -55
  105. package/packages/components/global-components/sh-form/index.vue +0 -114
  106. package/packages/components/global-components/sh-form/js/methods.js +0 -146
  107. package/packages/components/global-components/sh-form/mixin/defaultData.js +0 -32
  108. package/packages/components/global-components/sh-icon/css/default/index.scss +0 -27
  109. package/packages/components/global-components/sh-icon/css/font/index.scss +0 -16
  110. package/packages/components/global-components/sh-icon/icon-default.vue +0 -32
  111. package/packages/components/global-components/sh-icon/icon-font.vue +0 -32
  112. package/packages/components/global-components/sh-poptip/popper.js +0 -115
  113. package/packages/components/global-components/sh-query/index.vue +0 -317
  114. package/packages/components/global-components/sh-table/js/methods.js +0 -549
  115. package/packages/components/global-components/sh-table/mixin/defaultData.js +0 -94
  116. package/packages/components/global-components/sh-upload/js/mixin.js +0 -257
  117. package/packages/components/other-components/sh-cron-modal/mixin/cron-box.js +0 -169
  118. package/packages/vxeTable/render/mixin/cell-mixin.js +0 -206
  119. /package/packages/components/global-components/sh-icon/css/default/{fonts/ionicons.svg → ionicons.svg} +0 -0
  120. /package/packages/components/global-components/sh-icon/css/default/{fonts/ionicons.ttf → ionicons.ttf} +0 -0
  121. /package/packages/components/global-components/sh-icon/css/default/{fonts/ionicons.woff → ionicons.woff} +0 -0
  122. /package/packages/components/global-components/sh-icon/css/default/{fonts/ionicons.woff2 → ionicons.woff2} +0 -0
  123. /package/packages/components/global-components/sh-icon/css/font/{fonts/iconfont.js → iconfont.js} +0 -0
  124. /package/packages/components/global-components/sh-icon/css/font/{fonts/iconfont.json → iconfont.json} +0 -0
  125. /package/packages/components/global-components/sh-icon/css/font/{fonts/iconfont.ttf → iconfont.ttf} +0 -0
  126. /package/packages/components/global-components/sh-icon/css/font/{fonts/iconfont.woff → iconfont.woff} +0 -0
  127. /package/packages/components/global-components/sh-icon/css/font/{fonts/iconfont.woff2 → iconfont.woff2} +0 -0
  128. /package/packages/{assets/css → css}/animated.scss +0 -0
  129. /package/packages/{assets/css → css}/loader.scss +0 -0
@@ -13,7 +13,8 @@
13
13
  </template>
14
14
 
15
15
  <script>
16
- export default {
16
+ import { defineComponent, computed, ref, watch } from 'vue'
17
+ export default defineComponent({
17
18
  name: 'ShImage',
18
19
  props: {
19
20
  src: {
@@ -50,52 +51,60 @@ export default {
50
51
  }
51
52
  },
52
53
  emits: ['update:modelValue', 'load', 'error'],
53
- data() {
54
- return {
55
- imageloading: false,
56
- imageError: false
57
- }
58
- },
59
- computed: {
60
- wrapStyles() {
54
+ setup(props, context) {
55
+ const { emit } = context
56
+ const imageloading = ref(false)
57
+ const imageError = ref(false)
58
+
59
+ const wrapStyles = computed(() => {
61
60
  return {
62
- width: typeof this.width === 'number' ? `${this.width}px` : this.width,
63
- height: typeof this.height === 'number' ? `${this.height}px` : this.height
61
+ width: typeof props.width === 'number' ? `${props.width}px` : props.width,
62
+ height: typeof props.height === 'number' ? `${props.height}px` : props.height
64
63
  }
65
- },
66
- imgConfig() {
64
+ })
65
+ const imgConfig = computed(() => {
67
66
  const fitContains = ['fill', 'contain', 'cover', 'none', 'scale-down']
68
67
  return {
69
- alt: this.alt,
70
- src: this.src,
71
- referrerPolicy: this.referrerPolicy,
72
- loading: this.lazy ? 'lazy' : 'eager',
73
- style: fitContains.includes(this.fit) ? `object-fit:${this.fit};` : ''
68
+ alt: props.alt,
69
+ src: props.src,
70
+ referrerPolicy: props.referrerPolicy,
71
+ loading: props.lazy ? 'lazy' : 'eager',
72
+ style: fitContains.includes(props.fit) ? `object-fit:${props.fit};` : ''
74
73
  }
74
+ })
75
+
76
+ const onImageLoad = () => {
77
+ imageloading.value = false
78
+ imageError.value = false
79
+ emit('load')
75
80
  }
76
- },
77
- watch: {
78
- src() {
79
- this.loadImage()
81
+ const onImageError = () => {
82
+ imageloading.value = false
83
+ imageError.value = true
84
+ emit('error')
80
85
  }
81
- },
82
- methods: {
83
- onImageLoad() {
84
- this.imageloading = false
85
- this.imageError = false
86
- this.$emit('load')
87
- },
88
- onImageError() {
89
- this.imageloading = false
90
- this.imageError = true
91
- this.$emit('error')
92
- },
93
- loadImage() {
94
- this.imageloading = true
95
- this.imageError = false
86
+ const loadImage = () => {
87
+ imageloading.value = true
88
+ imageError.value = false
89
+ }
90
+
91
+ watch(
92
+ () => props.src,
93
+ () => {
94
+ loadImage()
95
+ }
96
+ )
97
+
98
+ return {
99
+ wrapStyles,
100
+ imageError,
101
+ imageloading,
102
+ imgConfig,
103
+ onImageLoad,
104
+ onImageError
96
105
  }
97
106
  }
98
- }
107
+ })
99
108
  </script>
100
109
 
101
110
  <style scoped lang="scss">
@@ -1,13 +1,13 @@
1
1
  <template>
2
2
  <div class="sh-list">
3
- <template v-if="$slots.header"><slot name="header"></slot></template>
4
- <vxe-list ref="vxeList" :class="{ grid }" v-bind="listConfig">
3
+ <template v-if="slots.header"><slot name="header"></slot></template>
4
+ <vxe-list ref="listRef" :class="{ grid }" v-bind="listConfig">
5
5
  <template #default="{ items }">
6
6
  <sh-empty v-if="items.length === 0 && !loading" :icon="emptyIcon" :content="emptyText"></sh-empty>
7
7
  <template v-if="groupSize">
8
8
  <sh-row v-for="(rows, rowsindex) in items" :key="rowsindex" class="sh-list-item" :gutter="grid.gutter" :margin="rowMargin">
9
9
  <sh-col v-for="(col, colindex) in rows" :key="colindex" :class="itemClassName" v-bind="grid">
10
- <slot v-if="$slots.item" name="item" v-bind="col"></slot>
10
+ <slot v-if="slots.item" name="item" v-bind="col"></slot>
11
11
  <div v-else :class="itemClassName">{{ col[labelField] }}</div>
12
12
  </sh-col>
13
13
  </sh-row>
@@ -15,7 +15,7 @@
15
15
  <template v-else-if="grid">
16
16
  <sh-row :gutter="grid.gutter" :margin="rowMargin">
17
17
  <sh-col v-for="(item, itemindex) in items" :key="itemindex" class="sh-list-item" :class="itemClassName" v-bind="grid">
18
- <slot v-if="$slots.item" name="item" v-bind="item"></slot>
18
+ <slot v-if="slots.item" name="item" v-bind="item"></slot>
19
19
  <div v-else :class="itemClassName">{{ item[labelField] }}</div>
20
20
  </sh-col>
21
21
  </sh-row>
@@ -29,13 +29,14 @@
29
29
  </template>
30
30
  </template>
31
31
  </vxe-list>
32
- <template v-if="$slots.footer"><slot name="footer"></slot></template>
32
+ <template v-if="slots.footer"><slot name="footer"></slot></template>
33
33
  <vxe-pager v-if="pagerConfig" v-bind="listPagerConfig" :loading="loading" @page-change="onPageChange"></vxe-pager>
34
34
  </div>
35
35
  </template>
36
36
 
37
37
  <script>
38
- export default {
38
+ import { defineComponent, ref, getCurrentInstance, computed } from 'vue'
39
+ export default defineComponent({
39
40
  name: 'ShList',
40
41
  props: {
41
42
  dataSourse: {
@@ -95,42 +96,46 @@ export default {
95
96
  }
96
97
  },
97
98
  emits: ['page-change'],
98
- data() {
99
- return {}
100
- },
101
- computed: {
102
- groupSize() {
103
- return this.grid && +this.grid.span > 0 && +this.grid.span < 24 ? 24 / this.grid.span : 0
104
- },
105
- listConfig() {
99
+ setup(props, context) {
100
+ const vm = getCurrentInstance()
101
+ const { $vUtils } = vm.proxy
102
+ const { emit, slots } = context
103
+ const listRef = ref()
104
+
105
+ const groupSize = computed(() => {
106
+ return props.grid && +props.grid.span > 0 && +props.grid.span < 24 ? 24 / props.grid.span : 0
107
+ })
108
+ const listConfig = computed(() => {
106
109
  return {
107
- data: this.groupSize ? this.$vUtils.chunk(this.$vUtils.clone(this.dataSourse, true), this.groupSize) : this.dataSourse,
108
- size: this.size,
109
- className: this.className,
110
- loading: this.loading,
111
- height: this.height,
112
- autoResize: this.autoResize,
113
- syncResize: this.syncResize,
114
- scrollY: Object.assign({ sItem: 'sh-list-item' }, this.scrollY)
110
+ data: groupSize.value ? $vUtils.chunk($vUtils.clone(props.dataSourse, true), groupSize.value) : props.dataSourse,
111
+ size: props.size,
112
+ className: props.className,
113
+ loading: props.loading,
114
+ height: props.height,
115
+ autoResize: props.autoResize,
116
+ syncResize: props.syncResize,
117
+ scrollY: Object.assign({ sItem: 'sh-list-item' }, props.scrollY)
115
118
  }
116
- },
117
- listPagerConfig() {
118
- return Object.assign({ enabled: this.pagerConfig, total: 0 }, this.pagerConfig)
119
- }
120
- },
121
- created() {},
122
- mounted() {},
123
- beforeUnmount() {},
124
- methods: {
125
- listRef() {
126
- return this.$refs.vxeList
127
- },
119
+ })
120
+ const listPagerConfig = computed(() => {
121
+ return Object.assign({ enabled: Boolean(props.pagerConfig), total: 0 }, props.pagerConfig)
122
+ })
123
+
128
124
  // 分页变化触发
129
- onPageChange(data) {
130
- this.$emit('page-change', data)
125
+ const onPageChange = data => {
126
+ emit('page-change', data)
127
+ }
128
+
129
+ return {
130
+ listRef,
131
+ slots,
132
+ groupSize,
133
+ listConfig,
134
+ listPagerConfig,
135
+ onPageChange
131
136
  }
132
137
  }
133
- }
138
+ })
134
139
  </script>
135
140
 
136
141
  <style lang="scss" scoped>
@@ -1,14 +1,14 @@
1
1
  <template>
2
- <div v-if="loading" size="large" class="sh-loading" :class="{ fix: fix }">
2
+ <div v-if="loading" class="sh-loading" :class="{ 'sh-loading-fix': fix }">
3
3
  <div class="loading" :class="`loading${loadingType}`"></div>
4
4
  <div v-if="content" class="loadtext">{{ content }}</div>
5
5
  </div>
6
6
  </template>
7
7
 
8
8
  <script>
9
- export default {
9
+ import { defineComponent, computed } from 'vue'
10
+ export default defineComponent({
10
11
  name: 'ShLoading',
11
- components: {},
12
12
  props: {
13
13
  type: {
14
14
  type: String,
@@ -21,12 +21,16 @@ export default {
21
21
  default: '加载中'
22
22
  }
23
23
  },
24
- computed: {
25
- loadingType() {
26
- return !this.type || this.type > 23 || this.type < 0 ? '12' : this.type
24
+ setup(props, context) {
25
+ const loadingType = computed(() => {
26
+ return !props.type || props.type > 23 || props.type < 0 ? '12' : props.type
27
+ })
28
+
29
+ return {
30
+ loadingType
27
31
  }
28
32
  }
29
- }
33
+ })
30
34
  </script>
31
35
 
32
36
  <style scoped lang="scss">
@@ -35,7 +39,7 @@ export default {
35
39
  z-index: 999;
36
40
  background: rgba(255, 255, 255, 0.5);
37
41
  padding: 0.5em;
38
- &.fix {
42
+ &-fix {
39
43
  position: absolute;
40
44
  top: 0;
41
45
  bottom: 0;
@@ -1,7 +1,7 @@
1
1
  <template>
2
2
  <vxe-modal
3
3
  :id="id"
4
- ref="vxeModal"
4
+ ref="modalRef"
5
5
  v-model="modalVisible"
6
6
  :title="title"
7
7
  :size="size"
@@ -30,7 +30,7 @@
30
30
  @close="onModalClose"
31
31
  @cancel="onModalClose"
32
32
  @confirm="onModalConfirm">
33
- <template v-for="slot in Object.keys($slots)" #[slot]="scope">
33
+ <template v-for="slot in Object.keys(slots)" #[slot]="scope">
34
34
  <!-- 以之前的名字命名插槽,同时把数据原样绑定 -->
35
35
  <slot :name="slot" v-bind="scope"></slot>
36
36
  </template>
@@ -49,7 +49,8 @@
49
49
  </template>
50
50
 
51
51
  <script>
52
- export default {
52
+ import { defineComponent, watch, ref } from 'vue'
53
+ export default defineComponent({
53
54
  name: 'ShModal',
54
55
  props: {
55
56
  visible: {
@@ -147,50 +148,58 @@ export default {
147
148
  }
148
149
  },
149
150
  emits: ['show', 'hide', 'zoom', 'confirm', 'close', 'update:visible'],
150
- data() {
151
- return {
152
- modalVisible: this.visible
153
- }
154
- },
155
- computed: {},
156
- watch: {
157
- visible() {
158
- this.modalVisible = this.visible
159
- },
160
- modalVisible(nv) {
161
- if (!nv) this.onModalClose()
162
- }
163
- },
164
- created() {},
165
- mounted() {},
166
- beforeUnmount() {},
167
- methods: {
168
- modalRef() {
169
- return this.$refs.vxeModal
170
- },
151
+ setup(props, context) {
152
+ const { emit, slots } = context
153
+ const modalRef = ref()
154
+ const modalVisible = ref(props.visible)
155
+
171
156
  // 弹窗显示回调
172
- onModalShow() {
173
- this.$emit('show')
174
- },
157
+ const onModalShow = () => {
158
+ emit('show')
159
+ }
175
160
  // 弹窗隐藏回调
176
- onModalHide() {
177
- this.$emit('hide')
178
- },
161
+ const onModalHide = () => {
162
+ emit('hide')
163
+ }
179
164
  // 弹窗全屏切换回调
180
- onModalZoom() {
181
- this.$emit('zoom')
182
- },
165
+ const onModalZoom = () => {
166
+ emit('zoom')
167
+ }
183
168
  // 确认操作
184
- onModalConfirm() {
185
- this.$emit('confirm')
186
- },
169
+ const onModalConfirm = () => {
170
+ emit('confirm')
171
+ }
187
172
  // 取消操作
188
- onModalClose() {
189
- this.$emit('close')
190
- this.$emit('update:visible', false)
173
+ const onModalClose = () => {
174
+ emit('close')
175
+ emit('update:visible', false)
176
+ }
177
+
178
+ watch(
179
+ () => props.visible,
180
+ value => {
181
+ modalVisible.value = value
182
+ }
183
+ )
184
+ watch(
185
+ () => modalVisible.value,
186
+ value => {
187
+ if (!value) onModalClose()
188
+ }
189
+ )
190
+
191
+ return {
192
+ modalRef,
193
+ slots,
194
+ modalVisible,
195
+ onModalShow,
196
+ onModalHide,
197
+ onModalZoom,
198
+ onModalClose,
199
+ onModalConfirm
191
200
  }
192
201
  }
193
- }
202
+ })
194
203
  </script>
195
204
 
196
205
  <style lang="scss" scoped>
@@ -8,8 +8,8 @@
8
8
  <sh-icon class="sh-notice-icon" :type="icon" size="20" />
9
9
  </template>
10
10
  </div>
11
- <div ref="wrap" class="sh-notice-bar-content" :class="[multiRows && 'sh-notice-bar-multi-content']">
12
- <div ref="content" :class="[overflow && scrollable && 'sh-notice-bar-content-animate']" :style="animateStyles">
11
+ <div ref="wrapRef" class="sh-notice-bar-content" :class="[multiRows && 'sh-notice-bar-multi-content']">
12
+ <div ref="contentRef" :class="[overflow && scrollable && 'sh-notice-bar-content-animate']" :style="animateStyles">
13
13
  <slot></slot>
14
14
  </div>
15
15
  </div>
@@ -25,9 +25,9 @@
25
25
  </template>
26
26
 
27
27
  <script>
28
- export default {
28
+ import { defineComponent, computed, onMounted, onUpdated, getCurrentInstance, ref } from 'vue'
29
+ export default defineComponent({
29
30
  name: 'ShNoticebar',
30
- components: {},
31
31
  props: {
32
32
  mode: {
33
33
  type: String,
@@ -71,74 +71,88 @@ export default {
71
71
  }
72
72
  },
73
73
  emits: ['close'],
74
- data() {
75
- return {
76
- isShow: true,
77
- overflow: false
78
- }
79
- },
80
- computed: {
81
- styles() {
74
+ setup(props, context) {
75
+ const vm = getCurrentInstance()
76
+ const { $vUtils } = vm.proxy
77
+ const { emit, slots } = context
78
+
79
+ const wrapRef = ref()
80
+ const contentRef = ref()
81
+ const isShow = ref(true)
82
+ const overflow = ref(false)
83
+
84
+ const styles = computed(() => {
82
85
  return {
83
- color: this.color,
84
- backgroundColor: this.$vUtils.fade(this.color, 30)
86
+ color: props.color,
87
+ backgroundColor: $vUtils.fade(props.color, 30)
85
88
  }
86
- },
87
- animateStyles() {
89
+ })
90
+ const animateStyles = computed(() => {
88
91
  return {
89
- animationDuration: this.speed + 's'
92
+ animationDuration: props.speed + 's'
90
93
  }
91
- },
92
- customLeft() {
93
- return Boolean(this.$slots.left)
94
- },
95
- customRight() {
96
- return Boolean(this.$slots.right)
97
- },
98
- rightIcon() {
99
- return this.mode === 'link' ? 'ios-arrow-forward' : 'md-close'
100
- }
101
- },
102
- watch: {},
103
- updated() {
104
- this.noticebarCheckOverflow()
105
- },
106
- mounted() {
107
- if (this.time) {
108
- this.noticebarHide(this.time)
109
- }
110
- this.noticebarCheckOverflow()
111
- },
112
- methods: {
113
- noticebarHide(time) {
94
+ })
95
+ const customLeft = computed(() => {
96
+ return Boolean(slots.left)
97
+ })
98
+ const customRight = computed(() => {
99
+ return Boolean(slots.right)
100
+ })
101
+ const rightIcon = computed(() => {
102
+ return props.mode === 'link' ? 'ios-arrow-forward' : 'md-close'
103
+ })
104
+
105
+ const noticebarHide = time => {
114
106
  setTimeout(() => {
115
- this.isShow = false
107
+ isShow.value = false
116
108
  }, time)
117
- },
118
- noticebarClose() {
119
- if (this.mode === 'closable' || this.closable) {
120
- this.isShow = false
109
+ }
110
+ const noticebarClose = () => {
111
+ if (props.mode === 'closable' || props.closable) {
112
+ isShow.value = false
121
113
  }
122
- this.$emit('close')
123
- },
124
- noticebarCheckOverflow() {
125
- if (!this.scrollable) {
114
+ emit('close')
115
+ }
116
+ const noticebarCheckOverflow = () => {
117
+ if (!props.scrollable) {
126
118
  return
127
119
  }
128
- const { wrap, content } = this.$refs
129
- if (!wrap || !content) {
120
+ if (!wrapRef.value || !contentRef.value) {
130
121
  return
131
122
  }
132
123
  /**
133
124
  * 计算 padding-left 对宽度的影响
134
125
  * 替换 clientWidth 为 getBoundingClientRect
135
126
  */
136
- const paddingLeft = window.getComputedStyle(content, null).getPropertyValue('padding').split(' ')[3] || '0px'
127
+ const paddingLeft = window.getComputedStyle(contentRef.value, null).getPropertyValue('padding').split(' ')[3] || '0px'
137
128
  const left = Number(paddingLeft.match(/\d+/g)[0])
138
- this.overflow = content.scrollWidth - left > Math.ceil(wrap.getBoundingClientRect().width)
129
+ overflow.value = contentRef.value.scrollWidth - left > Math.ceil(wrapRef.value.getBoundingClientRect().width)
130
+ }
131
+
132
+ onMounted(() => {
133
+ if (props.time) {
134
+ noticebarHide(props.time)
135
+ }
136
+ noticebarCheckOverflow()
137
+ })
138
+ onUpdated(() => {
139
+ noticebarCheckOverflow()
140
+ })
141
+
142
+ return {
143
+ contentRef,
144
+ wrapRef,
145
+ isShow,
146
+ styles,
147
+ customLeft,
148
+ overflow,
149
+ animateStyles,
150
+ customRight,
151
+ rightIcon,
152
+ noticebarClose
139
153
  }
140
154
  }
141
- }
155
+ })
142
156
  </script>
143
157
 
144
158
  <style lang="scss" scoped>