web-component-gallery 2.1.3 → 2.1.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.
@@ -63,7 +63,7 @@ function renderContent(h, {url, name}, images) {
63
63
  IMAGE: 'img'
64
64
  }
65
65
 
66
- const ICON_TYPE = "icon-file_thumb"
66
+ const ICON_TYPE = "file_thumb"
67
67
 
68
68
  const CustomTag = getCustomTag(url)
69
69
 
@@ -1,33 +1,58 @@
1
1
  import { Icon } from 'ant-design-vue/es'
2
+ import { handleEnvURL } from '../../utils/Utils'
2
3
 
3
4
  const IconFont = {
4
- name: 'IconFont',
5
- props: {
6
- scriptUrl: {
7
- type: String,
8
- default: '//at.alicdn.com/t/c/font_4641025_nxf7ygyw03.js'
9
- },
10
- type: {
11
- type: String,
12
- required: true
13
- }
5
+ name: 'IconFont',
6
+ props: {
7
+ scriptUrl: {
8
+ type: String,
9
+ default: 'webCompGallery'
14
10
  },
15
- computed: {
16
- iconType() {
17
- return Icon.createFromIconfontCN({
18
- scriptUrl: this.scriptUrl
11
+ type: {
12
+ type: String,
13
+ required: true
14
+ }
15
+ },
16
+ data() {
17
+ return {
18
+ _iconTypeCache: null
19
+ }
20
+ },
21
+ computed: {
22
+ iconType() {
23
+ if (this._iconTypeCache?.scriptUrl === this.scriptUrl) {
24
+ return this._iconTypeCache
25
+ }
26
+
27
+ try {
28
+ const iconType = Icon.createFromIconfontCN({
29
+ scriptUrl: handleEnvURL(`/iconfont/${this.scriptUrl}.js`, 'file')
19
30
  })
20
- }
21
- },
22
- render() {
23
- const {$props: props = {}, $attrs: attrs = {} } = this
24
- const IconComponent = this.iconType
25
- return <IconComponent {...{ props, attrs }} on={{ ...this.$listeners }} />
31
+ this._iconTypeCache = iconType
32
+ return iconType
33
+ } catch (error) {
34
+ console.error('icon文件不存在', error)
35
+ return null
36
+ }
26
37
  }
38
+ },
39
+ render() {
40
+ const { $props, $attrs = {}, type } = this
41
+ const IconComponent = this.iconType
42
+ return (
43
+ <IconComponent
44
+ {...{
45
+ props: { ...$props, type: `icon-${type}` },
46
+ attrs: $attrs,
47
+ on: { ...this.$listeners }
48
+ }}
49
+ />
50
+ )
51
+ }
27
52
  }
28
53
 
29
54
  IconFont.install = function (Vue) {
30
- Vue.component('IconFont', IconFont)
55
+ Vue.component('IconFont', IconFont)
31
56
  }
32
57
 
33
58
  export default IconFont
@@ -58,13 +58,13 @@ const ModalComp = {
58
58
  <span>{this.title}</span>
59
59
  <div class="AntModal__Title__Blank">
60
60
  <IconFont
61
- type="icon-modal_convert"
61
+ type="modal_convert"
62
62
  on={{ click: this.handleConvert }}
63
63
  />
64
64
  {
65
65
  $attrs.blankUrl &&
66
66
  <IconFont
67
- type="icon-modal_blank"
67
+ type="modal_blank"
68
68
  on={{ click: this.handleBlank }}
69
69
  />
70
70
  }
@@ -4,7 +4,7 @@
4
4
  class="no-data-container"
5
5
  >
6
6
  <div slot="image">
7
- <IconFont :type="`icon-noData_${type}`" />
7
+ <IconFont :type="`noData_${type}`" />
8
8
  </div>
9
9
  <slot></slot>
10
10
  </Empty>
@@ -124,7 +124,7 @@ export default {
124
124
  rowSelection: { selectedRowKeys: this.selectedRowKeys, onChange: this.onSelectChange },
125
125
  locale: {
126
126
  emptyText: <div class="WebComponentTable__List__Empty">
127
- <IconFont type="icon-noData_data" />
127
+ <IconFont type="noData_data" />
128
128
  <span>暂无数据</span>
129
129
  </div>
130
130
  },
@@ -1,49 +1,98 @@
1
- <template>
2
- <div class="weather">
3
- <slot name="weatherIcon" :weatherInfo="weatherInfo" />
4
- <span class="weather__Info">{{ weatherInfo.weather }}</span>
5
- <span class="weather__Temp">温度{{ weatherInfo.temperature }}°</span>
6
- </div>
1
+ <template>
2
+ <div class="weather">
3
+ <slot name="weatherIcon" :weatherInfo="weatherInfo">
4
+ <IconFont scriptUrl="weatherGallery" :type="weatherType" />
5
+ </slot>
6
+ <span class="weather__Info">{{ weatherInfo.weather || '--' }}</span>
7
+ <span class="weather__Temp">温度{{ weatherInfo.temperature || '--' }}°</span>
8
+ </div>
7
9
  </template>
8
10
 
9
11
  <script>
12
+ const WEATHER_TYPES = {
13
+ '小雨,毛毛雨/细雨,雨,小雨-中雨': 'lightRain',
14
+ '中雨,大雨,中雨-大雨,大雨-暴雨,暴雨,大暴雨,特大暴雨,极端降雨,暴雨-大暴雨,大暴雨-特大暴雨': 'heavyRain',
15
+ '阵雨,强阵雨': 'rainShower',
16
+ '冻雨': 'iceRain',
17
+ '雷阵雨,强雷阵雨': 'thunderShower',
18
+ '少云,多云,阴,冷': 'overcast',
19
+ '雪,小雪,中雪,大雪,小雪-大雪,中雪-大雪,暴雪,大雪-暴雪': 'lightSnow',
20
+ '阵雪': 'showerySnow',
21
+ '晴,热': 'clear',
22
+ '雨雪天气,雨夹雪,阵雨夹雪,雷阵雨并伴有冰雹': 'sleet',
23
+ '霾,中度霾,雾,轻雾': 'lightFog',
24
+ '重度霾,严重霾,浓雾,强浓雾,大雾,特强浓雾,未知': 'heavyFog',
25
+ '晴间多云': 'cloudyToSunny',
26
+ '有风,平静,微风,和风,清风,强风/劲风,疾风,大风,烈风,风暴,狂爆风,飓风,热带风暴,龙卷风,浮尘,扬沙,沙尘暴,强沙尘暴': 'gale'
27
+ }
28
+
29
+ import { IconFont } from '../index'
10
30
 
11
31
  export default {
12
32
  name: 'Weather',
13
33
  props: {
14
34
  /** 当前城市高德code编码 */
15
- adCode: String,
35
+ adCode: {
36
+ type: String,
37
+ default: '330802'
38
+ },
16
39
  AMapServiceKey: {
17
40
  type: String,
18
41
  default: '76aa516e74e87a1b9d169e796f2bbdc3'
19
42
  }
20
43
  },
21
- data() {
44
+ components: {
45
+ IconFont
46
+ },
47
+ data() {
22
48
  return {
23
- weatherInfo: {}
49
+ weatherInfo: {}
50
+ }
51
+ },
52
+ computed: {
53
+ weatherType() {
54
+ if (!this.weatherInfo.weather) return 'clear'
55
+
56
+ const matchedKey = Object.keys(WEATHER_TYPES).find(key =>
57
+ key.includes(this.weatherInfo.weather)
58
+ )
59
+ return WEATHER_TYPES[matchedKey] || 'clear'
24
60
  }
25
61
  },
26
62
  mounted() {
27
- this.getWeatherInfo()
63
+ this.fetchWeatherData()
64
+ },
65
+ watch: {
66
+ adCode() {
67
+ this.fetchWeatherData()
68
+ }
28
69
  },
29
70
  methods: {
30
- async getWeatherInfo() {
31
- await fetch(
32
- `https://restapi.amap.com/v3/weather/weatherInfo?key=${this.AMapServiceKey}&city=${this.adCode}`,
33
- {
71
+ async fetchWeatherData() {
72
+ if (!this.adCode || !this.AMapServiceKey) return
73
+
74
+ try {
75
+ const response = await fetch(
76
+ `https://restapi.amap.com/v3/weather/weatherInfo?key=${this.AMapServiceKey}&city=${this.adCode}`,
77
+ {
34
78
  method: 'GET',
35
79
  headers: {
36
- 'Content-Type': 'application/json'
80
+ 'Content-Type': 'application/json'
37
81
  }
38
- })
39
- .then(response => response.json())
40
- .then(({infocode, lives}) => {
41
- infocode == '10000' && (this.weatherInfo = { ...lives[0] })
42
- })
43
- .catch(error => {
44
- console.error('Error:', error)
45
- })
82
+ }
83
+ )
84
+
85
+ const { infocode, lives } = await response.json()
86
+
87
+ if (infocode === '10000') {
88
+ this.weatherInfo = { ...lives[0] }
89
+ return
90
+ }
91
+ console.error('天气数据解析失败:', err)
92
+ } catch (err) {
93
+ console.error('获取天气数据失败:', err)
94
+ }
46
95
  }
47
96
  }
48
97
  }
49
- </script>
98
+ </script>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "web-component-gallery",
3
- "version": "2.1.3",
3
+ "version": "2.1.4",
4
4
  "description": "基础vue、antdvue、less实现的私有组件库",
5
5
  "main": "dist/index.umd.js",
6
6
  "files": [
package/utils/Utils.js CHANGED
@@ -1,4 +1,6 @@
1
1
  import message from 'ant-design-vue/es/message'
2
+ import { verifyIPStr } from './Validate'
3
+ import { findNthOccurrence } from './Filter'
2
4
 
3
5
  /**
4
6
  * 下载文件
@@ -58,4 +60,60 @@ export function getPictureAttrs(url, astrictH) {
58
60
  // 错误处理
59
61
  image.onerror = () => resolve({ width: 0, height: 0 })
60
62
  })
63
+ }
64
+
65
+
66
+ /**
67
+ * 根据环境配置处理URL
68
+ * @param {string} url - 原始URL
69
+ * @param {string} [processType='url'] - 处理类型('url'|'image'|'file')
70
+ * @returns {string} 处理后的URL
71
+ * @throws {Error} 当processType不支持时抛出错误
72
+ */
73
+ export function handleEnvURL(url, processType = 'url') {
74
+ // 图片格式正则(预编译提升性能)
75
+ const imagePattern = /\.(jpg|jpeg|png|gif|bmp|webp|svg|tiff?)$/i
76
+ // 判断当前是否为开发环境
77
+ const isDev = process.env.NODE_ENV === 'development'
78
+
79
+ // 基础校验
80
+ if (verifyIPStr(url) || !url) return url
81
+
82
+ // 环境变量解构
83
+ const { origin } = window.location
84
+ const { VUE_APP_ROUTE_PORT, VUE_APP_API_BASE_URL } = process.env
85
+
86
+ // URL处理策略
87
+ const urlStrategies = {
88
+ url: {
89
+ dev: () => constructUrl(
90
+ `${origin.slice(0, -4)}${VUE_APP_ROUTE_PORT}`,
91
+ url.slice(findNthOccurrence(url, '/', 1))
92
+ ),
93
+ prod: () => constructUrl(origin, url)
94
+ },
95
+ image: {
96
+ dev: () =>
97
+ imagePattern.test(url)
98
+ ? constructUrl(VUE_APP_API_BASE_URL, url)
99
+ : url,
100
+ prod: () =>
101
+ imagePattern.test(url)
102
+ ? constructUrl(origin, url)
103
+ : url
104
+ },
105
+ file: {
106
+ dev: () => constructUrl(VUE_APP_API_BASE_URL, url),
107
+ prod: () => constructUrl(origin, url)
108
+ }
109
+ }
110
+
111
+ // 构造URL辅助函数
112
+ const constructUrl = (base, path) =>
113
+ `${base}${path}`
114
+
115
+ // 获取处理策略
116
+ const strategy = urlStrategies[processType]
117
+
118
+ return isDev ? strategy.dev() : strategy.prod()
61
119
  }