建立健管師新增

This commit is contained in:
威勝 張 2025-02-20 21:27:24 +08:00
parent 3c6e478575
commit f134fe3541
4 changed files with 124 additions and 51 deletions

View File

@ -84,7 +84,7 @@
</template>
<script setup>
import { useHead } from "#app";
import { useHead,useState } from "#app";
import { ref } from "vue";
import { useRouter } from "vue-router"; //
const { $api_host } = useNuxtApp(); //API host
@ -127,38 +127,39 @@ const email = ref("");
const password = ref("");
//
const authToken = useState("authToken", () => process.client ? localStorage.getItem("token_TCM") || "" : "");
async function login_in() {
if (!email.value || !password.value) {
alert("請輸入帳號和密碼");
return;
}
if (email.value) {
const obj = { Username: email.value, Password: password.value };
try {
const response = await fetch(`${$api_host}/Users/authenticate`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(obj),
});
if (response.ok) {
const data = await response.json();
console.log("成功:", data);
var token_str = data.token;
localStorage.setItem('token_TCM', token_str);
router.push("/");
// data
} else {
console.error("登入失敗");
alert("帳號、密碼 錯誤");
const obj = { Username: email.value, Password: password.value };
try {
const response = await fetch(`${$api_host}/Users/authenticate`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(obj),
});
if (response.ok) {
const data = await response.json();
console.log("成功:", data);
if (process.client) {
localStorage.setItem("token_TCM", data.token);
}
} catch (error) {
alert("伺服器有誤");
authToken.value = data.token; //
router.push("/");
} else {
console.error("登入失敗");
alert("帳號、密碼 錯誤");
}
} else {
alert("帳號、密碼 錯誤");
} catch (error) {
alert("伺服器有誤");
}
}
</script>

View File

@ -95,7 +95,7 @@ const get_data = async () => {
if (!response.ok) throw new Error(`HTTP 錯誤! 狀態碼: ${response.status}`);
const data = await response.json();
company_name.value=data.campant_name
company_name.value=data.company_name
} catch (error) {

View File

@ -15,7 +15,7 @@
<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">{{ company.campant_name }}</div>
<div class="h5 mb-0 font-weight-bold text-gray-800">{{ company.company_name }}</div>
</div>
<div class="col-auto">
<i class="fas fa-building fa-2x text-gray-300"></i> <!-- 改為企業圖標 -->
@ -131,7 +131,7 @@ async function submitCompany() {
const companies = ref([]);
const get_data = async () => {
try {
const response = await fetch('http://localhost:5291/api/Company_detail_table/get_all_campany');
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();

View File

@ -5,18 +5,18 @@
</button>
<br /><br />
<div class="row">
<div v-for="company in companies" :key="company.guid" class="col-xl-3 col-md-6 mb-4">
<div class="card border-left-primary shadow h-100 py-2" @click="edit_company(company.guid)">
<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 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">{{ company.campant_name }}</div>
<div class="h5 mb-0 font-weight-bold text-gray-800">{{ health.health_name }}</div>
</div>
<div class="col-auto">
<i class="fas fa-building fa-2x text-gray-300"></i> <!-- 改為企業圖標 -->
<i class="fas fa-user-tie fa-2x text-gray-300"></i> <!-- 改為圖標 -->
</div>
</div>
</div>
@ -27,37 +27,35 @@
<!--新增管理師-彈跳視窗-->
<div>
<dialog ref="add_Company_view" class="dialog-box">
<div><button class="btn btn-danger" style="float:right" @click="close_add_Company_view">關閉</button>
<dialog ref="add_Health_view" class="dialog-box">
<div><button class="btn btn-danger" style="float:right" @click="close_add_Health_view">關閉</button>
<h2>新增管理師</h2>
</div>
<!-- 表單內容 -->
<div class="form-group">
<label for="companyName">企業名稱</label>
<input id="companyName" v-model="companyName" type="text" class="form-control" placeholder="請輸入企業名稱">
<label for="healthName">健康管理師名稱</label>
<input v-model="healthName" type="text" class="form-control" placeholder="請輸入健管師名稱">
</div>
<div class="form-group">
<label for="companyPhone">聯絡電話</label>
<input id="companyPhone" v-model="companyPhone" type="tel" class="form-control" placeholder="請輸入聯絡電話">
<input v-model="healthPhone" type="tel" class="form-control" placeholder="請輸入聯絡電話">
</div>
<div class="form-group">
<label for="companyPhone">預設帳號</label>
<input id="companyPhone" v-model="companyaccount" type="text" class="form-control"
placeholder="請輸入預設帳號">
<label for="healthPhone">預設帳號</label>
<input v-model="healthaccount" type="text" class="form-control" placeholder="請輸入預設帳號">
</div>
<div class="form-group">
<label for="companyPhone">預設密碼</label>
<input id="companyPhone" v-model="companypassword" type="text" class="form-control"
placeholder="請輸入預設密碼">
<label for="healthPhone">預設密碼</label>
<input v-model="healthpassword" type="text" class="form-control" placeholder="請輸入預設密碼">
</div>
<!-- 操作按鈕 -->
<div class="button-group">
<button class="btn btn-success" @click="submitCompany">確認</button>
<button class="btn btn-success" @click="submitHealth">確認</button>
</div>
</dialog>
@ -70,22 +68,96 @@ import { ref, onMounted } from 'vue'
import { useRouter } from "vue-router"; //
const { $api_host } = useNuxtApp(); //API host
const router = useRouter(); //
const add_Company_view = ref(null);
const add_Health_view = ref(null);
definePageMeta({
layout: 'defaultmanager' //
})
//
//
async function add_health_manager() {
add_Company_view.value?.showModal();
healthName.value = "";
healthPhone.value = "";
healthaccount.value = "";
healthpassword.value = "";
add_Health_view.value?.showModal();
}
// <->
function close_add_Company_view() {
add_Company_view.value?.close();
// <->
function close_add_Health_view() {
add_Health_view.value?.close();
}
//
const healthName = ref("");
const healthPhone = ref("");
const healthaccount = ref("");
const healthpassword = ref("");
async function submitCompany() {
try {
const healthData = {
lastname: companyName.value,
username: companyaccount.value,
password: companypassword.value
};
console.log(companyData)
const response = await fetch(`${$api_host}/api/Company_detail_table/Add_campany`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(companyData)
});
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
add_Company_view.value?.close();
alert('上傳成功!');
get_data();
} catch (error) {
alert('上傳失敗,請檢查後端!');
}
}
const company_guid = ref ("")
//
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()
}
//
const get_company_basic_data = async () => {
try {
const response = await fetch(`${$api_host}/Users/token_check_user`, {
headers: {
Authorization: token,
},
});
if (!response.ok) throw new Error(`HTTP 錯誤! 狀態碼: ${response.status}`);
const data = await response.json();
company_guid.value = data.guid
} catch (error) {
console.error('企業基礎資料失敗:', error);
}
}
//
const get_all_health_data = async()=>{
console.log(company_guid.value)
}
//
onMounted(get_data);
</script>