@jx3box/jx3box-common-ui 7.0.1 → 7.0.2

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": "@jx3box/jx3box-common-ui",
3
- "version": "7.0.1",
3
+ "version": "7.0.2",
4
4
  "description": "JX3BOX UI",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/service/cms.js CHANGED
@@ -18,6 +18,10 @@ function getDecorationJson() {
18
18
  let url = __imgPath + "decoration/index.json";
19
19
  return axios.get(url);
20
20
  }
21
+ function getHonorJson() {
22
+ let url = __imgPath + "decoration/honor.json";
23
+ return axios.get(url);
24
+ }
21
25
  // 通用上传
22
26
  function upload(formData) {
23
27
  return $cms().post(`/api/cms/upload`, formData);
@@ -28,4 +32,4 @@ function checkTeamMember() {
28
32
  return $cms().get(`/api/cms/config/teammates/check`);
29
33
  }
30
34
 
31
- export { getPostAuthors, uploadImage, upload, getDecoration, getDecorationJson, checkTeamMember };
35
+ export { getPostAuthors, uploadImage, upload, getDecoration, getDecorationJson, checkTeamMember, getHonorJson };
@@ -0,0 +1,116 @@
1
+ <template>
2
+ <div class="c-honor" :style="{ backgroundImage: `url(${imgUrl()})` }" v-if="honor">
3
+ <span :style="{ color: honor.color }">{{ honor.honor }}</span>
4
+ </div>
5
+ </template>
6
+ <script>
7
+ import { __imgPath } from "@jx3box/jx3box-common/data/jx3box.json";
8
+ import { getDecoration, getHonorJson } from "../../service/cms";
9
+ import { inRange } from "lodash";
10
+ const HONOR_IMG_KEY = "honor_img";
11
+ export default {
12
+ props: ["uid"],
13
+ data: function () {
14
+ return {
15
+ honor: "",
16
+ };
17
+ },
18
+ watch: {
19
+ uid: {
20
+ immediate: true,
21
+ handler: function (val) {
22
+ val && this.getHonor();
23
+ },
24
+ },
25
+ },
26
+ methods: {
27
+ imgUrl: function () {
28
+ let item = this.honor;
29
+ if (!item) return;
30
+ if (item.isImgIndex) {
31
+ return __imgPath + `decoration/honor/${item.val}/${item.val}_${item.imgIndex}.${item.ext}`;
32
+ }
33
+ return __imgPath + `decoration/honor/${item.val}/${item.val}.${item.ext}`;
34
+ },
35
+ getHonor() {
36
+ let user_id = this.uid;
37
+ if (!user_id) return;
38
+ let honor_local = sessionStorage.getItem(HONOR_IMG_KEY + user_id);
39
+ if (honor_local) {
40
+ //解析本地缓存
41
+ let honor_parse = JSON.parse(honor_local);
42
+ if (!honor_parse == "no") return;
43
+ this.honor = honor_parse;
44
+ return;
45
+ }
46
+ getDecoration({ using: 1, user_id: user_id, type: "honor" }).then((data) => {
47
+ let res = data.data.data;
48
+ if (res.length == 0) {
49
+ //空 则为无主题,不再加载接口,界面设No
50
+ sessionStorage.setItem(HONOR_IMG_KEY + user_id, "no");
51
+ return;
52
+ }
53
+ let honor = res[0];
54
+ this.getHonorStyle(honor);
55
+ });
56
+ },
57
+ //有称号后,获取样式配置
58
+ getHonorStyle(data) {
59
+ getHonorJson().then((res) => {
60
+ let honorList = res.data;
61
+ //过滤称号信息
62
+ let honorConfig = honorList[data.val];
63
+ //正则取出前缀
64
+ let prefix = honorConfig.prefix;
65
+ let regPrefix = honorConfig.prefix.match(/(?<=\{)(.+?)(?=\})/g);
66
+ let ranking = honorConfig.ranking;
67
+ let honorStr = honorConfig.year || "";
68
+ if (regPrefix) {
69
+ honorStr = honorStr + (data[regPrefix[0]] || "");
70
+ } else {
71
+ honorStr = honorStr + prefix;
72
+ }
73
+ //排名处理
74
+ if (ranking.length > 0) {
75
+ data.imgIndex = 0;
76
+ for (let i = 0; i < ranking.length; i++) {
77
+ //处在范围内取数组第三个值进行称号拼接
78
+ if (data.ranking != undefined && inRange(Number(data.ranking), ranking[i][0], ranking[i][1])) {
79
+ data.imgIndex = i;
80
+ let str = ranking[i][2];
81
+ //正则取出需替换值,如果没有则直接拼接
82
+ let regStr = str.match(/(?<=\{)(.+?)(?=\})/g);
83
+ if (regStr) {
84
+ //包含花括号替换
85
+ honorStr = honorStr + str.replace(/\{(.+?)\}/g, data[regStr[0]]);
86
+ } else {
87
+ honorStr = honorStr + str;
88
+ }
89
+ break;
90
+ }
91
+ }
92
+ }
93
+ data.honor = honorStr + honorConfig.suffix;
94
+ data.color = honorConfig.color;
95
+ data.ext = honorConfig.ext;
96
+ data.isHave = true;
97
+ data.isImgIndex = honorConfig.ranking.length > 0 ? true : false;
98
+ sessionStorage.setItem(HONOR_IMG_KEY + this.uid, JSON.stringify(data));
99
+ this.honor = data;
100
+ });
101
+ },
102
+ },
103
+ };
104
+ </script>
105
+ <style lang="less">
106
+ .c-honor {
107
+ .dbi;
108
+ text-align: center;
109
+ .mb(10px);
110
+ .size(220px,45px);
111
+ // background-color: #494038;
112
+ color: #ffffff;
113
+ .fz(10px,45px);
114
+ .r(2px);
115
+ }
116
+ </style>
@@ -35,7 +35,7 @@
35
35
  </div>
36
36
  </div>
37
37
  </div>
38
- <div class="u-honor" :style="honorStyle" v-if="honor">{{ honor }}</div>
38
+ <Honor :uid="uid"></Honor>
39
39
  <div class="u-bio">{{ data.user_bio }}</div>
40
40
  </div>
41
41
  </template>
@@ -45,25 +45,23 @@ import { __server, __imgPath, __userLevel, __userLevelColor } from "@jx3box/jx3b
45
45
  import { authorLink } from "@jx3box/jx3box-common/js/utils";
46
46
  import User from "@jx3box/jx3box-common/js/user";
47
47
  import { getUserInfo } from "../../service/author";
48
- import { getDecoration, getDecorationJson } from "../../service/cms";
48
+ import { getDecoration, getHonorJson } from "../../service/cms";
49
49
  import Avatar from "./Avatar.vue";
50
- const DECORATION_JSON = "decoration_json";
51
- const DECORATION_KEY = "decoration_me";
52
- const HONOR_KEY = "honor_me";
50
+ import Honor from "./AuthorHonor.vue";
51
+ import { cloneDeep, inRange } from "lodash";
52
+ const HONOR_IMG_KEY = "honor_img";
53
53
  export default {
54
54
  name: "AuthorInfo",
55
55
  props: ["uid"],
56
56
  components: {
57
57
  Avatar,
58
+ Honor,
58
59
  },
59
60
  data: function () {
60
61
  return {
61
62
  data: {},
62
-
63
63
  isVIP: false,
64
64
  super_author_icon: __imgPath + "image/user/" + "superauthor.svg",
65
- honor: "",
66
- honorStyle: {},
67
65
  };
68
66
  },
69
67
  computed: {
@@ -92,7 +90,7 @@ export default {
92
90
  uid: {
93
91
  immediate: true,
94
92
  handler: function (val) {
95
- val && this.loadData() && this.getHonor();
93
+ val && this.loadData();
96
94
  },
97
95
  },
98
96
  },
@@ -111,80 +109,6 @@ export default {
111
109
  showLevelColor: function (level) {
112
110
  return __userLevelColor[level];
113
111
  },
114
- getHonor() {
115
- let user_id = this.uid;
116
- if (!user_id) {
117
- return;
118
- }
119
- let honor_local = sessionStorage.getItem(HONOR_KEY + user_id);
120
- if (honor_local == "no") return;
121
- //已有缓存,读取解析
122
- if (honor_local) {
123
- this.honor = honor_local;
124
- this.getHonorStyle();
125
- return;
126
- }
127
- getDecoration({ using: 1, user_id: user_id, type: "honor" }).then((data) => {
128
- let res = data.data.data;
129
- if (res.length == 0) {
130
- //空 则为无主题,不再加载接口,界面设No
131
- sessionStorage.setItem(HONOR_KEY + user_id, "no");
132
- return;
133
- }
134
- let honor = res[0];
135
- sessionStorage.setItem(HONOR_KEY + user_id, honor.val);
136
- this.honor = honor.val;
137
- this.getHonorStyle();
138
- });
139
- },
140
- //有称号后,获取样式配置
141
- getHonorStyle() {
142
- let user_id = this.uid;
143
- let decoration_local = sessionStorage.getItem(DECORATION_KEY + user_id);
144
- if (decoration_local) {
145
- //解析本地缓存
146
- let decoration_parse = JSON.parse(decoration_local);
147
- if (!decoration_parse.status) return;
148
-
149
- if (decoration_parse) {
150
- this.setHonorStyle(decoration_parse);
151
- return;
152
- }
153
- }
154
- getDecoration({ using: 1, user_id: user_id, type: "homebg" }).then((data) => {
155
- let res = data.data.data;
156
- if (res.length == 0) {
157
- //空 则为无主题,不再加载接口,界面设No
158
- sessionStorage.setItem(DECORATION_KEY + user_id, JSON.stringify({ status: false }));
159
- return;
160
- }
161
- let decoration = res[0];
162
- let decorationJson = sessionStorage.getItem(DECORATION_JSON);
163
- if (!decorationJson) {
164
- //加载远程json,用于Honor颜色配置
165
- getDecorationJson().then((json) => {
166
- let decoration_json = json.data;
167
- let theme = JSON.parse(JSON.stringify(decoration_json[decoration.val]));
168
- theme.status = true;
169
- sessionStorage.setItem(DECORATION_KEY + this.uid, JSON.stringify(theme));
170
- //缓存远程JSON文件
171
- sessionStorage.setItem(DECORATION_JSON, JSON.stringify(decoration_json));
172
- this.setHonorStyle(theme);
173
- });
174
- } else {
175
- let theme = JSON.parse(decorationJson)[decoration.val];
176
- theme.status = true;
177
- sessionStorage.setItem(DECORATION_KEY + this.uid, JSON.stringify(theme));
178
- this.setHonorStyle(theme);
179
- }
180
- });
181
- },
182
- setHonorStyle(style) {
183
- this.honorStyle = {
184
- "background-color": style.buttoncolor,
185
- color: style.buttontextcolor,
186
- };
187
- },
188
112
  },
189
113
  created: function () {},
190
114
  mounted: function () {},
@@ -295,12 +219,12 @@ export default {
295
219
  }
296
220
  .u-honor {
297
221
  .dbi;
298
- .mt(10px);
299
- background-color: #494038;
222
+ text-align: center;
223
+ .mb(10px);
224
+ .size(220px,45px);
225
+ // background-color: #494038;
300
226
  color: #ffffff;
301
- padding: 2px 50px 2px 10px;
302
- .fz(12px,14px);
303
- .mb(6px);
227
+ .fz(10px,45px);
304
228
  .r(2px);
305
229
  }
306
230
  }