parent
eab2bd60ed
commit
a0413df2a3
|
@ -44,6 +44,7 @@ import {
|
|||
} from '@ionic/vue';
|
||||
import BaseLayout from '@/components/base/BaseLayout.vue';
|
||||
import ItemsList from '@/components/lists/ItemsList.vue';
|
||||
import { InAppBrowserEvent } from '@awesome-cordova-plugins/in-app-browser';
|
||||
|
||||
export default defineComponent({
|
||||
components: {
|
||||
|
@ -116,8 +117,18 @@ export default defineComponent({
|
|||
icon: documentOutline,
|
||||
data: 'single item',
|
||||
handler: () => {
|
||||
console.log('Item simples')
|
||||
wpStore.openAppBrowser('/collections/' + props.id + '/items/new');
|
||||
wpStore.openInAppBrowser('/collections/' + props.id + '/items/new');
|
||||
wpStore.listenEventInAppBrowser((event: InAppBrowserEvent) => {
|
||||
if (event &&
|
||||
event.data &&
|
||||
event.data.type === 'item_updated' &&
|
||||
event.data.item &&
|
||||
event.data.item.status !== 'auto-draft'
|
||||
) {
|
||||
wpStore.hideInAppBrowser();
|
||||
loadItemsByCollection({}, true);
|
||||
}
|
||||
});
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
|
@ -95,11 +95,8 @@ export default {
|
|||
},
|
||||
methods: {
|
||||
async openLoginForm() {
|
||||
await this.wpStore.fetchApplicationAuthorization(
|
||||
this.siteUrl,
|
||||
"_self",
|
||||
"location=no"
|
||||
);
|
||||
this.wpStore.userSiteUrl = this.siteUrl;
|
||||
await this.wpStore.fetchApplicationAuthorization(this.siteUrl);
|
||||
if (this.wpStore.authorizationURL) {
|
||||
this.wpStore.createInAppBrowser();
|
||||
this.wpStore.inAppBrowser
|
||||
|
@ -108,6 +105,7 @@ export default {
|
|||
}
|
||||
},
|
||||
async handleBrowserLoadStop(event: InAppBrowserEvent) {
|
||||
console.log(event)
|
||||
if (
|
||||
event.url &&
|
||||
typeof event.url == "string" &&
|
||||
|
@ -115,16 +113,17 @@ export default {
|
|||
event.url.split("?").length >= 2
|
||||
) {
|
||||
const params = new URLSearchParams(event.url.split("?")[1]);
|
||||
|
||||
if ( params.get("page") === "tainacan_admin" ) {
|
||||
const userLogin = params.get("user_login");
|
||||
let userToken = params.get("password");
|
||||
|
||||
console.log(userToken)
|
||||
if (
|
||||
typeof userToken == "string" &&
|
||||
userToken.indexOf("#") >= 0
|
||||
)
|
||||
userToken = userToken.split("#")[0];
|
||||
|
||||
console.log(userToken, userLogin)
|
||||
if (!!userLogin && !!userToken) {
|
||||
this.wpStore.inAppBrowser.hide();
|
||||
|
||||
|
|
|
@ -3,8 +3,10 @@ import axios from "axios";
|
|||
import { Storage } from "@ionic/storage";
|
||||
import {
|
||||
InAppBrowser,
|
||||
InAppBrowserEvent,
|
||||
InAppBrowserEventType,
|
||||
InAppBrowserObject,
|
||||
InAppBrowserEvent
|
||||
InAppBrowserOriginal
|
||||
} from "@awesome-cordova-plugins/in-app-browser/index";
|
||||
|
||||
const store = new Storage();
|
||||
|
@ -89,32 +91,38 @@ const useWpStore = defineStore("wp", {
|
|||
this.userLogin = await store.get("userLogin");
|
||||
this.userToken = await store.get("userToken");
|
||||
},
|
||||
createInAppBrowser() {
|
||||
let tainacanAdminUrl = this.userSiteUrl + "/wp-admin/admin.php?page=tainacan_admin&mobileAppMode=true";
|
||||
createInAppBrowser(url = '',extraParams = 'location=no,fullscreen=no,zoom=no') {
|
||||
let tainacanAdminUrl = this.userSiteUrl + "/wp-admin/admin.php?page=tainacan_admin&mobileAppMode=true&itemEditionMode=true" + url;
|
||||
if (!this.userIsLoggedIn && this.authorizationURL)
|
||||
tainacanAdminUrl = this.authorizationURL + "?app_name=TainacanMobileApp&success_url=" + tainacanAdminUrl;
|
||||
|
||||
const anInAppBrowser = InAppBrowser.create(tainacanAdminUrl);
|
||||
const anInAppBrowser = InAppBrowser.create(tainacanAdminUrl, '_blank', extraParams);
|
||||
this.inAppBrowser = anInAppBrowser;
|
||||
},
|
||||
openAppBrowser(url: string) {
|
||||
const inAppBrowserScript = `
|
||||
window.addEventListener('hashchange', function() {
|
||||
console.log(window.location.hash);
|
||||
});
|
||||
openInAppBrowser(url: string) {
|
||||
|
||||
if (!this.inAppBrowser || !this.inAppBrowser.executeScript)
|
||||
this.createInAppBrowser('#' + url, 'hidden=yes,location=no,fullscreen=no,zoom=no');
|
||||
else {
|
||||
const urlRedirectionScript = `
|
||||
window.history.replaceState(
|
||||
null,
|
||||
null,
|
||||
'${this.userSiteUrl}/wp-admin/admin.php?mobileAppMode=true&page=tainacan_admin#${url}'
|
||||
'${this.userSiteUrl}/wp-admin/admin.php?page=tainacan_admin&mobileAppMode=true&itemEditionMode=true#${url}'
|
||||
);
|
||||
window.history.go(0);
|
||||
`;
|
||||
if (!this.inAppBrowser || !this.inAppBrowser.executeScript)
|
||||
this.createInAppBrowser();
|
||||
|
||||
this.inAppBrowser.executeScript({ code: inAppBrowserScript });
|
||||
this.inAppBrowser.executeScript({ code: urlRedirectionScript });
|
||||
}
|
||||
this.inAppBrowser.show();
|
||||
},
|
||||
hideInAppBrowser() {
|
||||
if (this.inAppBrowser && this.inAppBrowser.hide)
|
||||
this.inAppBrowser.hide();
|
||||
},
|
||||
listenEventInAppBrowser(event: any) {
|
||||
this.inAppBrowser.on('message').subscribe(event);
|
||||
}
|
||||
},
|
||||
});
|
||||
export { useWpStore };
|
||||
|
|
Loading…
Reference in New Issue