王飞
2025-03-07 c5e49c10499435802a6551b98772f95660c6f85a
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
import {
    validator,
    enumConverter
} from '@/js_sdk/validator/opendb-app-versions.js';
 
const platform_iOS = 'iOS';
const platform_Android = 'Android';
const db = uniCloud.database();
 
function getValidator(fields) {
    let reuslt = {}
    for (let key in validator) {
        if (fields.includes(key)) {
            reuslt[key] = validator[key]
        }
    }
    return reuslt
}
 
export const fields =
    'appid,name,title,contents,platform,type,version,min_uni_version,url,stable_publish,is_silently,is_mandatory,create_date,store_list'
 
export default {
    data() {
        return {
            labelWidth: '100px',
            enableiOSWgt: true, // 是否开启iOS的wgt更新
            silentlyContent: '静默更新:App升级时会在后台下载wgt包并自行安装。新功能在下次启动App时生效',
            mandatoryContent: '强制更新:App升级弹出框不可取消',
            stablePublishContent: '同时只可有一个线上发行版,线上发行不可更设为下线。\n未上线可以设为上线发行并自动替换当前线上发行版',
            stablePublishContent2: '使用本包替换当前线上发行版',
            uploadFileContent: '可下载安装包地址。上传文件到云存储自动填写,也可以手动填写',
            minUniVersionContent: '上次使用新Api或打包新模块的App版本',
            priorityContent: '检查更新时,按照优先级从大到小依次尝试跳转商店。如果都跳转失败,则会打开浏览器使用下载链接下载apk安装包',
            latestStableData: [], // 库中最新已上线版
            appFileList: null, // 上传包
            type_valuetotext: enumConverter.type_valuetotext,
            preUrl: '',
            formData: {
                "appid": "",
                "name": "",
                "title": "",
                "contents": "",
                "platform": [],
                "store_list": [],
                "type": "",
                "version": "",
                "min_uni_version": "",
                "url": "",
                "stable_publish": false,
                "create_date": null
            },
            formOptions: {
                "platform_localdata": [{
                    "value": "Android",
                    "text": "安卓"
                },
                {
                    "value": "iOS",
                    "text": "苹果"
                }
                ],
                "type_localdata": [{
                    "value": "native_app",
                    "text": "原生App安装包"
                },
                {
                    "value": "wgt",
                    "text": "App资源包"
                }
                ]
            },
            rules: {
                ...getValidator([
                    "appid", "contents", "platform", "type",
                    "version", "min_uni_version", "url", "stable_publish",
                    "title", "name", "is_silently", "is_mandatory", "store_list"
                ])
            }
        }
    },
    onReady() {
        this.$refs.form.setRules(this.rules)
    },
    computed: {
        isWGT() {
            return this.formData.type === 'wgt'
        },
        isiOS() {
            return !this.isWGT ? this.formData.platform.includes(platform_iOS) : false;
        },
        hasPackage() {
            return this.appFileList && !!Object.keys(this.appFileList).length
        },
        fileExtname() {
            return this.isWGT ? ['wgt'] : ['apk']
        },
        platformLocaldata() {
            return !this.isWGT ? this.formOptions.platform_localdata : this.enableiOSWgt ? this.formOptions
                .platform_localdata : [this.formOptions.platform_localdata[0]]
        },
        uni_platform() {
            return (this.isiOS ? platform_iOS : platform_Android).toLocaleLowerCase()
        }
    },
    methods: {
        getStoreList(appid) {
            return db.collection('opendb-app-list')
                .where({
                    appid
                })
                .get()
                .then(res => {
                    const data = res.result.data[0]
                    return data ? data.store_list || [] : []
                })
        },
        packageUploadSuccess(res) {
            uni.showToast({
                icon: 'success',
                title: '上传成功',
                duration: 800
            })
            this.preUrl = this.formData.url
            this.formData.url = res.tempFilePaths[0]
        },
        deleteFile(fileList) {
            return this.$request('deleteFile', {
                fileList
            }, {
                functionName: 'uni-upgrade-center'
            })
        },
        async packageDelete(res) {
            if (!this.hasPackage) return;
            await this.deleteFile([res.tempFilePath])
            uni.showToast({
                icon: 'success',
                title: '删除成功',
                duration: 800
            })
            this.formData.url = this.preUrl
            this.$refs.form.clearValidate('url')
        },
        selectFile() {
            if (this.hasPackage) {
                uni.showToast({
                    icon: 'none',
                    title: '只可上传一个文件,请删除已上传后重试',
                    duration: 1000
                });
            }
        },
        createCenterRecord(value) {
            return {
                ...value,
                uni_platform: this.uni_platform,
                create_env: 'upgrade-center'
            }
        },
        createCenterQuery({
            appid
        }) {
            return {
                appid,
                create_env: 'upgrade-center'
            }
        },
        createStatQuery({
            appid,
            type,
            version,
            uni_platform
        }) {
            return {
                appid,
                type,
                version,
                uni_platform: uni_platform ? uni_platform : this.uni_platform,
                create_env: 'uni-stat',
                stable_publish: false
            }
        },
        toUrl(url){
            // #ifdef H5
            window.open(url);
            // #endif
            // #ifndef H5
            uni.showToast({
                title: '请在浏览器中打开',
                icon: 'none'
            });
            // #endif
        },
        getCloudStorageConfig(){
            return uni.getStorageSync('uni-admin-cloud-storage-config') || {};
        },
        setCloudStorageConfig(data={}){
            uni.setStorageSync('uni-admin-cloud-storage-config', data);
        },
        // 临时方法,后面会优化
        setCloudStorage(data){
            // uniCloud.setCloudStorage 不是标准的API,临时挂载在uniCloud对象上的,后面会优化
            if (typeof uniCloud.setCloudStorage === "function") {
                uniCloud.setCloudStorage(data);
            }
        }
    }
}