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