新增健管師並顯示

This commit is contained in:
leo 2025-02-22 12:26:58 +08:00
parent f134fe3541
commit 37b445ea63
6 changed files with 276 additions and 167 deletions

View File

@ -570,36 +570,45 @@ async function logout() {
});
}
// 🔐 Token SSR
const authToken = useState("authToken", () => process.client ? localStorage.getItem("token_TCM") || "" : "");
var token; //
const token_check = ()=>{
// JWT
token = localStorage.getItem("token_TCM");
console.log(token);
// token
if (token != null) {
$.ajax({
type: "GET",
url: $api_host + "/Users/token_check_user",
// 🔍 Token
const token_check = async () => {
if (!process.client) return; // client-side
const token = localStorage.getItem("token_TCM");
console.log("Token:", token);
if (!token) {
console.log("無 Token轉跳首頁");
router.push("/Home_pages/");
return;
}
try {
const response = await fetch(`${$api_host}/Users/token_check_user`, {
method: "GET",
headers: {
Authorization: token,
},
success: function (response) {
// 8
if(response.level<=8 ){
router.push("/Home_pages/");
}
},
error: function (xhr) {
console.log(xhr);
},
});
} else {
console.log("pass");
if (!response.ok) throw new Error("Token 驗證失敗");
const data = await response.json();
console.log("驗證成功:", data);
// level 8
if (data.level <= 8) {
router.push("/Home_pages/");
}
} catch (error) {
console.error("Token 驗證失敗", error);
router.push("/Home_pages/");
}
};
//
// 🔄
onMounted(token_check);
</script>

View File

@ -568,36 +568,46 @@ async function logout() {
});
}
var token; //
const token_check = ()=>{
// JWT
token = localStorage.getItem("token_TCM");
console.log(token);
// token
if (token != null) {
$.ajax({
type: "GET",
url: $api_host + "/Users/token_check_user",
// 🔐 Token SSR
const authToken = useState("authToken", () => process.client ? localStorage.getItem("token_TCM") || "" : "");
// 🔍 Token
const token_check = async () => {
if (!process.client) return; // client-side
const token = localStorage.getItem("token_TCM");
console.log("Token:", token);
if (!token) {
console.log("無 Token轉跳首頁");
router.push("/Home_pages/");
return;
}
try {
const response = await fetch(`${$api_host}/Users/token_check_user`, {
method: "GET",
headers: {
Authorization: token,
},
success: function (response) {
// 8
if(response.level<=6 ){
router.push("/Home_pages/");
}
},
error: function (xhr) {
console.log(xhr);
},
});
} else {
console.log("pass");
if (!response.ok) throw new Error("Token 驗證失敗");
const data = await response.json();
console.log("驗證成功:", data);
// level 6
if (data.level <= 6) {
router.push("/Home_pages/");
}
} catch (error) {
console.error("Token 驗證失敗", error);
router.push("/Home_pages/");
}
};
//
// 🔄
onMounted(token_check);
</script>

View File

@ -41,7 +41,7 @@
</div>
<div class="form-group">
<label>是否啟用</label>
<select style="width:100%" v-model="Enable_ON">
<select style="width:100%" >
<option value="Y">Y</option>
<option value="N">N</option>
</select>
@ -65,7 +65,8 @@ import { ref, onMounted } from 'vue'
import { useRouter } from "vue-router"; //
const { $api_host } = useNuxtApp(); //API host
const router = useRouter(); //
// 🔐 token
const authToken = ref("");
//
@ -80,32 +81,57 @@ function close_edit_Company_view() {
edit_Company_view.value?.close();
}
const company_name=ref("");
//
const get_data = async () => {
const now_route = useRoute(); //
const company_guid = now_route.params.guid
const Company_data = await get_company_data()
set_Company(Company_data);
};
//
const get_company_data= async () =>{
const route = useRoute(); //
const company_guid = route.params.guid; // guid
// company_guid
if (!company_guid) {
console.error("沒有找到公司 GUID");
return;
}
try {
const response = await fetch(`${$api_host}/api/Company_detail_table/get_campany-${company_guid}`, {
const response = await $fetch(`${$api_host}/api/Company_detail_table/get_campany-${company_guid}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: authToken.value, // authToken
},
});
if (!response.ok) throw new Error(`HTTP 錯誤! 狀態碼: ${response.status}`);
const data = await response.json();
company_name.value=data.company_name
console.log("✅ 獲取成功", response);
return response
} catch (error) {
console.error("獲取公司資料失敗:", error);
}
}
};
//
const company_name=ref("");
const set_Company=(data)=>{
company_name.value =data.company_name
}
//
onMounted(get_data);
// 🚀 mounted token
onMounted(() => {
if (process.client) {
// localStorage token reactive
authToken.value = localStorage.getItem("token_TCM") || "";
}
get_data(); // token 調 API
});
</script>

View File

@ -74,11 +74,14 @@ import { ref, onMounted } from 'vue'
import { useRouter } from "vue-router"; //
const { $api_host } = useNuxtApp(); //API host
const router = useRouter(); //
// 🔐 token
const authToken = ref("");
const add_Company_view = ref(null);
//
async function add_company() {
const add_company = async () => {
companyName.value = "";
companyPhone.value = "";
companyaccount.value = "";
@ -86,7 +89,7 @@ async function add_company() {
add_Company_view.value?.showModal();
}
// <->
function close_add_Company_view() {
const close_add_Company_view = () => {
add_Company_view.value?.close();
}
@ -96,7 +99,7 @@ const companyName = ref("");
const companyPhone = ref("");
const companyaccount = ref("");
const companypassword = ref("");
async function submitCompany() {
const submitCompany = async () => {
try {
const companyData = {
@ -109,14 +112,11 @@ async function submitCompany() {
const response = await fetch(`${$api_host}/api/Company_detail_table/Add_campany`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
'Content-Type': 'application/json',
Authorization: authToken.value,
},
body: JSON.stringify(companyData)
});
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
add_Company_view.value?.close();
alert('上傳成功!');
get_data();
@ -127,29 +127,63 @@ async function submitCompany() {
}
//
const companies = ref([]);
const get_data = async () => {
try {
const response = await fetch(`${$api_host}/api/Company_detail_table/get_all_campany`);
if (!response.ok) throw new Error(`HTTP 錯誤! 狀態碼: ${response.status}`);
const data = await response.json();
companies.value = data; //
//
const get_data = async () => {
const All_Companies = await get_All_Companies();//
set_All_Companies_data(All_Companies);
}
// 📌
const get_All_Companies = async () => {
if (!process.client) return; // client-side
//const token = localStorage.getItem("token_TCM");
try {
const response = await $fetch(`${$api_host}/api/Company_detail_table/get_all_campany`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: authToken.value,
},
});
console.log("✅ 獲取成功", response);
return response
} catch (error) {
console.error('獲取公司資料失敗:', error);
console.error("🔴 獲取公司資料失敗", error);
}
};
//
const companies = ref([]);
const set_All_Companies_data = (data) => {
console.log(data)
companies.value = data; //
}
//
async function edit_company(guid){
const edit_company = async (guid) => {
console.log(guid)
router.push("/Lamiter_pages/Company-" + guid);
}
//
onMounted(get_data);
// 🚀 mounted token
onMounted(() => {
if (process.client) {
// localStorage token reactive
authToken.value = localStorage.getItem("token_TCM") || "";
}
get_data(); // token 調 API
});
</script>

View File

@ -5,15 +5,15 @@
</button>
<br /><br />
<div class="row">
<div v-for="healther in healthers" :key="health.guid" class="col-xl-3 col-md-6 mb-4">
<div class="card border-left-primary shadow h-100 py-2" @click="edit_health(health.guid)">
<div v-for="healther in healthers" :key="healther.guid" class="col-xl-3 col-md-6 mb-4">
<div class="card border-left-primary shadow h-100 py-2" @click="edit_health(healther.guid)">
<div class="card-body">
<div class="row no-gutters align-items-center">
<div class="col mr-2">
<div class="text-xs font-weight-bold text-primary text-uppercase mb-1">
健管師名稱
</div>
<div class="h5 mb-0 font-weight-bold text-gray-800">{{ health.health_name }}</div>
<div class="h5 mb-0 font-weight-bold text-gray-800">{{ healther.health_name }}</div>
</div>
<div class="col-auto">
<i class="fas fa-user-tie fa-2x text-gray-300"></i> <!-- 改為人圖標 -->
@ -68,6 +68,8 @@ import { ref, onMounted } from 'vue'
import { useRouter } from "vue-router"; //
const { $api_host } = useNuxtApp(); //API host
const router = useRouter(); //
const authToken = ref("");// 🔐 token
const add_Health_view = ref(null);
definePageMeta({
@ -75,7 +77,7 @@ definePageMeta({
})
//
async function add_health_manager() {
const add_health_manager = async () => {
healthName.value = "";
healthPhone.value = "";
healthaccount.value = "";
@ -84,7 +86,7 @@ async function add_health_manager() {
}
// <->
function close_add_Health_view() {
const close_add_Health_view = () => {
add_Health_view.value?.close();
}
@ -93,31 +95,30 @@ const healthName = ref("");
const healthPhone = ref("");
const healthaccount = ref("");
const healthpassword = ref("");
async function submitCompany() {
const submitHealth = async () => {
try {
const healthData = {
lastname: companyName.value,
username: companyaccount.value,
password: companypassword.value
lastname: healthName.value,
username: healthaccount.value,
password: healthpassword.value,
company_guid: company_guid.value
};
console.log(companyData)
console.log(healthData)
const response = await fetch(`${$api_host}/api/Company_detail_table/Add_campany`, {
const response = await $fetch(`${$api_host}/api/Health_detail_table/Add_health`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
'Content-Type': 'application/json',
Authorization: authToken.value,
},
body: JSON.stringify(companyData)
body: JSON.stringify(healthData)
});
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
add_Company_view.value?.close();
add_Health_view.value?.close();
alert('上傳成功!');
get_data();
} catch (error) {
console.error(error);
alert('上傳失敗,請檢查後端!');
}
@ -125,42 +126,72 @@ async function submitCompany() {
const company_guid = ref ("")
const company_guid = ref("") //GUID
//
const get_data = async () => {
const authToken = useState("authToken", () => process.client ? localStorage.getItem("token_TCM") || "" : "");
console.log(authToken)
await get_company_basic_data()
await get_all_health_data()
await get_company_basic_data();
const All_Health_data = await get_all_health_data();
set_All_Health_data(All_Health_data);
}
//
const get_company_basic_data = async () => {
try {
const response = await fetch(`${$api_host}/Users/token_check_user`, {
const response = await $fetch(`${$api_host}/Users/token_check_user`, {
method: 'GET',
headers: {
Authorization: token,
"Content-Type": "application/json",
Authorization: authToken.value,
},
});
if (!response.ok) throw new Error(`HTTP 錯誤! 狀態碼: ${response.status}`);
const data = await response.json();
company_guid.value = data.guid
company_guid.value = response.guid
} catch (error) {
console.error('企業基礎資料失敗:', error);
}
}
//
const get_all_health_data = async () => {
console.log(company_guid.value)
try {
const response = await $fetch(`${$api_host}/api/Health_detail_table/get_company_all_health-${company_guid.value}`, {
method: 'GET',
headers: {
"Content-Type": "application/json",
Authorization: authToken.value,
},
});
return response;
} catch (error) {
console.error(error);
}
}
//
const healthers = ref([]);
const set_All_Health_data = (data) => {
console.log(data)
healthers.value = data
}
//
onMounted(get_data);
//
// 🚀 mounted token
onMounted(() => {
if (process.client) {
// localStorage token reactive
authToken.value = localStorage.getItem("token_TCM") || "";
}
get_data(); // token 調 API
});
</script>
<style>
/* 簡單美化對話框 */
.dialog-box {

View File

@ -2,25 +2,22 @@
<script setup>
import { useHead } from "#app"; // Head
import { ref } from "vue";
import { onMounted } from "vue"; //
import { useRouter } from "vue-router"; //
import { ref, onMounted } from "vue"; //
import { useRouter } from "vue-router"; //
const { $api_host } = useNuxtApp(); // API host
const router = useRouter(); //
const router = useRouter(); //
definePageMeta({
layout: false, // layout
});
// Head
useHead({
title: "Lamiter",
meta: [
{ charset: "utf-8" },
{ "http-equiv": "X-UA-Compatible", content: "IE=edge" },
{
name: "viewport",
content: "width=device-width, initial-scale=1, shrink-to-fit=no",
},
{ name: "viewport", content: "width=device-width, initial-scale=1, shrink-to-fit=no" },
{ name: "description", content: "" },
{ name: "author", content: "" },
],
@ -28,12 +25,11 @@ useHead({
{
rel: "stylesheet",
href: "https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i",
}, // `styles.css` public/css
},
{ rel: "stylesheet", href: "/css/sb-admin-2.min.css" },
{ rel: "stylesheet", href: "/vendor/fontawesome-free/css/all.min.css" },
],
script: [
//{ src: 'https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js', crossorigin: 'anonymous' },
{ src: "/vendor/jquery/jquery.min.js" },
{ src: "/vendor/bootstrap/js/bootstrap.bundle.min.js" },
{ src: "/vendor/jquery-easing/jquery.easing.min.js" },
@ -41,44 +37,47 @@ useHead({
],
});
console.log($api_host);
var token; //
// 🔐 Token SSR
const authToken = useState("authToken", () => process.client ? localStorage.getItem("token_TCM") || "" : "");
//token
function token_check() {
// JWT
token = localStorage.getItem("token_TCM");
console.log(token);
// token
if (token != null) {
$.ajax({
type: "GET",
url: $api_host + "/Users/token_check_user",
// 🔍 Token
async function token_check() {
if (!process.client) return; // client-side
const token = localStorage.getItem("token_TCM");
console.log("Token:", token);
if (!token) {
console.log("無 Token轉跳首頁");
router.push("/Home_pages/");
return;
}
try {
const response = await fetch(`${$api_host}/Users/token_check_user`, {
method: "GET",
headers: {
Authorization: token,
},
success: function (response) {
// 10 BOSS
if(response.level>=9){
});
if (!response.ok) throw new Error("Token 驗證失敗");
const data = await response.json();
console.log("驗證成功:", data);
if (data.level >= 9) {
router.push("/Lamiter_pages/");
}
// 9
if(response.level==8){
} else if (data.level == 8) {
router.push("/Manage_pages/");
}
},
error: function (xhr) {
console.log("false");
},
});
} else {
console.log("pass");
} catch (error) {
console.error("Token 驗證失敗", error);
router.push("/Home_pages/");
}
}
//
onMounted(() => {
token_check();
});
// 🔄
onMounted(token_check);
</script>