haiwei-ui 1.2.2 → 1.2.4

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "haiwei-ui",
3
- "version": "1.2.2",
3
+ "version": "1.2.4",
4
4
  "description": "HaiWei前端组件库",
5
5
  "author": "Eric",
6
6
  "license": "ISC",
@@ -0,0 +1,227 @@
1
+ <template>
2
+ <!--工具栏-->
3
+ <section class="nm-list-querybar">
4
+ <nm-form ref="normalForm" class="nm-list-querybar-normal" :model="model_" :rules="rules" :size="fontSize" :inline="true">
5
+ <slot />
6
+ <el-form-item v-if="!noSearch">
7
+ <nm-button type="primary" @click="query" :icon="!noSearchButtonIcon ? 'search' : ''" text="查询" />
8
+ </el-form-item>
9
+ <el-form-item v-if="!noReset">
10
+ <nm-button type="info" @click="reset" :icon="!noSearchButtonIcon ? 'refresh' : ''" text="重置" />
11
+ </el-form-item>
12
+ <el-form-item v-if="exportEnabled" v-nm-has="exportBtnCode">
13
+ <nm-button type="primary" @click="onExport" icon="export" text="导出" />
14
+ </el-form-item>
15
+ <el-form-item v-if="advanced_.enabled">
16
+ <nm-button ref="showAdvnacedBtn" type="warning" @click="onAdvancedClick">
17
+ 高级查询
18
+ <i class="el-icon--right" :class="[showAdvanced ? 'el-icon-arrow-up' : 'el-icon-arrow-down']"></i>
19
+ </nm-button>
20
+ </el-form-item>
21
+ <!--自定义按钮插槽-->
22
+ <el-form-item>
23
+ <slot name="buttons" />
24
+ </el-form-item>
25
+ </nm-form>
26
+
27
+ <!--高级查询框-->
28
+ <transition name="el-zoom-in-top">
29
+ <section ref="advancedBox" class="nm-list-querybar-advanced" v-if="advanced_.enabled" v-show="showAdvanced" :style="advancedStyle">
30
+ <nm-box page header footer title="高级查询" icon="search">
31
+ <template v-slot:toolbar>
32
+ <nm-button icon="close" @click="showAdvanced = false" />
33
+ </template>
34
+ <!--查询条件-->
35
+ <nm-form ref="advancedForm" :model="model_" :rules="rules" :label-width="advanced_.labelWidth" :inline="advanced_.inline">
36
+ <slot name="advanced" />
37
+ </nm-form>
38
+ <template v-slot:footer>
39
+ <!--查询按钮-->
40
+ <nm-button type="primary" @click="query" text="查询" :icon="!noSearchButtonIcon ? 'search' : ''" />
41
+ <!--重置按钮-->
42
+ <nm-button type="info" @click="reset" text="重置" :icon="!noSearchButtonIcon ? 'refresh' : ''" />
43
+ </template>
44
+ </nm-box>
45
+ <div ref="arrow" class="advanced-arrow" />
46
+ </section>
47
+ </transition>
48
+ </section>
49
+ </template>
50
+ <script>
51
+ const defaultAdvanced = {
52
+ // 是否开启
53
+ enabled: false,
54
+ // 宽度
55
+ width: '400px',
56
+ // 高度
57
+ height: '',
58
+ // 表单标签宽度
59
+ labelWidth: '100px',
60
+ // 内联表单
61
+ inline: false
62
+ }
63
+ export default {
64
+ data() {
65
+ return {
66
+ // 是否显示高级查询
67
+ showAdvanced: false,
68
+ // 动态计算的高度
69
+ dynamicHeight: ''
70
+ }
71
+ },
72
+ props: {
73
+ /** 输入框的宽度 */
74
+ inputWidth: {
75
+ type: String,
76
+ default: '160px'
77
+ },
78
+ /** 查询模型 */
79
+ model: Object,
80
+ /** 验证规则 */
81
+ rules: Object,
82
+ /** 高级查询属性 */
83
+ advanced: Object,
84
+ /** 不显示按钮图标 */
85
+ noSearchButtonIcon: Boolean,
86
+ /** 不需要查询 */
87
+ noSearch: Boolean,
88
+ /**不显示查询按钮 */
89
+ noReset: Boolean,
90
+ /**显示导出按钮 */
91
+ exportEnabled: Boolean,
92
+ /**导出按钮权限编码 */
93
+ exportBtnCode: String
94
+ },
95
+ computed: {
96
+ model_() {
97
+ return this.model || {}
98
+ },
99
+ /** 高级查询设置 */
100
+ advanced_() {
101
+ const ad = this.$_.merge({}, defaultAdvanced, this.advanced)
102
+ ad.enabled = ad.enabled && !this.noSearch
103
+ return ad
104
+ },
105
+ /** 高级查询框样式 */
106
+ advancedStyle() {
107
+ return {
108
+ width: this.advanced_.width,
109
+ height: this.advanced_.height || this.dynamicHeight
110
+ }
111
+ }
112
+ },
113
+ methods: {
114
+ query() {
115
+ this.$parent.page.index = 1
116
+ this.$parent.query()
117
+ // 如果高级查询框显示,重新计算高度
118
+ if (this.showAdvanced && !this.advanced_.height) {
119
+ this.$nextTick(() => {
120
+ this.calculateAdvancedHeight()
121
+ })
122
+ }
123
+ },
124
+ /** 表单重置 */
125
+ reset() {
126
+ if (this.$refs.normalForm) {
127
+ this.$refs.normalForm.reset()
128
+ }
129
+ if (this.$refs.advancedForm) {
130
+ this.$refs.advancedForm.reset()
131
+ }
132
+ this.$emit('reset')
133
+ },
134
+ validate(action) {
135
+ return this.$refs.normalForm.validate(action)
136
+ },
137
+ /** 计算高级查询框高度 */
138
+ calculateAdvancedHeight() {
139
+ if (!this.$refs.advancedBox) return
140
+
141
+ const $box = this.$refs.advancedBox
142
+ const boxHeader = $box.querySelector('.nm-box-header')?.offsetHeight || 0
143
+ const boxFooter = $box.querySelector('.nm-box-footer')?.offsetHeight || 0
144
+ const form = $box.querySelector('.nm-form')
145
+ if (!form) return
146
+
147
+ let boxHeight = form.offsetHeight + boxHeader + boxFooter + 20
148
+ if (!this.advanced_.inline) {
149
+ boxHeight += 20
150
+ }
151
+ $box.style.height = boxHeight + 'px'
152
+ // 保存动态计算的高度,避免后续样式被覆盖
153
+ this.dynamicHeight = boxHeight + 'px'
154
+ },
155
+
156
+ /** 高级查询按钮点击事件 */
157
+ onAdvancedClick() {
158
+ this.showAdvanced = !this.showAdvanced
159
+
160
+ if (this.showAdvanced) {
161
+ this.$nextTick(() => {
162
+ let $box = this.$refs.advancedBox
163
+ let $arrow = this.$refs.arrow
164
+ const boxWidth = $box.offsetWidth
165
+ const { x, y, width, height } = this.$refs.showAdvnacedBtn.$el.getBoundingClientRect()
166
+ let left = x + width / 2 - $box.offsetWidth / 2
167
+ // 判断右侧有没有超出页面
168
+ if (left + boxWidth > document.body.offsetWidth) {
169
+ left = document.body.offsetWidth - boxWidth - 20
170
+ // 计算箭头的位置
171
+ $arrow.style.left = x - left - 10 + width / 2 + 'px'
172
+ } else {
173
+ // 计算箭头的位置
174
+ $arrow.style.left = $box.offsetWidth / 2 + 'px'
175
+ }
176
+
177
+ $box.style.left = left + 'px'
178
+ $box.style.top = y + height + 14 + 'px'
179
+
180
+ // 设置高度
181
+ if (!this.advanced_.height) {
182
+ this.calculateAdvancedHeight()
183
+ }
184
+ })
185
+ }
186
+ },
187
+ onExport() {
188
+ this.$parent.triggerExport()
189
+ },
190
+ /** 设置输入框宽度 */
191
+ setInputWidths(formRef) {
192
+ if (!this.inputWidth || !formRef || !formRef.$el) return
193
+
194
+ let inputs = formRef.$el.querySelectorAll('.el-input__inner')
195
+ if (inputs) {
196
+ for (let i = 0; i < inputs.length; i++) {
197
+ const input = inputs[i]
198
+ // 检查是否有data-width属性,如果有则使用该值,否则使用inputWidth
199
+ const customWidth = input.getAttribute('data-width')
200
+ input.style.width = customWidth || this.inputWidth
201
+ }
202
+ }
203
+ }
204
+ },
205
+ mounted() {
206
+ this.$nextTick(() => {
207
+ this.$refs.normalForm.$el.addEventListener('keydown', e => {
208
+ if (e.keyCode === 13) {
209
+ this.query()
210
+ }
211
+ })
212
+ // 设置普通查询栏输入框宽度
213
+ this.setInputWidths(this.$refs.normalForm)
214
+ })
215
+ },
216
+ watch: {
217
+ showAdvanced(newVal) {
218
+ if (newVal && this.$refs.advancedForm) {
219
+ // 高级查询框显示时,设置其中的输入框宽度
220
+ this.$nextTick(() => {
221
+ this.setInputWidths(this.$refs.advancedForm)
222
+ })
223
+ }
224
+ }
225
+ }
226
+ }
227
+ </script>
@@ -1,7 +1,8 @@
1
1
  <template>
