q-koa 13.1.0 → 13.1.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.
@@ -186,6 +186,16 @@ exports.showTables = async (ctx) => {
186
186
 
187
187
  if (!target) throw new Error(`检查是否有${_model}/config.js`)
188
188
  const model = target.model ? target.model : _model
189
+
190
+ function getValueByModelName(target, key, defaultValue, model, _model) {
191
+ return lodash.get(
192
+ target,
193
+ key,
194
+ model !== _model
195
+ ? lodash.get(app.config[model], key, defaultValue)
196
+ : defaultValue
197
+ )
198
+ }
189
199
  return {
190
200
  modelName: _model,
191
201
  model,
@@ -200,7 +210,7 @@ exports.showTables = async (ctx) => {
200
210
  // 默认排序
201
211
  defaultOrder: lodash.get(target, 'defaultOrder', []),
202
212
  // 下拉筛选
203
- select: lodash.get(target, 'select', []),
213
+ select: getValueByModelName(target, 'select', [], model, _model),
204
214
  // 是否可以选择批量删除
205
215
  multiple: lodash.get(target, 'multiple', true),
206
216
  // 是否后台拆分sql
@@ -221,17 +231,9 @@ exports.showTables = async (ctx) => {
221
231
  lodash.get(target, 'order', [])
222
232
  ),
223
233
  // reference admin components
224
- reference: lodash.get(
225
- target,
226
- 'reference',
227
- model !== _model ? lodash.get(app.config[model], 'reference', []) : []
228
- ),
234
+ reference: getValueByModelName(target, 'reference', [], model, _model),
229
235
  // reference admin components
230
- personal: lodash.get(
231
- target,
232
- 'personal',
233
- model !== _model ? lodash.get(app.config[model], 'personal', []) : []
234
- ),
236
+ personal: getValueByModelName(target, 'personal', [], model, _model),
235
237
  // sortOrder router
236
238
  sortOrder: lodash.get(target, 'sortOrder', 1),
237
239
 
@@ -241,7 +243,7 @@ exports.showTables = async (ctx) => {
241
243
  ),
242
244
 
243
245
  // include for admin
244
- include: lodash.get(target, 'include', ''),
246
+ include: getValueByModelName(target, 'include', '', model, _model),
245
247
  // only include exsit, and for custom like user_distribute has two user model
246
248
  relate: lodash.get(target, 'relate', ''),
247
249
  // can be mock boolean
@@ -1,4 +1,10 @@
1
- const { lodash, getAppByCtx, getConfig, moment } = require('q-koa')
1
+ const {
2
+ lodash,
3
+ getAppByCtx,
4
+ getConfig,
5
+ moment,
6
+ ServiceError,
7
+ } = require('q-koa')
2
8
 
3
9
  const axios = require('axios')
4
10
  const OAuth = require('wechat-oauth')
@@ -1269,10 +1275,10 @@ exports.short_link = async (ctx) => {
1269
1275
  ctx.SUCCESS(result)
1270
1276
  }
1271
1277
 
1272
- exports.url_scheme = async (ctx) => {
1278
+ exports.url_scheme = async (ctx, _data) => {
1273
1279
  const { app } = getAppByCtx(ctx)
1274
1280
 
1275
- const { page, scene, config = 'weixin_mp' } = ctx.request.body
1281
+ const { page, scene, config = 'weixin_mp' } = _data || ctx.request.body
1276
1282
  const appConfig = getConfig(app)
1277
1283
  const { app_id, app_secrect } = await appConfig.getObject(config)
1278
1284
  const weixinMp = new WeixinMp({
@@ -1285,9 +1291,32 @@ exports.url_scheme = async (ctx) => {
1285
1291
  scene,
1286
1292
  })
1287
1293
  ctx.SUCCESS(result)
1294
+ return result
1288
1295
  }
1289
1296
 
1290
- exports.qr_code = async (ctx) => {
1297
+ exports.query_url_link = async (ctx, _data) => {
1298
+ const { app } = getAppByCtx(ctx)
1299
+
1300
+ const { url_link, config = 'weixin_mp' } = _data || ctx.request.body
1301
+ if (!url_link) throw new ServiceError(`url_link?`)
1302
+ const appConfig = getConfig(app)
1303
+ const { app_id, app_secrect } = await appConfig.getObject(config)
1304
+ const weixinMp = new WeixinMp({
1305
+ appid: app_id,
1306
+ secrect: app_secrect,
1307
+ })
1308
+ weixinMp.init()
1309
+ const result = await weixinMp.queryUrlLink(url_link)
1310
+ const payLoad = {
1311
+ ...result,
1312
+ is_out: result.expire_time * 1000 - moment().valueOf() < 0,
1313
+ }
1314
+
1315
+ ctx.SUCCESS(payLoad)
1316
+ return payLoad
1317
+ }
1318
+
1319
+ exports.qr_code = async (ctx, _data) => {
1291
1320
  const { app } = getAppByCtx(ctx)
1292
1321
 
1293
1322
  const {
@@ -1297,7 +1326,7 @@ exports.qr_code = async (ctx) => {
1297
1326
  is_oss = false,
1298
1327
  config = 'weixin_mp',
1299
1328
  width,
1300
- } = ctx.request.body
1329
+ } = _data || ctx.request.body
1301
1330
 
1302
1331
  if (!app.service.weixin) throw new Error(`weixin可能没有service.js`)
1303
1332
  const result = await app.service.weixin.qr_code({
@@ -1309,8 +1338,8 @@ exports.qr_code = async (ctx) => {
1309
1338
  config,
1310
1339
  width,
1311
1340
  })
1312
-
1313
- return ctx.SUCCESS(result)
1341
+ ctx.SUCCESS(result)
1342
+ return result
1314
1343
  }
1315
1344
 
1316
1345
  exports.sendMessage = async (ctx) => {
@@ -12,6 +12,8 @@ const createUrlschemeUrl =
12
12
  'https://api.weixin.qq.com/wxa/generatescheme?access_token=%s'
13
13
  const createUrlLinkUrl =
14
14
  'https://api.weixin.qq.com/wxa/generate_urllink?access_token=%s'
15
+ const queryUrlLinkUrl =
16
+ 'https://api.weixin.qq.com/wxa/query_urllink?access_token=%s'
15
17
  const createShortLinkUrl =
16
18
  'https://api.weixin.qq.com/wxa/genwxashortlink?access_token=%s'
17
19
  const sendMessageUrl =
@@ -374,6 +376,26 @@ module.exports = class Singleton {
374
376
  return result.url_link
375
377
  }
376
378
 
379
+ async queryUrlLink(url_link) {
380
+ const access_token = await this.getAccessToken()
381
+ const url = util.format(queryUrlLinkUrl, access_token)
382
+
383
+ const result = await axios
384
+ .post(url, {
385
+ url_link,
386
+ })
387
+ .then((res) => res.data)
388
+
389
+ if (result.errcode) {
390
+ if (result.errcode === 40001) {
391
+ cache.reset()
392
+ return await this.queryUrlLink(url_link)
393
+ }
394
+ throw new Error(`${result.errcode};${result.errmsg}`)
395
+ }
396
+ return result.url_link_info
397
+ }
398
+
377
399
  async createShortLink(options) {
378
400
  const { page, scene, title, ...rest } = options
379
401
  const access_token = await this.getAccessToken()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "13.1.0",
3
+ "version": "13.1.2",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {