sh-tools 2.2.14 → 2.2.16

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": "sh-tools",
3
- "version": "2.2.14",
3
+ "version": "2.2.16",
4
4
  "description": "基于fetch和xe-utils二次封装,支持宏公式计算,及notification提示窗",
5
5
  "main": "packages/index.js",
6
6
  "scripts": {
@@ -13,7 +13,7 @@
13
13
  "license": "ISC",
14
14
  "dependencies": {
15
15
  "hot-formula-parser": "^4.0.0",
16
- "xe-utils": "^3.5.22"
16
+ "xe-utils": "^3.7.0"
17
17
  },
18
18
  "devDependencies": {
19
19
  "@babel/core": "^7.12.16",
@@ -1,5 +1,3 @@
1
- import Notice from '../components/sh-notification'
2
-
3
1
  // fetch文档: https://developer.mozilla.org/en-US/docs/Web/API/fetch
4
2
 
5
3
  class HttpRequest {
@@ -62,27 +60,9 @@ class HttpRequest {
62
60
  }
63
61
  // 响应拦截器
64
62
  async responseInterceptors(response, request) {
65
- const { status, statusText, headers } = response
66
63
  let resBody = response
67
64
  if (request.bodyType === 'json') {
68
65
  resBody = await response.json()
69
- let errorMsg = resBody.msg || resBody.message || resBody.result || resBody.error || statusText || '系统错误'
70
- switch (status) {
71
- case 0:
72
- Notice.error({ title: '请求错误', content: errorMsg })
73
- break
74
- case 200:
75
- break
76
- case 401:
77
- Notice.error({ title: '系统提示 401', content: '未授权,请重新登录' })
78
- return
79
- case 504:
80
- Notice.error({ title: '系统提示 网络超时', content: errorMsg })
81
- break
82
- default:
83
- Notice.error({ title: `系统提示 ${status}`, content: errorMsg })
84
- break
85
- }
86
66
  }
87
67
  return resBody
88
68
  }
package/packages/index.js CHANGED
@@ -2,6 +2,4 @@ import http from './api/index'
2
2
 
3
3
  import utils from './utils/index'
4
4
 
5
- import notice from './components/sh-notification'
6
-
7
- export { http, utils, notice }
5
+ export { http, utils }
@@ -7,15 +7,15 @@ export default {
7
7
  if (dateDiff.done) {
8
8
  if (dateDiff.time < 10000) {
9
9
  return '刚刚'
10
- }else if(dateDiff.time < 60000) {
10
+ } else if (dateDiff.time < 60000) {
11
11
  return `${dateDiff.ss}秒之前`
12
- }else if(dateDiff.time < 360000) {
12
+ } else if (dateDiff.time < 360000) {
13
13
  return `${dateDiff.mm}分钟之前`
14
- }else if(dateDiff.time < 86400000) {
14
+ } else if (dateDiff.time < 86400000) {
15
15
  return `${dateDiff.HH}小时之前`
16
- }else if(dateDiff.time < 2592000000) {
16
+ } else if (dateDiff.time < 2592000000) {
17
17
  return `${dateDiff.dd}天之前`
18
- }else if(dateDiff.time < 31536000000) {
18
+ } else if (dateDiff.time < 31536000000) {
19
19
  return `${dateDiff.MM}个月之前`
20
20
  }
21
21
  return `${dateDiff.yyyy}年之前`
@@ -148,7 +148,7 @@ export default {
148
148
  // editable: 是否对返回值进行修正 默认 否
149
149
  let rvalue, rtext, rname
150
150
  let { $vUtils, $vxePluginNames } = renderContext
151
- let { min, max, digits, type, multiple, split, range, options, format, nodeKey, labelField, moneyUnit, commafy, openValue, openLabel, closeValue, closeLabel, bill, defaultValue } = renderProps
151
+ let { min, max, digits, type, multiple, split, options, callvalue, format, nodeKey, labelField, moneyUnit, openValue, openLabel, closeValue, closeLabel, defaultValue } = renderProps || {}
152
152
  let defaultDateFormat = {
153
153
  date: 'yyyy-MM-dd',
154
154
  time: 'HH:mm:ss',
@@ -165,8 +165,6 @@ export default {
165
165
  }
166
166
  // 对于多选获取数组类型值进行解析 赋值
167
167
  let oriArray = []
168
- // 是否需要对原值进行重写 默认为false
169
- let resetValue = false
170
168
  // 配置公式,优先取解析后的嵌套公式
171
169
  let formula = $vUtils.get(renderProps, `formulaMap.${key}`) || renderProps.formula
172
170
  // 进行默认赋值 若没有任何解析原数返回
@@ -196,20 +194,15 @@ export default {
196
194
  }
197
195
  if (rname === '$vMoney' && !$vUtils.isNone(rvalue)) {
198
196
  rtext = $vUtils.truncate($vUtils.divide(rvalue, moneyUnit), digits)
199
- }else if(rname === '$vInput' && format) {
197
+ } else if (rname === '$vInput' && format) {
200
198
  rtext = $vUtils.format(format, rowData)
201
199
  }
202
- if (commafy && !bill && bill !== '0') rtext = $vUtils.commafy(rtext, { digits }).replace(/0+$/, '').replace(/\.+$/, '')
203
200
  break
204
201
  case '$vTime':
205
202
  format = format ? format.replace('YYYY', 'yyyy').replace('DD', 'dd').replace('hh', 'HH') : defaultDateFormat[type]
206
203
  if ($vUtils.isNumber(value)) value = String(value)
207
- if (range && Array.isArray(value) && format) {
208
- rvalue = value.map(item => $vUtils.toDateString(item || '', format))
209
- resetValue = true
210
- } else if (!$vUtils.isNone(value) && format) {
204
+ if (!$vUtils.isNone(value) && format) {
211
205
  rvalue = $vUtils.toDateString(value, format)
212
- resetValue = true
213
206
  }
214
207
  break
215
208
  case '$vSelect':
@@ -217,7 +210,13 @@ export default {
217
210
  case '$vRadiogroup':
218
211
  case '$vUpload':
219
212
  case '$vTree':
220
- let prefixKey = key.endsWith('Id') ? String(key).replace('Id', '') : key
213
+ let prefixKey = key
214
+ const endStrs = ['Id', '_id']
215
+ endStrs.forEach(end => {
216
+ if (String(key).endsWith(end)) {
217
+ prefixKey = key.replace(end, '')
218
+ }
219
+ })
221
220
  let isMutiple = multiple || ['$vCheckgroup', '$vUpload'].includes(rname)
222
221
  let optionValue = 'value'
223
222
  let optionLabel = 'label'
@@ -263,11 +262,15 @@ export default {
263
262
  }
264
263
  break
265
264
  }
266
- if ($vUtils.isString(rvalue)) rvalue = $vUtils.replaceNutrim(rvalue)
267
- if (formula || resetValue) {
265
+ if ($vUtils.isString(rvalue)) {
266
+ rvalue = $vUtils.replaceNutrim(rvalue)
267
+ }
268
+ if (formula && !callvalue) {
268
269
  $vUtils.set(rowData, key, rvalue)
269
270
  }
270
- rtext = rtext || rvalue
271
+ if ($vUtils.isNone(rtext) && !$vUtils.isNone(rvalue)) {
272
+ rtext = rvalue
273
+ }
271
274
  return { rvalue, rtext }
272
275
  }
273
276
  }
@@ -15,7 +15,7 @@ function format(format, data, toNumber) {
15
15
  let formatStr = String(format)
16
16
  keys.map((key, indexkey) => {
17
17
  let value = XEUtils.get(data, key) || ''
18
- if(toNumber) value = XEUtils.toNumber(value)
18
+ if (toNumber) value = XEUtils.toNumber(value)
19
19
  formatStr = formatStr.replace(new RegExp('{' + key + '}', 'ig'), value)
20
20
  })
21
21
  return formatStr
@@ -37,7 +37,7 @@ export default {
37
37
  getFormatKeys,
38
38
  format,
39
39
  replaceNutrim(str) {
40
- return String(str).replace(/null|undefined|(^\s*)|(\s*$)/gi, '')
40
+ return String(str).replace(/undefined|(^\s*)|(\s*$)/gi, '')
41
41
  },
42
42
  replaceAll(str, from, to) {
43
43
  // 替换全部 将str中的所有from替换为to
@@ -1,55 +0,0 @@
1
- import { createApp } from 'vue'
2
- import Notification from './notification.vue'
3
-
4
- let instances = []
5
- let seed = 0
6
- const now = Date.now()
7
- function getUuid() {
8
- return 'ShNotification_' + now + '_' + seed++
9
- }
10
-
11
- function notice(type, options) {
12
- const option = Object.assign({ title: '提示', id: getUuid(), type, placement: 'right-top', offset: 10 }, options)
13
- option.onClose = nid => {
14
- const inss = instances.filter(n => n.placement.startsWith(option.placement))
15
- const idx = inss.findIndex(n => n.id === nid)
16
- const ins = inss[idx]
17
- const ykey = option.placement.split('-')[1]
18
- if (idx > -1 && ins) {
19
- for (let i = idx + 1; i < inss.length; i++) {
20
- const cmpcss = getComputedStyle(inss[i].$el)
21
- const y = parseInt(cmpcss[ykey]) || 0
22
- inss[i].show(y - ins.$el.offsetHeight - option.offset + 'px')
23
- }
24
- instances = instances.filter(n => n.id !== nid)
25
- }
26
- }
27
- const notification = createApp(Notification, option)
28
- const dom = document.createElement('div')
29
- const ins = notification.mount(dom)
30
- const inss = instances.filter(n => n.placement.startsWith(option.placement))
31
- document.body.appendChild(ins.$el)
32
- let y = option.offset
33
- inss.forEach(n => (y += n.$el.offsetHeight + option.offset))
34
- ins.show(y + 'px')
35
- instances.push(ins)
36
- return { option, ins }
37
- }
38
-
39
- export default {
40
- open(options) {
41
- return notice('', options)
42
- },
43
- info(options) {
44
- return notice('info', options)
45
- },
46
- success(options) {
47
- return notice('success', options)
48
- },
49
- warning(options) {
50
- return notice('warning', options)
51
- },
52
- error(options) {
53
- return notice('error', options)
54
- }
55
- }
@@ -1,212 +0,0 @@
1
- <template>
2
- <transition :name="transtionName">
3
- <div v-if="visible" class="sh-notification" :class="classes" :style="styles">
4
- <svg v-if="['info', 'success', 'warning', 'error'].includes(type)" class="sh-notification-icon" :fill="colorStyle[type]" viewBox="64 64 896 896">
5
- <template v-if="type === 'info'">
6
- <path
7
- d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372 372 166.6 372 372-166.6 372-372 372z"></path>
8
- <path d="M464 336a48 48 0 1 0 96 0 48 48 0 1 0-96 0zm72 112h-48c-4.4 0-8 3.6-8 8v272c0 4.4 3.6 8 8 8h48c4.4 0 8-3.6 8-8V456c0-4.4-3.6-8-8-8z"></path>
9
- </template>
10
- <template v-else-if="type === 'success'">
11
- <path
12
- d="M699 353h-46.9c-10.2 0-19.9 4.9-25.9 13.3L469 584.3l-71.2-98.8c-6-8.3-15.6-13.3-25.9-13.3H325c-6.5 0-10.3 7.4-6.5 12.7l124.6 172.8a31.8 31.8 0 0 0 51.7 0l210.6-292c3.9-5.3.1-12.7-6.4-12.7z"></path>
13
- <path
14
- d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372 372 166.6 372 372-166.6 372-372 372z"></path>
15
- </template>
16
- <template v-else-if="type === 'warning'">
17
- <path
18
- d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372 372 166.6 372 372-166.6 372-372 372z"></path>
19
- <path d="M464 688a48 48 0 1 0 96 0 48 48 0 1 0-96 0zm24-112h48c4.4 0 8-3.6 8-8V296c0-4.4-3.6-8-8-8h-48c-4.4 0-8 3.6-8 8v272c0 4.4 3.6 8 8 8z"></path>
20
- </template>
21
- <template v-else-if="type === 'error'">
22
- <path
23
- d="M685.4 354.8c0-4.4-3.6-8-8-8l-66 .3L512 465.6l-99.3-118.4-66.1-.3c-4.4 0-8 3.5-8 8 0 1.9.7 3.7 1.9 5.2l130.1 155L340.5 670a8.32 8.32 0 0 0-1.9 5.2c0 4.4 3.6 8 8 8l66.1-.3L512 564.4l99.3 118.4 66 .3c4.4 0 8-3.5 8-8 0-1.9-.7-3.7-1.9-5.2L553.5 515l130.1-155c1.2-1.4 1.8-3.3 1.8-5.2z"></path>
24
- <path
25
- d="M512 65C264.6 65 64 265.6 64 513s200.6 448 448 448 448-200.6 448-448S759.4 65 512 65zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372 372 166.6 372 372-166.6 372-372 372z"></path>
26
- </template>
27
- </svg>
28
- <div class="sh-notification-content">
29
- <div class="sh-notification-title">
30
- <u v-html="title"></u>
31
- <a class="sh-notification-close" @click="close()">&times;</a>
32
- </div>
33
- <div v-if="content" class="sh-notification-description" v-html="content"></div>
34
- </div>
35
- </div>
36
- </transition>
37
- </template>
38
-
39
- <script>
40
- export default {
41
- name: 'ShNotification',
42
- props: {
43
- nid: String,
44
- type: String,
45
- duration: {
46
- type: Number,
47
- default: 3000
48
- },
49
- placement: {
50
- type: String,
51
- default: 'right-top' // left-top,right-top,left-bottom,right-bottom
52
- },
53
- title: String,
54
- content: String,
55
- className: String,
56
- beforeClose: Function,
57
- onClose: Function
58
- },
59
- data() {
60
- return {
61
- colorStyle: {
62
- info: '#1890FF',
63
- success: '#25ad4a',
64
- error: '#ff3552',
65
- warning: '#faad14'
66
- },
67
- visible: false,
68
- vmOffset: 0,
69
- timer: null
70
- }
71
- },
72
- computed: {
73
- transtionName() {
74
- return 'notice-fade-' + this.placement.split('-')[0]
75
- },
76
- classes() {
77
- return {
78
- right: this.placement.startsWith('right'),
79
- left: this.placement.startsWith('left'),
80
- simple: !this.content
81
- }
82
- },
83
- styles() {
84
- let result = {}
85
- const Y = this.placement.split('-')[1]
86
- if (Y) result[Y] = this.vmOffset
87
- return result
88
- }
89
- },
90
- mounted() {
91
- this.createTimer()
92
- },
93
- unmounted() {
94
- this.clearTimer()
95
- },
96
- methods: {
97
- createTimer() {
98
- if (this.duration) {
99
- this.timer = setTimeout(() => {
100
- this.close()
101
- }, this.duration)
102
- }
103
- },
104
- clearTimer() {
105
- if (this.timer) {
106
- clearTimeout(this.timer)
107
- }
108
- },
109
- show(top) {
110
- this.visible = true
111
- this.vmOffset = top
112
- },
113
- close() {
114
- if (this.visible && this.onClose) {
115
- this.beforeClose && this.beforeClose(this)
116
- this.onClose(this.nid, this)
117
- this.visible = false
118
- }
119
- }
120
- }
121
- }
122
- </script>
123
-
124
- <style scoped lang="scss">
125
- .sh-notification {
126
- border-radius: 5px;
127
- color: #333;
128
- display: inline-flex;
129
- align-items: flex-start;
130
- padding: 15px;
131
- margin-bottom: 10px;
132
- width: 400px;
133
- max-width: 90%;
134
- position: fixed;
135
- z-index: 3000;
136
- box-shadow: 0 0 8px rgba(0, 0, 0, 0.12);
137
- background: #fff;
138
- overflow: hidden;
139
- vertical-align: top;
140
- right: 15px;
141
- transition: opacity 0.2s, transform 0.2s, left 0.2s, right 0.2s, top 0.3s, bottom 0.2s;
142
- &.right {
143
- right: 15px;
144
- left: auto;
145
- }
146
- &.left {
147
- left: 15px;
148
- right: auto;
149
- }
150
- &.simple {
151
- .sh-notification-icon {
152
- width: 22px;
153
- }
154
- }
155
- &-icon {
156
- line-height: 1;
157
- display: inline-block;
158
- width: 33px;
159
- margin: 2px 15px 0 5px;
160
- }
161
- &-content {
162
- flex: 1;
163
- .sh-notification-title {
164
- width: 100%;
165
- display: flex;
166
- align-items: center;
167
- font-size: 18px;
168
- line-height: 24px;
169
- & > u {
170
- flex: 1;
171
- display: block;
172
- text-decoration: none;
173
- font-weight: normal;
174
-
175
- padding-right: 5px;
176
- }
177
- .sh-notification-close {
178
- display: inline-block;
179
- cursor: pointer;
180
- padding: 0 5px;
181
- color: inherit;
182
- vertical-align: top;
183
- }
184
- }
185
- .sh-notification-description {
186
- display: block;
187
- width: 100%;
188
- margin-top: 8px;
189
- color: #666;
190
- }
191
- }
192
- }
193
- .notice-fade-left,
194
- .notice-fade-right {
195
- &-enter-active,
196
- &-leave-active {
197
- transition: transform 150ms ease-in-out;
198
- }
199
- }
200
- .notice-fade-left {
201
- &-enter-from,
202
- &-leave-to {
203
- transform: translateX(-100%);
204
- }
205
- }
206
- .notice-fade-right {
207
- &-enter-from,
208
- &-leave-to {
209
- transform: translateX(100%);
210
- }
211
- }
212
- </style>