2
2
  <!--工具栏-->
3
3
  <section class="nm-list-querybar">
4
- <nm-form ref="normalForm" class="nm-list-querybar-normal" :model="model_" :rules="rules" :size="fontSize" :inline="true">
4
+ <nm-form ref="normalForm" class="nm-list-querybar-normal" :model="model_" :rules="rules" :size="fontSize"
5
+ :inline="true">
5
6
  <slot />
6
7
  <el-form-item v-if="!noSearch">
7
8
  <nm-button type="primary" @click="query" :icon="!noSearchButtonIcon ? 'search' : ''" text="查询" />
@@ -26,13 +27,15 @@
26
27
 
27
28
  <!--高级查询框-->
28
29
  <transition name="el-zoom-in-top">
29
- <section ref="advancedBox" class="nm-list-querybar-advanced" v-if="advanced_.enabled" v-show="showAdvanced" :style="advancedStyle">
30
+ <section ref="advancedBox" class="nm-list-querybar-advanced" v-if="advanced_.enabled" v-show="showAdvanced"
31
+ :style="advancedStyle">
30
32
  <nm-box page header footer title="高级查询" icon="search">
31
33
  <template v-slot:toolbar>
32
34
  <nm-button icon="close" @click="showAdvanced = false" />
33
35
  </template>
