diff --git a/src/constants/constants.js b/src/constants/constants.js index c37b1dd..8cc2122 100644 --- a/src/constants/constants.js +++ b/src/constants/constants.js @@ -1,5 +1,5 @@ export const PRIME_VUE_TICKS_LIMIT = 6; -export const ONCE_RENDER_NUM_OF_DATA = 6; +export const ONCE_RENDER_NUM_OF_DATA = 9; export const GRID_COLOR = '#64748b'; diff --git a/src/stores/acctMgmt.js b/src/stores/acctMgmt.js index 68ec17a..7e87799 100644 --- a/src/stores/acctMgmt.js +++ b/src/stores/acctMgmt.js @@ -69,6 +69,28 @@ export default defineStore('acctMgmtStore', { isEditHovered: false, })); }, + /** + * Create new user in database. + * @param {object} userToCreate + * userToCreate { + * "username": "string", + * "password": "string", + * "name": "string", + * "is_admin": boolean, + * "is_active": boolean, + * } + */ + async createNewAccount(userToCreate) { + const apiCreateAccount = `/api/users`; + + try{ + const response = await this.$axios.post(apiCreateAccount, userToCreate); + console.log('TODO: response:', response, response.status); + } + catch(error) { + apiError(error, 'Failed to add a new account'); + }; + }, /** * According to mouseover or mouseleave status, change the bool value. * @param {string} username diff --git a/src/views/AccountManagement/AccountAdmin/index.vue b/src/views/AccountManagement/AccountAdmin/index.vue index eb8448b..e47461b 100644 --- a/src/views/AccountManagement/AccountAdmin/index.vue +++ b/src/views/AccountManagement/AccountAdmin/index.vue @@ -123,7 +123,7 @@ import { import iconDetailOn from '@/assets/icon-detail-on.svg'; import iconDetailOff from '@/assets/icon-detail-card.svg'; - +// 這是製作假資料,在正式環境不會用到 function repeatAccountList(accountList, N) { const repeatedList = []; @@ -143,7 +143,7 @@ function repeatAccountList(accountList, N) { const repeatedAccountList = repeatAccountList(accountList, 20); export default { - setup(props) { + setup() { const acctMgmtStore = useAcctMgmtStore(); const loadingStore = LoadingStore(); const modalStore = useModalStore(); @@ -182,6 +182,8 @@ export default { internalInfiniteAcctData.value = allUserAccoutList.value.slice(0, ONCE_RENDER_NUM_OF_DATA) }; + const isInfiniteFinish = ref(true); + const handleDeleteMouseOver = (username) => { acctMgmtStore.changeIsDeleteHoveredByUser(username, true); }; @@ -229,12 +231,39 @@ export default { moveCurrentLoginUserToFirstRow(); }); + /** + * 無限滾動: 監聽 scroll 有沒有滾到底部 + * @param {element} event 滾動傳入的事件 + */ + const handleScroll = (event) => { + if(internalInfiniteAcctData.value.length < ONCE_RENDER_NUM_OF_DATA || isInfiniteFinish.value === false) { + return; + } + + const container = event.target; + const smallValue = 4; + + const overScrollHeight = container.scrollTop + container.clientHeight >= container.scrollHeight - smallValue; + + if(overScrollHeight){ + fetchMoreDataVue3(); + } + }; + + const fetchMoreDataVue3 = () => { + infiniteStart.value += ONCE_RENDER_NUM_OF_DATA; + internalInfiniteAcctData.value = [internalInfiniteAcctData.value, acctMgmtStore.allUserAccoutList.slice( + infiniteStart.value, this.infiniteStart + ONCE_RENDER_NUM_OF_DATA)]; + isInfiniteFinish.value = true; + }; + return { isLoading, modalStore, loginUserData, internalInfiniteAcctData, onCreateNewClick, + handleScroll, getRowClass, onDeleteBtnClick, handleDeleteMouseOver, @@ -276,11 +305,12 @@ export default { onAdminRightsBtnClick(isOn){ }, + /** * 無限滾動: 監聽 scroll 有沒有滾到底部 * @param {element} event 滾動傳入的事件 */ - handleScroll(event) { + handleScrollVue2(event) { if(this.infinitMaxItems || this.infiniteAcctData.length < ONCE_RENDER_NUM_OF_DATA || this.isInfiniteFinish === false) { return; } @@ -291,13 +321,13 @@ export default { const overScrollHeight = container.scrollTop + container.clientHeight >= container.scrollHeight - smallValue; if(overScrollHeight){ - this.fetchMoreData(); + this.fetchMoreDataVue2(); } }, /** * 無限滾動: 滾到底後,要載入數據 */ - async fetchMoreData() { + async fetchMoreDataVue2() { this.isLoading = true; this.infiniteFinish = false; this.infiniteStart += ONCE_RENDER_NUM_OF_DATA; diff --git a/src/views/AccountManagement/ModalAccountEdit.vue b/src/views/AccountManagement/ModalAccountEdit.vue index 580c8ce..84e181b 100644 --- a/src/views/AccountManagement/ModalAccountEdit.vue +++ b/src/views/AccountManagement/ModalAccountEdit.vue @@ -13,7 +13,7 @@ + v-model="inputUserAccount"/>
@@ -23,7 +23,7 @@
+ v-model="inputName"/>
@@ -115,7 +115,7 @@