@jx3box/jx3box-editor 1.5.5 → 1.5.7

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-editor",
3
- "version": "1.5.5",
3
+ "version": "1.5.7",
4
4
  "description": "JX3BOX Article & Editor",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -13,8 +13,8 @@ const $ = axios.create({
13
13
  baseURL: 'http://localhost:7002/',
14
14
  }) */
15
15
 
16
- function getResource(id, client = 'std') {
17
- return $.get(`/resource/${client}/${id}`);
16
+ function getResource(type, ids, client = "std") {
17
+ return $.post(`/resource/${client}/${type}/`, { ids });
18
18
  }
19
19
 
20
20
  export { getResource };
package/src/GameText.vue CHANGED
@@ -15,7 +15,7 @@ import {
15
15
  getLink,
16
16
  iconLink,
17
17
  } from "@jx3box/jx3box-common/js/utils";
18
- import { getResource } from "../service/resource";
18
+ import { getResource as getResourceFromNode } from "../service/resource";
19
19
  import { escape } from "lodash";
20
20
 
21
21
  export default {
@@ -117,101 +117,133 @@ export default {
117
117
  /**
118
118
  * 获取形如<BUFF 110 1 desc>, <ENCHANT 100>的资源字段并转换
119
119
  */
120
- renderBuffResource: function () {
121
- const matches = this.html.match(/<BUFF (\d+) (\d+) (.*?)>/gim);
120
+ renderBuffResource: async function () {
121
+ const matches = this.html?.match(/<BUFF (\d+) (\d+) (.*?)>/gim);
122
122
  if (!matches) return;
123
- let need_replaces = {};
123
+ let resourceKeys = [];
124
+ let replaceMap = {};
124
125
  //先统计需要的资源,减少请求数量
125
126
  for (let match of matches) {
126
127
  let [token, id, level, type] = match.match(
127
128
  /<BUFF (\d+) (\d+) (.*?)>/i
128
129
  );
129
- let buff_token = `${id}_${level}`;
130
- if (!need_replaces[buff_token]) {
131
- need_replaces[buff_token] = [];
132
- }
133
- need_replaces[buff_token].push({
134
- token,
135
- type,
136
- });
130
+ resourceKeys.push(`${id}_${level}`);
131
+ if (level != 0) resourceKeys.push(`${id}_0`);
132
+ replaceMap[token] = [id, level, type];
137
133
  }
138
- //对每一个需要的资源发起请求
139
- for (let buff_token in need_replaces) {
140
- let token_item = need_replaces[buff_token];
141
- getResource(`buff.${buff_token}`, this.client)
142
- .then(res => {
143
- let data = res.data;
144
- for (let item of token_item) {
145
- item.type = item.type.toLowerCase();
146
- let type_map = {
147
- desc: "Desc",
148
- time: "Interval",
149
- };
150
- let attr = type_map[item.type] || item.type;
151
- let value = data[attr];
152
- if (
153
- typeof value == "number" &&
154
- item.type == "time"
155
- ) {
156
- let time = value / 16;
157
- if (time > 60) {
158
- time = `${Math.floor(time / 60)}分钟`;
159
- } else {
160
- time = `${time}秒`;
161
- }
162
- this.html = this.html.replace(item.token, time);
163
- return;
164
- }
165
- if (!value) return;
166
- let _matches = value.match(
167
- /<BUFF ([0-9a-zA-Z]+)>/gi
168
- );
169
- if (!_matches)
170
- this.html = this.html.replace(match, value);
171
- for (let _match of _matches) {
172
- let [, _attr] = _match.match(
173
- /<BUFF ([0-9a-zA-Z]+)>/i
174
- );
175
- for (let i = 1; i < 15; i++) {
176
- if (data[`BeginAttrib${i}`] == _attr) {
177
- value = value.replace(
178
- _match,
179
- data[`BeginValue${i}A`]
180
- );
181
- }
134
+ await this.getAllResources("buff", resourceKeys, this.client);
135
+ for (let replace in replaceMap) {
136
+ let [id, level, type] = replaceMap[replace];
137
+ // 持续时间
138
+ if (type === "time") {
139
+ let interval;
140
+ let buff = this.getResource("buff", id, level);
141
+ if (buff["Interval"]) interval = buff["Interval"];
142
+ else interval = this.getResource("buff", id, 0)["Interval"];
143
+ if (!interval) {
144
+ console.log(replace, escape(replace));
145
+ this.html = this.html.replace(replace, escape(replace));
146
+ continue;
147
+ }
148
+ let time = interval / 16;
149
+ if (time > 60) {
150
+ time = Math.floor(time / 60) + "分钟";
151
+ } else {
152
+ time = time + "秒";
153
+ }
154
+ this.html = this.html.replace(replace, escape(time));
155
+ continue;
156
+ }
157
+ // buff描述
158
+ if (type === "desc") {
159
+ let buff = this.getResource("buff", id, level);
160
+ let desc = buff["Desc"];
161
+ if (!desc) desc = this.getResource("buff", id, 0)["Desc"];
162
+ if (!desc) {
163
+ this.html = this.html.replace(replace, escape(replace));
164
+ continue;
165
+ }
166
+ // buff的描述里面可能会混着一些buff的属性啥的
167
+ let _matches = desc.match(/<BUFF ([0-9a-zA-Z]+)>/gi);
168
+ if (_matches) {
169
+ for (let _m of _matches) {
170
+ let [_, _attr] = _m.match(/<BUFF ([0-9a-zA-Z]+)>/i);
171
+ for (let i = 1; i < 15; i++) {
172
+ if (buff[`BeginAttrib${i}`] == _attr) {
173
+ desc = desc.replace(
174
+ _m,
175
+ buff[`BeginValue${i}A`]
176
+ );
182
177
  }
183
178
  }
184
- this.html = this.html.replace(item.token, value);
185
179
  }
186
- })
187
- .catch(err => {
188
- console.log(err);
189
- });
180
+ }
181
+ this.html = this.html.replace(replace, desc);
182
+ }
190
183
  }
191
184
  },
192
- renderEnchantResource: function () {
185
+ renderEnchantResource: async function () {
193
186
  const matches = this.html.match(/<ENCHANT (\d+)>/gim);
194
187
  if (!matches) return;
188
+ let resourceKeys = [];
189
+ let replaceMap = {};
195
190
  for (let match of matches) {
196
191
  let enchant_id = match.match(/<ENCHANT (\d+)>/i)[1];
197
- getResource(`enchant.${enchant_id}`, this.client)
198
- .then(res => {
199
- let data = res.data;
200
- let time = data.Time;
201
- if (time) time = `,持续${parseInt(time) / 60}分钟。`;
202
- let result = `${data.AttriName}${time ? time : ""}`;
203
- this.html = this.html.replace(match, result);
204
- })
205
- .catch(err => {
206
- this.html = this.html.replace(match, escape(match));
207
- console.log(err);
208
- });
192
+ resourceKeys.push(enchant_id);
193
+ replaceMap[match] = enchant_id;
194
+ }
195
+ await this.getAllResources("enchant", resourceKeys, this.client);
196
+ for (let replace in replaceMap) {
197
+ try {
198
+ let enchant_id = replaceMap[replace];
199
+ let enchant = this.getResource("enchant", enchant_id);
200
+ let time = enchant.Time;
201
+ if (time) time = `,持续${parseInt(time) / 60}分钟。`;
202
+ let result = `${enchant.AttriName}${time ? time : ""}`;
203
+ this.html = this.html.replace(replace, result);
204
+ } catch (e) {
205
+ console.log(e);
206
+ this.html = this.html.replace(replace, escape(replace));
207
+ }
209
208
  }
210
209
  },
211
210
  renderResource: function () {
212
211
  this.renderBuffResource();
213
212
  this.renderEnchantResource();
214
213
  },
214
+ getAllResources: async function (type, ids) {
215
+ let resources = await getResourceFromNode(type, ids, this.client);
216
+ let data = resources.data;
217
+ if (data.length === undefined) data = [data];
218
+ if (type == "buff") {
219
+ for (let item of data) {
220
+ let buff_token = `${item.BuffID}_${item.Level}`;
221
+ sessionStorage.setItem(
222
+ `buff-${this.client}-${buff_token}`,
223
+ JSON.stringify(item)
224
+ );
225
+ }
226
+ } else if (type == "enchant") {
227
+ for (let item of data) {
228
+ let enchant_token = `${item.ID}`;
229
+ sessionStorage.setItem(
230
+ `enchant-${this.client}-${enchant_token}`,
231
+ JSON.stringify(item)
232
+ );
233
+ }
234
+ }
235
+ },
236
+ getResource: function (type, id, level) {
237
+ let token = `${id}`;
238
+ if (type == "buff") {
239
+ token = `${id}_${level}`;
240
+ }
241
+ let resource = sessionStorage.getItem(
242
+ `${type}-${this.client}-${token}`
243
+ );
244
+ if (resource) return JSON.parse(resource);
245
+ return null;
246
+ },
215
247
  },
216
248
  watch: {
217
249
  text: {
package/src/Upload.vue CHANGED
@@ -59,7 +59,7 @@ const API_Root = process.env.NODE_ENV === "production" ? __cms : "/";
59
59
  const API = API_Root + "api/cms/upload";
60
60
 
61
61
  import allow_types from "@jx3box/jx3box-common/data/conf";
62
- const imgtypes = ["jpg", "png", "gif", "bmp", "webp", "jpeg"];
62
+ const imgtypes = ["jpg", "png", "gif", "bmp", "webp", "jpeg", "JPG", "PNG", "GIF", "BMP", "WEBP", "JPEG"];
63
63
 
64
64
  export default {
65
65
  name: "Upload",