34
36
  <!--查询条件-->
35
- <nm-form ref="advancedForm" :model="model_" :rules="rules" :label-width="advanced_.labelWidth" :inline="advanced_.inline">
37
+ <nm-form ref="advancedForm" :model="model_" :rules="rules" :label-width="advanced_.labelWidth"
38
+ :inline="advanced_.inline">
36
39
  <slot name="advanced" />
37
40
  </nm-form>
38
41
  <template v-slot:footer>
@@ -48,184 +51,166 @@
48
51
  </section>
49
52
  </template>
50
53
  <script>
51
- const defaultAdvanced = {
52
- // 是否开启
53
- enabled: false,
54
- // 宽度
55
- width: '400px',
56
- // 高度
57
- height: '',
58
- // 表单标签宽度
59
- labelWidth: '100px',
60
- // 内联表单
61
- inline: false
62
- }
63
- export default {
64
- data() {
54
+ const defaultAdvanced = {
55
+ // 是否开启
56
+ enabled: false,
57
+ // 宽度
58
+ width: '400px',
59
+ // 高度
60
+ height: '',
61
+ // 表单标签宽度
62
+ labelWidth: '100px',
63
+ // 内联表单
64
+ inline: false
65
+ }
66
+ export default {
67
+ data() {
68
+ return {
69
+ // 是否显示高级查询
70
+ showAdvanced: false,
71
+ // 动态计算的高度
72
+ dynamicHeight: ''
73
+ }
74
+ },
75
+ props: {
76
+ /** 输入框的宽度 */
77
+ inputWidth: {
78
+ type: String,
79
+ default: '160px'
80
+ },
81
+ /** 查询模型 */
82
+ model: Object,
83
+ /** 验证规则 */
84
+ rules: Object,
85
+ /** 高级查询属性 */
86
+ advanced: Object,
87
+ /** 不显示按钮图标 */
88
+ noSearchButtonIcon: Boolean,
89
+ /** 不需要查询 */
90
+ noSearch: Boolean,
91
+ /**不显示查询按钮 */
92
+ noReset: Boolean,
93
+ /**显示导出按钮 */
94
+ exportEnabled: Boolean,
95
+ /**导出按钮权限编码 */
96
+ exportBtnCode: String
97
+ },
98
+ computed: {
99
+ model_() {
100
+ return this.model || {}
101
+ },
102
+ /** 高级查询设置 */
103
+ advanced_() {
104
+ const ad = this.$_.merge({}, defaultAdvanced, this.advanced)
105
+ ad.enabled = ad.enabled && !this.noSearch
106
+ return ad
107
+ },
108
+ /** 高级查询框样式 */
109
+ advancedStyle() {
65
110
  return {
66
- // 是否显示高级查询
67
- showAdvanced: false,
68
- // 动态计算的高度
69
- dynamicHeight: ''
111
+ width: this.advanced_.width,
112
+ height: this.advanced_.height || this.dynamicHeight
113
+ }
114
+ }
115
+ },
116
+ methods: {
117
+ query() {
118
+ this.$parent.page.index = 1
119
+ this.$parent.query()
120
+ // 如果高级查询框显示,重新计算高度
121
+ if (this.showAdvanced && !this.advanced_.height) {
122
+ this.$nextTick(() => {
123
+ this.calculateAdvancedHeight()
124
+ })
70
125
  }
71
126
  },
72
- props: {
73
- /** 输入框的宽度 */
74
- inputWidth: {
75
- type: String,
76
- default: '160px'
77
- },
78
- /** 查询模型 */
79
- model: Object,
80
- /** 验证规则 */
81
- rules: Object,
82
- /** 高级查询属性 */
83
- advanced: Object,
84
- /** 不显示按钮图标 */
85
- noSearchButtonIcon: Boolean,
86
- /** 不需要查询 */
87
- noSearch: Boolean,
88
- /**不显示查询按钮 */
89
- noReset: Boolean,
90
- /**显示导出按钮 */
91
- exportEnabled: Boolean,
92
- /**导出按钮权限编码 */
93
- exportBtnCode: String
94
- },
95
- computed: {
96
- model_() {
97
- return this.model || {}
98
- },
99
- /** 高级查询设置 */
100
- advanced_() {
101
- const ad = this.$_.merge({}, defaultAdvanced, this.advanced)
102
- ad.enabled = ad.enabled && !this.noSearch
103
- return ad
104
- },
105
- /** 高级查询框样式 */
106
- advancedStyle() {
107
- return {
108
- width: this.advanced_.width,
109
- height: this.advanced_.height || this.dynamicHeight
110
- }
127
+ /** 表单重置 */
128
+ reset() {
129
+ if (this.$refs.normalForm) {
130
+ this.$refs.normalForm.reset()
111
131
  }
132
+ if (this.$refs.advancedForm) {
133
+ this.$refs.advancedForm.reset()
134
+ }
135
+ this.$emit('reset')
112
136
  },
113
- methods: {
114
- query() {
115
- this.$parent.page.index = 1
116
- this.$parent.query()
117
- // 如果高级查询框显示,重新计算高度
118
- if (this.showAdvanced && !this.advanced_.height) {
119
- this.$nextTick(() => {
120
- this.calculateAdvancedHeight()
121
- })
122
- }
123
- },
124
- /** 表单重置 */
125
- reset() {
126
- if (this.$refs.normalForm) {
127
- this.$refs.normalForm.reset()
128
- }
129
- if (this.$refs.advancedForm) {
130
- this.$refs.advancedForm.reset()
131
- }
132
- this.$emit('reset')
133
- },
134
- validate(action) {
135
- return this.$refs.normalForm.validate(action)
136
- },
137
- /** 计算高级查询框高度 */
138
- calculateAdvancedHeight() {
139
- if (!this.$refs.advancedBox) return
137
+ validate(action) {
138
+ return this.$refs.normalForm.validate(action)
139
+ },
140
+ /** 计算高级查询框高度 */
141
+ calculateAdvancedHeight() {
142
+ if (!this.$refs.advancedBox) return
140
143
 
141
- const $box = this.$refs.advancedBox
142
- const boxHeader = $box.querySelector('.nm-box-header')?.offsetHeight || 0
143
- const boxFooter = $box.querySelector('.nm-box-footer')?.offsetHeight || 0
144
- const form = $box.querySelector('.nm-form')
145
- if (!form) return
144
+ const $box = this.$refs.advancedBox
145
+ const boxHeader = $box.querySelector('.nm-box-header')?.offsetHeight || 0
146
+ const boxFooter = $box.querySelector('.nm-box-footer')?.offsetHeight || 0
147
+ const form = $box.querySelector('.nm-form')
148
+ if (!form) return
146
149
 
147
- let boxHeight = form.offsetHeight + boxHeader + boxFooter + 20
148
- if (!this.advanced_.inline) {
149
- boxHeight += 20
150
- }
151
- $box.style.height = boxHeight + 'px'
152
- // 保存动态计算的高度,避免后续样式被覆盖
153
- this.dynamicHeight = boxHeight + 'px'
154
- },
150
+ let boxHeight = form.offsetHeight + boxHeader + boxFooter + 20
151
+ if (!this.advanced_.inline) {
152
+ boxHeight += 20
153
+ }
154
+ $box.style.height = boxHeight + 'px'
155
+ // 保存动态计算的高度,避免后续样式被覆盖
156
+ this.dynamicHeight = boxHeight + 'px'
157
+ },
155
158
 
156
- /** 高级查询按钮点击事件 */
157
- onAdvancedClick() {
158
- this.showAdvanced = !this.showAdvanced
159
+ /** 高级查询按钮点击事件 */
160
+ onAdvancedClick() {
161
+ this.showAdvanced = !this.showAdvanced
159
162
 
160
- if (this.showAdvanced) {
161
- this.$nextTick(() => {
162
- let $box = this.$refs.advancedBox
163
- let $arrow = this.$refs.arrow
164
- const boxWidth = $box.offsetWidth
165
- const { x, y, width, height } = this.$refs.showAdvnacedBtn.$el.getBoundingClientRect()
166
- let left = x + width / 2 - $box.offsetWidth / 2
167
- // 判断右侧有没有超出页面
168
- if (left + boxWidth > document.body.offsetWidth) {
169
- left = document.body.offsetWidth - boxWidth - 20
170
- // 计算箭头的位置
171
- $arrow.style.left = x - left - 10 + width / 2 + 'px'
172
- } else {
173
- // 计算箭头的位置
174
- $arrow.style.left = $box.offsetWidth / 2 + 'px'
175
- }
163
+ if (this.showAdvanced) {
164
+ this.$nextTick(() => {
165
+ let $box = this.$refs.advancedBox
166
+ let $arrow = this.$refs.arrow
167
+ const boxWidth = $box.offsetWidth
168
+ const { x, y, width, height } = this.$refs.showAdvnacedBtn.$el.getBoundingClientRect()
169
+ let left = x + width / 2 - $box.offsetWidth / 2
170
+ // 判断右侧有没有超出页面
171
+ if (left + boxWidth > document.body.offsetWidth) {
172
+ left = document.body.offsetWidth - boxWidth - 20
173
+ // 计算箭头的位置
174
+ $arrow.style.left = x - left - 10 + width / 2 + 'px'
175
+ } else {
176
+ // 计算箭头的位置
177
+ $arrow.style.left = $box.offsetWidth / 2 + 'px'
178
+ }
176
179
 
177
- $box.style.left = left + 'px'
178
- $box.style.top = y + height + 14 + 'px'
180
+ $box.style.left = left + 'px'
181
+ $box.style.top = y + height + 14 + 'px'
179
182
 
180
- // 设置高度
181
- if (!this.advanced_.height) {
182
- this.calculateAdvancedHeight()
183
- }
184
- })
183
+ // 设置高度
184
+ if (!this.advanced_.height) {
185
+ this.calculateAdvancedHeight()
186
+ }
187
+ })
188
+ }
189
+ },
190
+ onExport() {
191
+ this.$parent.triggerExport()
192
+ }
193
+ },
194
+ mounted() {
195
+ this.$nextTick(() => {
196
+ this.$refs.normalForm.$el.addEventListener('keydown', e => {
197
+ if (e.keyCode === 13) {
198
+ this.query()
185
199
  }
186
- },
187
- onExport() {
188
- this.$parent.triggerExport()
189
- },
190
- /** 设置输入框宽度 */
191
- setInputWidths(formRef) {
192
- if (!this.inputWidth || !formRef || !formRef.$el) return
193
-
194
- let inputs = formRef.$el.querySelectorAll('.el-input__inner')
200
+ })
201
+ if (this.inputWidth) {
202
+ let inputs = this.$refs.normalForm.$el.querySelectorAll('.el-input__inner')
195
203
  if (inputs) {
196
204
  for (let i = 0; i < inputs.length; i++) {
197
- const input = inputs[i]
198
-
205
+ // inputs[i].style.width = this.inputWidth
206
+ const input = inputs[i]
199
207
  // 检查是否有data-width属性,如果有则使用该值,否则使用inputWidth
200
208
  const customWidth = input.getAttribute('data-width')
201
-
202
- console.log('data-width============>1',customWidth)
203
- input.style.width = customWidth || this.inputWidth
204
- console.log('input.style.width==========>2',input.style.width)
209
+ input.style.width = customWidth || this.inputWidth
205
210
  }
206
211
  }
207
212
  }
208
- },
209
- mounted() {
210
- this.$nextTick(() => {
211
- this.$refs.normalForm.$el.addEventListener('keydown', e => {
212
- if (e.keyCode === 13) {
213
- this.query()
214
- }
215
- })
216
- // 设置普通查询栏输入框宽度
217
- this.setInputWidths(this.$refs.normalForm)
218
- })
219
- },
220
- watch: {
221
- showAdvanced(newVal) {
222
- if (newVal && this.$refs.advancedForm) {
223
- // 高级查询框显示时,设置其中的输入框宽度
224
- this.$nextTick(() => {
225
- this.setInputWidths(this.$refs.advancedForm)
226
- })
227
- }
228
- }
229
- }
213
+ })
230
214
  }
215
+ }
231
216
  </script>
@@ -81,8 +81,19 @@ export default {
81
81
  },
82
82
  mounted() {
83
83
  this.refresh()
84
+ this.$nextTick(() => {
85
+ this.setDataWidth()
86
+ })
84
87
  },
85
88
  methods: {
89
+ // 设置data-width属性到内部的input元素
90
+ setDataWidth() {
91
+ if (!this.$el) return
92
+ const input = this.$el.querySelector('.el-input__inner')
93
+ if (input && this.$attrs['data-width']) {
94
+ input.setAttribute('data-width', this.$attrs['data-width'])
95
+ }
96
+ },
86
97
  // 刷新
87
98
  refresh() {
88
99
  //远程搜索使用远程方法
@@ -201,6 +212,9 @@ export default {
201
212
  remote: this.remote,
202
213
  remoteMethod: this.remoteMethod
203
214
  },
215
+ attrs: {
216
+ 'data-width': this.$attrs['data-width'] || ''
217
+ },
204
218
  on: {
205
219
  change: this.onChange,
206
220
  'visible-change': this.onVisibleChange,