support pull to refresh in account list page

This commit is contained in:
MaysWind
2020-11-11 00:27:51 +08:00
parent 9f328402d8
commit 6e782d9d83
2 changed files with 44 additions and 13 deletions
+18
View File
@@ -26,6 +26,23 @@ function isBoolean(val) {
return typeof(val) === 'boolean';
}
function getCategorizedAccounts(allAccounts) {
const ret = {};
for (let i = 0; i < allAccounts.length; i++) {
const account = allAccounts[i];
if (!ret[account.category]) {
ret[account.category] = [];
}
const accountList = ret[account.category];
accountList.push(account);
}
return ret;
}
export default {
isFunction,
isObject,
@@ -33,4 +50,5 @@ export default {
isString,
isNumber,
isBoolean,
getCategorizedAccounts,
};
+26 -13
View File
@@ -1,5 +1,5 @@
<template>
<f7-page>
<f7-page ptr @ptr:refresh="reload">
<f7-navbar>
<f7-nav-left :back-link="$t('Back')"></f7-nav-left>
<f7-nav-title :title="$t('Account List')" :back-link="$t('Back')"></f7-nav-title>
@@ -97,18 +97,7 @@ export default {
return;
}
self.accounts = {};
for (let i = 0; i < data.result.length; i++) {
const account = data.result[i];
if (!self.accounts[account.category]) {
self.accounts[account.category] = [];
}
const accountList = self.accounts[account.category];
accountList.push(account);
}
self.accounts = self.$utils.getCategorizedAccounts(data.result);
}).catch(error => {
self.loading = false;
@@ -124,6 +113,30 @@ export default {
});
},
methods: {
reload(done) {
const self = this;
self.$services.getAllAccounts().then(response => {
done();
const data = response.data;
if (!data || !data.success || !data.result) {
self.$toast('Unable to get account list');
return;
}
self.accounts = self.$utils.getCategorizedAccounts(data.result);
}).catch(error => {
done();
if (error.response && error.response.data && error.response.data.errorMessage) {
self.$toast({ error: error.response.data });
} else if (!error.processed) {
self.$toast('Unable to get account list');
}
});
},
edit() {
},