Skip to content

Commit

Permalink
make all element being component!
Browse files Browse the repository at this point in the history
  • Loading branch information
syzygy608 committed Jul 8, 2024
1 parent 46514fd commit 3263bd8
Show file tree
Hide file tree
Showing 12 changed files with 280 additions and 240 deletions.
2 changes: 2 additions & 0 deletions components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ declare module 'vue' {
Comment: typeof import('./src/components/pages/main/comment.vue')['default']
CommonOption: typeof import('./src/components/common/option/commonOption.vue')['default']
Course_name: typeof import('./src/components/pages/main/serach_modes/course_name.vue')['default']
Course_tab: typeof import('./src/components/pages/main/course_tab.vue')['default']
CourseCard: typeof import('./src/components/pages/main/courseCard.vue')['default']
Custom: typeof import('./src/components/pages/main/serach_modes/custom.vue')['default']
Department: typeof import('./src/components/pages/main/serach_modes/department.vue')['default']
Expand All @@ -22,6 +23,7 @@ declare module 'vue' {
KebabButton: typeof import('./src/components/common/optionButton/kebabButton.vue')['default']
LoadingSpinner: typeof import('./src/components/common/loadingSpinner.vue')['default']
Loginarea: typeof import('./src/components/pages/login/loginarea.vue')['default']
Modal: typeof import('./src/components/pages/main/modal.vue')['default']
Navbar: typeof import('./src/components/layout/navbar.vue')['default']
Notify: typeof import('./src/components/pages/home/notify.vue')['default']
RouterLink: typeof import('vue-router')['RouterLink']
Expand Down
4 changes: 2 additions & 2 deletions src/components/pages/main/classTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,8 @@ async function showsearchclass(event) {
onMounted(() => {
store.dispatch("initAll");
console.log(activeIndex.value);
console.log(TotalCourseData.value[activeIndex.value].classStorage);
// console.log(activeIndex.value);
// console.log(TotalCourseData.value[activeIndex.value].classStorage);
// using env to control <ul> display
let ul = document.getElementById("result");
if (ul != null) {
Expand Down
108 changes: 108 additions & 0 deletions src/components/pages/main/course_tab.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<template>
<div
class="bg-orange-100 rounded-lg px-2 flex py-2 mx-auto md:w-6/12 max-w-[60rem] min-w-[60rem] overflow-auto flex-nowrap">
<div
v-for="(tab, index) in tabs"
:key="index"
@click="setactiveIndex(index)"
@dblclick="activateInputFocus(index)"
:class="[
'tab rounded-lg text-center justify-center py-2 px-4 mx-1 flex max-w-full flex-auto grow-0 min-w-[5rem] w-36',
{
'bg-orange-300': activeIndex === index,
'bg-orange-200': activeIndex !== index,
},
]">
<div class="w-[8rem] text-center" v-if="!tabIsEditing[index]">
{{ show_tab_name(tab.name) }}
</div>
<input
v-else
v-model="tab.name"
@blur="
renameTab(index, tab.name);
tabIsEditing[index] = false;
"
@keyup.enter="$event.target.blur()"
class="bg-transparent !shadow-none w-[8rem] max-w-[90%] text-center border border-transparent focus:outline-none focus:border-white focus:bg-white/60" />
<button
@click.stop="removeTab(index)"
v-if="tabs.length > 1 && activeIndex === index"
class="ml-2 font-bold hover:text-red-700 inline-flex items-center justify-center z-20">
<CloseOutlined />
</button>
</div>
<button
@click="addTab"
class="tab rounded-lg text-center py-2 px-4 bg-orange-200 hover:bg-orange-300 mx-1">
+
</button>
</div>
</template>

<script setup>
import { computed, ref } from "vue";
import store from "@/store";
import { CloseOutlined } from "@ant-design/icons-vue";
const tabs = computed(() => store.state.course.TotalCourseData);
store.dispatch("init_tab_is_editing", tabs.value.length);
const tabIsEditing = computed(
() => store.state.general.tab_is_editing,
);
const addTab = () => {
if (tabs.value.length >= 8) {
alert("最多只能開啟 8 組課表!");
return;
}
store.dispatch("open_main_modal");
};
const show_tab_name = (tab_name) => {
if (tab_name.length > 8) return tab_name.slice(0, 6) + "...";
return tab_name;
};
const activateInputFocus = (index) => {
oldName.value = tabs.value[index].name;
tabIsEditing.value[index] = true;
setTimeout(() => {
let div = document.getElementsByClassName("tab")[index];
let input = div.querySelector("input");
input.select();
input.focus();
}, 10);
};
function renameTab(index, newName) {
console.log("rename");
if (newName === "") {
tabs.value[index].name = oldName.value;
alert("名稱不可為空!");
return;
}
if (tabs.value[index]) {
store.dispatch("renameTabs", {
id: tabs.value[index].id,
name: newName,
});
}
}
const removeTab = (index) => {
if (tabs.value.length === 1) {
alert("至少要保留一組課表!");
return;
}
if (confirm("確定要刪除此課表?") === false) return;
store.dispatch("deleteTabs", tabs.value[index].id);
};
const activeIndex = computed(() => store.state.course.activeIndex);
const setactiveIndex = (index) => {
store.dispatch("setactiveIndex", index);
};
</script>
25 changes: 6 additions & 19 deletions src/components/pages/main/inputArea.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,10 @@
</select>
</div>
<div class="flex flex-col py-1 mx-auto">
<CourseName
v-if="searchType == '以課程名稱搜尋'"
:year="selectedYear"
:sem="selectedSem" />
<Teacher
v-if="searchType == '以教師名稱搜尋'"
:year="selectedYear"
:sem="selectedSem" />
<Department
v-if="searchType == '以系所年級搜尋'"
:year="selectedYear"
:sem="selectedSem" />
<Time
v-if="searchType == '以時間區間搜尋'"
:year="selectedYear"
:sem="selectedSem" />
<CourseName v-if="searchType == '以課程名稱搜尋'" />
<Teacher v-if="searchType == '以教師名稱搜尋'" />
<Department v-if="searchType == '以系所年級搜尋'" />
<Time v-if="searchType == '以時間區間搜尋'" />
<Custom v-if="searchType == '自定義新增課程'" />
</div>
<hr class="mx-3 my-3 text-slate-300" />
Expand Down Expand Up @@ -205,7 +193,6 @@ const selectedSem = ref(null);
watch(searchSem, async (inputValue) => {
selectedYear.value = inputValue.year;
selectedSem.value = inputValue.semester;
console.log(selectedYear.value, selectedSem.value);
store.dispatch("set_yearNsemester", [
selectedYear.value,
selectedSem.value,
Expand Down Expand Up @@ -270,8 +257,8 @@ let opened = computed(() => store.state.course.timeSearchMode);
onMounted(async () => {
semList.value = await searchSemster();
searchSem.value = semList.value[semList.value.length - 1];
console.log(TotalCourseData.value[activeIndex.value]);
console.log(activeIndex.value);
// console.log(TotalCourseData.value[activeIndex.value]);
// console.log(activeIndex.value);
let temp_list = _.cloneDeep(
TotalCourseData.value[activeIndex.value].classListStorage,
);
Expand Down
77 changes: 77 additions & 0 deletions src/components/pages/main/modal.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<template>
<div
class="z-40 top-0 left-0 w-screen h-screen fixed flex items-center backdrop-blur-sm"
v-show="showModal">
<div
id="modal-container"
class="fixed inset-0 flex justify-center h-full md:h-6/12 w-full md:w-7/12 mx-auto"
v-show="showModal">
<div class="bg-white p-8 rounded-3xl shadow-lg my-auto">
<h2 class="text-xl font-semibold mb-4 text-center">
新增課表
</h2>
<hr class="py-2" />
<p class="mb-4">
請問你是要新增一個空白課表還是複製一個現有的課表?
</p>
<div class="mb-4">
<select
v-model="ret"
class="w-full bg-gray-100 py-2 rounded-lg text-center">
<option value="0" selected>新增空白課表</option>
<option
v-for="(tab, index) in tabs"
:key="index"
:value="index + 1">
複製 {{ tab.name }}
</option>
</select>
</div>
<div class="text-center">
<button
id="close-modal"
class="bg-red-300 px-3 py-1 rounded hover:bg-red-400"
@click="closeModal">
取消
</button>
<button
id="add-tab"
class="bg-green-300 px-3 py-1 rounded hover:bg-green-400 ml-2"
@click="SubmitModal">
確認
</button>
</div>
</div>
</div>
</div>
</template>

<script setup>
import { computed, ref } from "vue";
import store from "@/store";
const showModal = computed(() => store.state.general.main_modal_show);
const tabs = computed(() => store.state.course.TotalCourseData);
const closeModal = () => {
store.dispatch("close_main_modal");
};
const ret = ref("0");
const SubmitModal = () => {
if (ret === null) return;
let copy = parseInt(ret.value);
if (copy >= 1 && copy <= tabs.value.length) {
store.dispatch("addTabs", tabs.value[copy - 1].id);
// copy data from copy-th tab here
closeModal();
return;
} else if (copy != 0) {
alert("輸入錯誤!");
return;
}
store.dispatch("addTabs", null);
closeModal();
};
</script>
23 changes: 10 additions & 13 deletions src/components/pages/main/serach_modes/course_name.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,17 @@ let cleanInputArea = function () {
searchInput.value = "";
};
const props = defineProps({
year: Number,
sem: Number,
});
const selectedYear = ref(props.year);
const selectedSemester = ref(props.sem);
const selectedYear = computed(() => store.state.course.selectedYear);
const selectedSemester = computed(
() => store.state.course.selectedSemester,
);
watchEffect(() => {
selectedYear.value = props.year;
selectedSemester.value = props.sem;
isLoading.value = false;
show_search_box.value = false;
searchInput.value = "";
watch([selectedYear, selectedSemester], async ([year, semester]) => {
if (searchInput.value != "") {
show_search_box.value = false;
isLoading.value = true;
searchInput.value = "";
}
});
watch(searchInput, async (inputValue) => {
Expand Down
27 changes: 12 additions & 15 deletions src/components/pages/main/serach_modes/department.vue
Original file line number Diff line number Diff line change
Expand Up @@ -110,22 +110,19 @@ const gradeList = ref();
const courseList = ref([]);
const gradeSelection = ref();
const props = defineProps({
year: Number,
sem: Number,
});
const selectedYear = ref(props.year);
const selectedSemester = ref(props.sem);
const selectedYear = computed(() => store.state.course.selectedYear);
const selectedSemester = computed(
() => store.state.course.selectedSemester,
);
watchEffect(async () => {
selectedYear.value = props.year;
selectedSemester.value = props.sem;
departmentInput.value = "";
departmentList = await getDepartment(
selectedYear.value,
selectedSemester.value,
);
watch([selectedYear, selectedSemester], async ([year, semester]) => {
if (departmentInput.value != "") {
departmentInput.value = "";
departmentList = await getDepartment(
selectedYear.value,
selectedSemester.value,
);
}
});
const filteredClassList = computed(() => {
Expand Down
26 changes: 12 additions & 14 deletions src/components/pages/main/serach_modes/teacher.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,25 +71,23 @@ const show_search_box = ref(false);
const data = ref([]);
const searchList = ref(null);
const props = defineProps({
year: Number,
sem: Number,
});
const selectedYear = ref(props.year);
const selectedSem = ref(props.sem);
let cleanInputArea = function () {
console.log(48763);
show_search_box.value = !show_search_box.value;
searchInput.value = "";
};
watchEffect(() => {
selectedYear.value = props.year;
selectedSem.value = props.sem;
show_search_box.value = false;
cleanInputArea();
const selectedYear = computed(() => store.state.course.selectedYear);
const selectedSemester = computed(
() => store.state.course.selectedSemester,
);
watch([selectedYear, selectedSemester], async ([year, semester]) => {
if (searchInput.value != "") {
show_search_box.value = false;
isLoading.value = true;
searchInput.value = "";
}
});
watch(searchInput, async (inputValue) => {
Expand All @@ -100,7 +98,7 @@ watch(searchInput, async (inputValue) => {
data.value = await searchByTeacher(
inputValue,
selectedYear.value,
selectedSem.value,
selectedSemester.value,
);
data.value = data.value.map((temp) => {
temp["conflict"] = classconflict(temp);
Expand Down
4 changes: 2 additions & 2 deletions src/store/course.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ const store: Module<State, any> = {
console.log("initAll");
let TotalCourseData = localStorage.getItem("TotalCourseData");
// 無資料或者是僅有舊資料
console.log(TotalCourseData);
// console.log(TotalCourseData);
if (TotalCourseData === null) {
console.log("initAll debug");
state.TotalCourseData = OldDataTransfer();
Expand Down Expand Up @@ -340,7 +340,7 @@ const store: Module<State, any> = {
break;
}
}
console.log(state.TotalCourseData);
// console.log(state.TotalCourseData);
}
localStorage.setItem(
"TotalCourseData",
Expand Down
Loading

0 comments on commit 3263bd8

Please sign in to comment.