forked from opentiny/tiny-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
73 lines (68 loc) · 2.07 KB
/
Copy pathapp.js
File metadata and controls
73 lines (68 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
* Copyright (c) 2023 - present TinyEngine Authors.
* Copyright (c) 2023 - present Huawei Cloud Computing Technologies Co., Ltd.
*
* Use of this source code is governed by an MIT-style license.
*
* THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
* BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
*
*/
import { pageService } from '../routes/main-routes'
import { getResponseData } from '../tool/Common'
export default class AppService {
async lock(query) {
const { id, state } = query
const occupier = state === 'occupy' ? pageService.userInfo : null
await pageService.update(id, { occupier })
return getResponseData({
operate: 'success',
occupier
})
}
// 获取应用预览数据
getAppPreviewMetaData() {
const appMetaData = require('./appinfo.json')
const { i18n: i18nEntries, source = [], extension = [], app } = appMetaData
// 拼装数据源
const dataSource = {
list: source,
dataHandler: app['data_handler']
}
// 拼装工具类
const utils = []
extension.forEach((item) => {
const { name, type, content, category } = item
const data = { name, type, content }
if (category === 'utils') {
utils.push(data)
}
})
// 拼装国际化词条
const entriesData = getResponseData(i18nEntries)
const i18n = this.formatI18nEntrites(entriesData)
return getResponseData({
dataSource,
globalState: app['global_state'],
utils,
i18n
})
}
formatI18nEntrites(entriesData) {
const entries = entriesData.data
// 中文和英文作为全局国际化语言,并没有和应用/区块建立关联关系
const defaultLang = [{ lang: 'en_US' }, { lang: 'zh_CN' }]
const res = {}
entries.forEach((entry) => {
const {
key,
lang: { lang },
content
} = entry
res[lang] = res[lang] || {}
res[lang][key] = content
})
return res
}
}