建立健管師新增
This commit is contained in:
parent
3c6e478575
commit
f134fe3541
@ -84,7 +84,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { useHead } from "#app";
|
import { useHead,useState } from "#app";
|
||||||
import { ref } from "vue";
|
import { ref } from "vue";
|
||||||
import { useRouter } from "vue-router"; //匯入路徑
|
import { useRouter } from "vue-router"; //匯入路徑
|
||||||
const { $api_host } = useNuxtApp(); //匯入API host
|
const { $api_host } = useNuxtApp(); //匯入API host
|
||||||
@ -127,38 +127,39 @@ const email = ref("");
|
|||||||
const password = ref("");
|
const password = ref("");
|
||||||
|
|
||||||
// 提交登入資料
|
// 提交登入資料
|
||||||
|
const authToken = useState("authToken", () => process.client ? localStorage.getItem("token_TCM") || "" : "");
|
||||||
|
|
||||||
async function login_in() {
|
async function login_in() {
|
||||||
if (!email.value || !password.value) {
|
if (!email.value || !password.value) {
|
||||||
alert("請輸入帳號和密碼");
|
alert("請輸入帳號和密碼");
|
||||||
return;
|
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 obj = { Username: email.value, Password: password.value };
|
||||||
const data = await response.json();
|
|
||||||
console.log("成功:", data);
|
try {
|
||||||
var token_str = data.token;
|
const response = await fetch(`${$api_host}/Users/authenticate`, {
|
||||||
localStorage.setItem('token_TCM', token_str);
|
method: "POST",
|
||||||
router.push("/");
|
headers: { "Content-Type": "application/json" },
|
||||||
// 根據 data 處理登入成功邏輯
|
body: JSON.stringify(obj),
|
||||||
} else {
|
});
|
||||||
console.error("登入失敗");
|
|
||||||
alert("帳號、密碼 錯誤");
|
if (response.ok) {
|
||||||
|
const data = await response.json();
|
||||||
|
console.log("成功:", data);
|
||||||
|
|
||||||
|
if (process.client) {
|
||||||
|
localStorage.setItem("token_TCM", data.token);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
authToken.value = data.token; // 更新狀態
|
||||||
alert("伺服器有誤");
|
router.push("/");
|
||||||
|
} else {
|
||||||
|
console.error("登入失敗");
|
||||||
|
alert("帳號、密碼 錯誤");
|
||||||
}
|
}
|
||||||
} else {
|
} catch (error) {
|
||||||
alert("帳號、密碼 錯誤");
|
alert("伺服器有誤");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
@ -95,7 +95,7 @@ const get_data = async () => {
|
|||||||
if (!response.ok) throw new Error(`HTTP 錯誤! 狀態碼: ${response.status}`);
|
if (!response.ok) throw new Error(`HTTP 錯誤! 狀態碼: ${response.status}`);
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
company_name.value=data.campant_name
|
company_name.value=data.company_name
|
||||||
|
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
<div class="text-xs font-weight-bold text-primary text-uppercase mb-1">
|
<div class="text-xs font-weight-bold text-primary text-uppercase mb-1">
|
||||||
企業名稱:
|
企業名稱:
|
||||||
</div>
|
</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>
|
||||||
<div class="col-auto">
|
<div class="col-auto">
|
||||||
<i class="fas fa-building fa-2x text-gray-300"></i> <!-- 改為企業圖標 -->
|
<i class="fas fa-building fa-2x text-gray-300"></i> <!-- 改為企業圖標 -->
|
||||||
@ -131,7 +131,7 @@ async function submitCompany() {
|
|||||||
const companies = ref([]);
|
const companies = ref([]);
|
||||||
const get_data = async () => {
|
const get_data = async () => {
|
||||||
try {
|
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}`);
|
if (!response.ok) throw new Error(`HTTP 錯誤! 狀態碼: ${response.status}`);
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
@ -5,18 +5,18 @@
|
|||||||
</button>
|
</button>
|
||||||
<br /><br />
|
<br /><br />
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div v-for="company in companies" :key="company.guid" class="col-xl-3 col-md-6 mb-4">
|
<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_company(company.guid)">
|
<div class="card border-left-primary shadow h-100 py-2" @click="edit_health(health.guid)">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<div class="row no-gutters align-items-center">
|
<div class="row no-gutters align-items-center">
|
||||||
<div class="col mr-2">
|
<div class="col mr-2">
|
||||||
<div class="text-xs font-weight-bold text-primary text-uppercase mb-1">
|
<div class="text-xs font-weight-bold text-primary text-uppercase mb-1">
|
||||||
企業名稱:
|
健管師名稱:
|
||||||
</div>
|
</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>
|
||||||
<div class="col-auto">
|
<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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -27,37 +27,35 @@
|
|||||||
|
|
||||||
<!--新增管理師-彈跳視窗-->
|
<!--新增管理師-彈跳視窗-->
|
||||||
<div>
|
<div>
|
||||||
<dialog ref="add_Company_view" class="dialog-box">
|
<dialog ref="add_Health_view" class="dialog-box">
|
||||||
<div><button class="btn btn-danger" style="float:right" @click="close_add_Company_view">關閉</button>
|
<div><button class="btn btn-danger" style="float:right" @click="close_add_Health_view">關閉</button>
|
||||||
<h2>新增管理師</h2>
|
<h2>新增管理師</h2>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 表單內容 -->
|
<!-- 表單內容 -->
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="companyName">企業名稱:</label>
|
<label for="healthName">健康管理師名稱:</label>
|
||||||
<input id="companyName" v-model="companyName" type="text" class="form-control" placeholder="請輸入企業名稱">
|
<input v-model="healthName" type="text" class="form-control" placeholder="請輸入健管師名稱">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="companyPhone">聯絡電話:</label>
|
<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>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="companyPhone">預設帳號:</label>
|
<label for="healthPhone">預設帳號:</label>
|
||||||
<input id="companyPhone" v-model="companyaccount" type="text" class="form-control"
|
<input v-model="healthaccount" type="text" class="form-control" placeholder="請輸入預設帳號">
|
||||||
placeholder="請輸入預設帳號">
|
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="companyPhone">預設密碼:</label>
|
<label for="healthPhone">預設密碼:</label>
|
||||||
<input id="companyPhone" v-model="companypassword" type="text" class="form-control"
|
<input v-model="healthpassword" type="text" class="form-control" placeholder="請輸入預設密碼">
|
||||||
placeholder="請輸入預設密碼">
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 操作按鈕 -->
|
<!-- 操作按鈕 -->
|
||||||
<div class="button-group">
|
<div class="button-group">
|
||||||
<button class="btn btn-success" @click="submitCompany">確認</button>
|
<button class="btn btn-success" @click="submitHealth">確認</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</dialog>
|
</dialog>
|
||||||
@ -70,22 +68,96 @@ import { ref, onMounted } from 'vue'
|
|||||||
import { useRouter } from "vue-router"; //匯入路徑
|
import { useRouter } from "vue-router"; //匯入路徑
|
||||||
const { $api_host } = useNuxtApp(); //匯入API host
|
const { $api_host } = useNuxtApp(); //匯入API host
|
||||||
const router = useRouter(); // 匯入
|
const router = useRouter(); // 匯入
|
||||||
const add_Company_view = ref(null);
|
const add_Health_view = ref(null);
|
||||||
|
|
||||||
definePageMeta({
|
definePageMeta({
|
||||||
layout: 'defaultmanager' // 指定自定義的佈局名稱
|
layout: 'defaultmanager' // 指定自定義的佈局名稱
|
||||||
})
|
})
|
||||||
|
|
||||||
//新增企業
|
//新增健管師
|
||||||
async function add_health_manager() {
|
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() {
|
function close_add_Health_view() {
|
||||||
add_Company_view.value?.close();
|
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>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user