settings.vue
6.6 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
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
<template>
<view>
<view class="data-item">
<text>弹窗开关</text>
<switch checked @change="switchChange"></switch>
</view>
<view v-show="isApp" class="data-item" @click="clearCache()">
<text>清理缓存</text>
<view>
<text style="margin-right: 30rpx;">{{currentSize}}</text>
<image style="width: 28rpx; height: 28rpx;" src="../../static/arrow_right.png"></image>
</view>
</view>
<view class="data-item" @click="goToShare()">
<text>好友分享</text>
<image style="width: 28rpx; height: 28rpx;" src="../../static/arrow_right.png"></image>
</view>
<view class="data-item" @click="goToStop()">
<text>店主认证资料</text>
<image style="width: 28rpx; height: 28rpx;" src="../../static/arrow_right.png"></image>
</view>
<view v-show="isApp" class="data-item" @click="showUpdateVersion()">
<text>版本检测和更新</text>
<view>
<text style="font-size: 27rpx; margin-right: 15rpx;">{{this.updateInfoStr}}</text>
<image style="width: 28rpx; height: 28rpx;" src="../../static/arrow_right.png"></image>
</view>
</view>
<button style="background-color: white; margin: 35rpx; color: #469bf4;" @click="bindLogout()">
{{ this.hasLogin ? "退出登录" : '登陆/注册' }}</button>
</view>
</template>
<script>
import {
default as http
} from "@/utils/http.js";
import {
updateUseModal,
compare
} from '@/utils/check_update.js';
import {
default as app_config
} from '@/utils/app.js';
import loginHelper from "../../utils/loginHelper.js"
export default {
data() {
return {
app_config,
hasLogin: false,
updateInfoStr: "已是最新版本",
versionData: null,
versionName: app_config.app_info.AppName,
currentSize: "",
isApp: false
}
},
onShow() {
this.hasLogin = loginHelper.hasLogin()
console.log("onShow");
// #ifdef APP
this.updateVersion();
this.getStorageSize()
this.isApp = true;
// #endif
},
methods: {
goToStop() {
if(this.hasLogin) {
let tempData = {
url: `${app_config.server_url.app_host}eshop/center/adv?zq`
}
uni.navigateTo({
url: `/pages/notitle_webview/notitle_webview?info=${encodeURIComponent(JSON.stringify(tempData))}`
})
} else {
uni.navigateTo({
url: '/pages/login_pwd/login_pwd',
});
}
},
goToShare() {
},
clearCache() {
let that = this;
let os = plus.os.name;
if (os == 'Android') {
let main = plus.android.runtimeMainActivity();
let sdRoot = main.getCacheDir();
let files = plus.android.invoke(sdRoot, "listFiles");
let len = files.length;
console.log(files, len)
for (let i = 0; i < len; i++) {
let filePath = '' + files[i]; // 没有找到合适的方法获取路径,这样写可以转成文件路径
plus.io.resolveLocalFileSystemURL(filePath, function(entry) {
if (entry.isDirectory) {
entry.removeRecursively(function(entry) { //递归删除其下的所有文件及子目录
that.files = []
uni.showToast({
title: '清除成功',
duration: 2000
});
that.getStorageSize(); // 重新计算缓存
}, function(e) {
console.log(e.message)
});
} else {
entry.remove();
}
}, function(e) {
console.log('文件路径读取失败')
});
}
} else { // ios
plus.cache.clear(function() {
uni.showToast({
title: '清除成功',
duration: 2000
});
that.getStorageSize();
});
}
},
// 获取本地缓存大小
getStorageSize() {
// #ifdef APP
let that = this;
plus.cache.calculate(function(size) {
let sizeCache = parseInt(size);
if (sizeCache == 0) {
that.currentSize = "0B";
} else if (sizeCache < 1024) {
that.currentSize = sizeCache + "B";
} else if (sizeCache < 1048576) {
that.currentSize = (sizeCache / 1024).toFixed(2) + "KB";
} else if (sizeCache < 1073741824) {
that.currentSize = (sizeCache / 1048576).toFixed(2) + "MB";
} else {
that.currentSize = (sizeCache / 1073741824).toFixed(2) + "GB";
}
});
// #endif
},
bindLogout() {
{
loginHelper.logout();
uni.reLaunch({
url: '/pages/mine/mine'
})
}
},
onLogout() {
if (!loginHelper.hasLogin()) {
uni.navigateTo({
url: '/pages/login_pwd/login_pwd',
});
} else {
uni.navigateTo({
url: "/pages/logout/logout",
});
}
},
showUpdateVersion() {
if (this.versionData) {
updateUseModal({
title: "更新",
contents: this.versionData.Version_Content || '',
is_mandatory: false,
url: this.versionData.Package_Url,
platform: 'android',
type: "pkg" // 安装包类型
});
}
},
async updateVersion() {
let appInfo = app_config.app_info;
// #ifdef APP-PLUS
let query_data = `query{
update_app_version(App_Code:${JSON.stringify(appInfo.Version)}) {
App_Code
App_Name
Sys_Code
Sys_Name
Version_Code
Version_Type
Version_Content
Package_Url
Package_Weight
Version_Num
Update_Way
Download_Way
Update_Time
Publish_Time
Sys_Version
Promoter_Id
}
}`;
console.info(query_data);
let result = await http.gql({
query: query_data
})
console.info(result);
//处理返回请求
if (result && result.data && result.data.update_app_version) {
if (result.data.update_app_version.Error) {
uni.showToast({
icon: "none",
title: result.data.update_app_version.Error,
});
} else {
this.versionData = result.data.update_app_version;
if (this.versionData && this.versionData.Package_Url) {
this.updateInfoStr = "更新版本";
} else {
this.updateInfoStr = "已是最新版本";
}
}
}
// #endif
// #ifdef MP-WEIXIN
this.versionName = app_config.app_info.AppName
this.updateInfoStr = appInfo.Version
// #endif
},
switchChange(e) {
}
}
}
</script>
<style>
.data-item {
display: flex;
justify-content: space-between;
align-items: center;
height: 110rpx;
background-color: white;
margin-top: 3rpx;
margin-bottom: 3rpx;
padding-left: 30rpx;
padding-right: 30rpx;
}
</style>