|
@@ -1,10 +1,13 @@
|
|
|
import { defineStore, } from 'pinia';
|
|
|
+import { useRoute } from "vue-router";
|
|
|
import axios from "axios";
|
|
|
|
|
|
export const useMainStore = defineStore('mainStore', {
|
|
|
state: () => ({
|
|
|
+ apiUrl: import.meta.env.VITE_API_URL,
|
|
|
count: 0,
|
|
|
token: "",
|
|
|
+ authCode: "", // 藝文中心登入回傳參數
|
|
|
loginState: false, // 登入狀態
|
|
|
loginDialog: false, // 登入視窗
|
|
|
profile: {}, // 使用者資訊
|
|
@@ -23,19 +26,69 @@ export const useMainStore = defineStore('mainStore', {
|
|
|
},
|
|
|
actions: {
|
|
|
// 檢查登入狀態
|
|
|
+ // checkToken() {
|
|
|
+ // const token = localStorage.getItem('token');
|
|
|
+ // console.log('checkToken', token);
|
|
|
+ // if (token) {
|
|
|
+ // this.token = token;
|
|
|
+ // this.loginState = true;
|
|
|
+ // } else {
|
|
|
+ // this.token = null;
|
|
|
+ // this.loginState = false;
|
|
|
+ // }
|
|
|
+
|
|
|
+ // return this.loginState;
|
|
|
+ // },
|
|
|
checkToken() {
|
|
|
- const token = localStorage.getItem('token');
|
|
|
- console.log('checkToken', token);
|
|
|
- if (token) {
|
|
|
- this.token = token;
|
|
|
+ const queryParams = this.getURLParams();
|
|
|
+
|
|
|
+ console.log('queryParams', queryParams);
|
|
|
+ if (queryParams.AuthCode) {
|
|
|
this.loginState = true;
|
|
|
+ this.authCode = queryParams.AuthCode;
|
|
|
+ console.log('AuthCode', this.authCode);
|
|
|
+ localStorage.setItem("AuthCode", this.authCode);
|
|
|
+ this.getAuthToken();
|
|
|
} else {
|
|
|
- this.token = null;
|
|
|
this.loginState = false;
|
|
|
}
|
|
|
+ console.log(queryParams.AuthCode);
|
|
|
|
|
|
return this.loginState;
|
|
|
},
|
|
|
+ async getAuthToken() {
|
|
|
+ console.log('getAuthToken');
|
|
|
+ // https://member.moc.gov.tw/MOCMC/T0001/ottGetAuthToken
|
|
|
+
|
|
|
+ try {
|
|
|
+ // const response1 = await axios.get(
|
|
|
+ // `https://member.moc.gov.tw/MOCMC/T0001/ottGetAuthToken?SYS_ID=CRAFT_NTCRI&SYS_PASSWORD=luZ2le0W&AuthCode=${this.authCode}&IS_DEV=Y`
|
|
|
+ // );
|
|
|
+ // const response2 = await axios.get(
|
|
|
+ // `https://10.40.100.32/MOCMC/T0001/ottGetAuthToken?SYS_ID=CRAFT_NTCRI&SYS_PASSWORD=luZ2le0W&AuthCode=${this.authCode}&IS_DEV=Y`
|
|
|
+ // );
|
|
|
+ const response3 = await axios.post(
|
|
|
+ `https://member.moc.gov.tw/MOCMC/T0001/ottGetAuthToken?SYS_ID=CRAFT_NTCRI&SYS_PASSWORD=luZ2le0W&AuthCode=${this.authCode}&IS_DEV=Y`
|
|
|
+ );
|
|
|
+ // console.log('取得 AuthToken-1', response1);
|
|
|
+ // console.log('取得 AuthToken-2', response2);
|
|
|
+ console.log('取得 AuthToken-3', response3);
|
|
|
+
|
|
|
+ } catch (error) {
|
|
|
+ console.error(error);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 取得網址參數
|
|
|
+ getURLParams() {
|
|
|
+ const urlParams = new URLSearchParams(window.location.search);
|
|
|
+ const params = {};
|
|
|
+
|
|
|
+ urlParams.forEach((value, key) => {
|
|
|
+ params[key] = value;
|
|
|
+ });
|
|
|
+
|
|
|
+ return params;
|
|
|
+ },
|
|
|
logout() {
|
|
|
localStorage.removeItem("token");
|
|
|
console.log('logout');
|
|
@@ -104,19 +157,12 @@ export const useMainStore = defineStore('mainStore', {
|
|
|
// 處理時間格式(日期+時間)
|
|
|
mergeAndFormatDateTime(dateString, timeInfo) {
|
|
|
const date = new Date(dateString);
|
|
|
+ const year = date.getFullYear();
|
|
|
+ const month = date.getMonth() + 1; // 月份是從 0 開始計算的,所以要加 1
|
|
|
+ const day = date.getDate();
|
|
|
|
|
|
- date.setHours(timeInfo.hours);
|
|
|
- date.setMinutes(timeInfo.minutes);
|
|
|
- date.setSeconds(timeInfo.seconds);
|
|
|
-
|
|
|
- const year = date.getUTCFullYear();
|
|
|
- const month = String(date.getUTCMonth() + 1).padStart(2, "0");
|
|
|
- const day = String(date.getUTCDate()).padStart(2, "0");
|
|
|
- const hours = String(date.getUTCHours()).padStart(2, "0");
|
|
|
- const minutes = String(date.getUTCMinutes()).padStart(2, "0");
|
|
|
- const seconds = String(date.getUTCSeconds()).padStart(2, "0");
|
|
|
-
|
|
|
- return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}.000Z`;
|
|
|
+ return `${year}-${month}-${day}T${timeInfo.hours < 10 ? '0' : ''}${timeInfo.hours}:${timeInfo.minutes < 10 ? '0' : ''}${timeInfo.minutes}:00.000Z`;
|
|
|
+ // return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}.000Z`;
|
|
|
},
|
|
|
// 將 UTC 時間轉換為台灣時間
|
|
|
convertUTCtoTaiwanTime(utcTimeString) {
|
|
@@ -125,6 +171,18 @@ export const useMainStore = defineStore('mainStore', {
|
|
|
console.log('轉台灣時間', localTime);
|
|
|
return localTime;
|
|
|
},
|
|
|
+ // 判斷兩組日期是否相同
|
|
|
+ isSameDay(date1, date2) {
|
|
|
+ const year1 = date1.getFullYear();
|
|
|
+ const month1 = date1.getMonth() + 1;
|
|
|
+ const day1 = date1.getDate();
|
|
|
+
|
|
|
+ const year2 = date2.getFullYear();
|
|
|
+ const month2 = date2.getMonth() + 1;
|
|
|
+ const day2 = date2.getDate();
|
|
|
+
|
|
|
+ return `${year1}${month1}${day1}` === `${year2}${month2}${day2}`;
|
|
|
+ },
|
|
|
getPDF(name) {
|
|
|
return `https://ntcri.org/pdf/${name}.pdf`;
|
|
|
},
|
|
@@ -162,7 +220,7 @@ export const useMainStore = defineStore('mainStore', {
|
|
|
if (data.group_id === 9) {
|
|
|
return this.getImageUrl("cfa-default.jpg");
|
|
|
} else if (data.special_class_list_name === "one_day_class") {
|
|
|
- return this.getImageUrl("default.png");
|
|
|
+ return this.getImageUrl("default.webp");
|
|
|
} else if (regex.test(data.cover_img)) {
|
|
|
return data.cover_img;
|
|
|
} else {
|