sh-tools 1.2.7 → 1.3.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sh-tools",
3
- "version": "1.2.7",
3
+ "version": "1.3.0",
4
4
  "description": "基于xe-ajax和xe-utils二次封装",
5
5
  "main": "packages/index.js",
6
6
  "scripts": {
@@ -13,7 +13,6 @@
13
13
  "license": "ISC",
14
14
  "dependencies": {
15
15
  "hot-formula-parser": "^4.0.0",
16
- "view-ui-plus": "^1.3.14",
17
16
  "xe-ajax": "^4.0.5",
18
17
  "xe-utils": "^3.5.11"
19
18
  },
@@ -1,5 +1,5 @@
1
1
  import XEAjax from 'xe-ajax'
2
- import { Notice } from 'view-ui-plus'
2
+ import Notice from '../components/sh-notification'
3
3
 
4
4
  class HttpRequest {
5
5
  constructor(options = {}) {
@@ -53,7 +53,6 @@ class HttpRequest {
53
53
  // 错误处理
54
54
  async responseNext(response, next) {
55
55
  const { status, statusText, headers } = response
56
- const duration = 5
57
56
  let resBody = null
58
57
  try {
59
58
  resBody = await response.json()
@@ -63,18 +62,18 @@ class HttpRequest {
63
62
  let errorMsg = resBody.error || resBody.msg || resBody.message || resBody.result || statusText || '系统错误'
64
63
  switch (status) {
65
64
  case 0:
66
- Notice.error({ title: '请求错误', desc: errorMsg, duration: duration })
65
+ Notice.error({ title: '请求错误', content: errorMsg })
67
66
  break
68
67
  case 200:
69
68
  break
70
69
  case 401:
71
- Notice.error({ title: '系统提示 401', desc: '未授权,请重新登录', duration: duration })
70
+ Notice.error({ title: '系统提示 401', content: '未授权,请重新登录' })
72
71
  return
73
72
  case 504:
74
- Notice.error({ title: '系统提示 网络超时', desc: errorMsg, duration: duration })
73
+ Notice.error({ title: '系统提示 网络超时', content: errorMsg })
75
74
  break
76
75
  default:
77
- Notice.error({ title: `系统提示 ${status}`, desc: errorMsg, duration: duration })
76
+ Notice.error({ title: `系统提示 ${status}`, content: errorMsg })
78
77
  break
79
78
  }
80
79
  this.setResponse(resBody)
@@ -0,0 +1,58 @@
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 placement = options?.placement || 'right-top',
13
+ offset = 10,
14
+ nid = options?.id || getUuid()
15
+ const onClose = nid => {
16
+ const inss = instances.filter(n => n.placement.startsWith(placement)),
17
+ idx = inss.findIndex(n => n.nid === nid),
18
+ ins = inss[idx],
19
+ ykey = placement.split('-')[1]
20
+ if (idx > -1 && ins) {
21
+ for (let i = idx + 1; i < inss.length; i++) {
22
+ const cmpcss = getComputedStyle(inss[i].$el)
23
+ const y = parseInt(cmpcss[ykey]) || 0
24
+ inss[i].show(y - ins.$el.offsetHeight - offset + 'px')
25
+ }
26
+ instances = instances.filter(n => n.nid !== nid)
27
+ }
28
+ }
29
+ const option = Object.assign({ title: '提示', nid, type, placement }, options, { onClose }),
30
+ notification = createApp(Notification, option),
31
+ dom = document.createElement('div'),
32
+ ins = notification.mount(dom),
33
+ inss = instances.filter(n => n.placement.startsWith(option.placement))
34
+ document.body.appendChild(ins.$el)
35
+ let y = offset
36
+ inss.forEach(n => (y += n.$el.offsetHeight + offset))
37
+ ins.show(y + 'px')
38
+ instances.push(ins)
39
+ return { option, ins }
40
+ }
41
+
42
+ export default {
43
+ open(options) {
44
+ return notice('', options)
45
+ },
46
+ info(options) {
47
+ return notice('info', options)
48
+ },
49
+ success(options) {
50
+ return notice('success', options)
51
+ },
52
+ warning(options) {
53
+ return notice('warning', options)
54
+ },
55
+ error(options) {
56
+ return notice('error', options)
57
+ }
58
+ }
@@ -0,0 +1,212 @@
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>
package/packages/index.js CHANGED
@@ -2,4 +2,6 @@ import http from './api/index'
2
2
 
3
3
  import utils from './utils/index'
4
4
 
5
- export { http, utils }
5
+ import notice from './components/sh-notification'
6
+
7
+ export { http, utils, notice }
@@ -6,14 +6,14 @@ const colorKeywords = new Map([
6
6
  ['white', '#FFFFFF'],
7
7
  ['maroon', '#800000'],
8
8
  ['red', '#FF0000'],
9
- ['purple', '#800080'],
9
+ ['purple', '#722ed1'],
10
10
  ['fuchsia', '#FF00FF'],
11
- ['green', '#008000'],
12
- ['lime', '#00FF00'],
11
+ ['green', '#52c41a'],
12
+ ['lime', '#a0d911'],
13
13
  ['olive', '#808000'],
14
- ['yellow', '#FFFF00'],
14
+ ['yellow', '#fadb14'],
15
15
  ['navy', '#000080'],
16
- ['blue', '#0000FF'],
16
+ ['blue', '#1890ff'],
17
17
  ['teal', '#008080'],
18
18
  ['aqua', '#00FFFF'],
19
19
  ['aliceblue', '#f0f8ff'],
@@ -33,7 +33,7 @@ const colorKeywords = new Map([
33
33
  ['cornflowerblue', '#6495ed'],
34
34
  ['cornsilk', '#fff8dc'],
35
35
  ['crimson', '#dc143c'],
36
- ['cyan', '#00ffff'],
36
+ ['cyan', '#13c2c2'],
37
37
  ['darkblue', '#00008b'],
38
38
  ['darkcyan', '#008b8b'],
39
39
  ['darkgoldenrod', '#b8860b'],
@@ -62,8 +62,9 @@ const colorKeywords = new Map([
62
62
  ['floralwhite', '#fffaf0'],
63
63
  ['forestgreen', '#228b22'],
64
64
  ['gainsboro', '#dcdcdc'],
65
+ ['geekblue', '#2f54eb'],
65
66
  ['ghostwhite', '#f8f8ff'],
66
- ['gold', '#ffd700'],
67
+ ['gold', '#faad14'],
67
68
  ['goldenrod', '#daa520'],
68
69
  ['greenyellow', '#adff2f'],
69
70
  ['grey', '#808080'],
@@ -94,7 +95,7 @@ const colorKeywords = new Map([
94
95
  ['lightyellow', '#ffffe0'],
95
96
  ['limegreen', '#32cd32'],
96
97
  ['linen', '#faf0e6'],
97
- ['magenta', '#ff00ff'],
98
+ ['magenta', '#eb2f96'],
98
99
  ['mediumaquamarine', '#66cdaa'],
99
100
  ['mediumblue', '#0000cd'],
100
101
  ['mediumorchid', '#ba55d3'],
@@ -111,7 +112,7 @@ const colorKeywords = new Map([
111
112
  ['navajowhite', '#ffdead'],
112
113
  ['oldlace', '#fdf5e6'],
113
114
  ['olivedrab', '#6b8e23'],
114
- ['orange', '#ffa500'],
115
+ ['orange', '#fa8c16'],
115
116
  ['orangered', '#ff4500'],
116
117
  ['orchid', '#da70d6'],
117
118
  ['palegoldenrod', '#eee8aa'],
@@ -144,6 +145,7 @@ const colorKeywords = new Map([
144
145
  ['tomato', '#ff6347'],
145
146
  ['turquoise', '#40e0d0'],
146
147
  ['violet', '#ee82ee'],
148
+ ['volcano', '#fa541c'],
147
149
  ['wheat', '#f5deb3'],
148
150
  ['whitesmoke', '#f5f5f5'],
149
151
  ['yellowgreen', '#9acd32']