摘要:愈發(fā)純熟的業(yè)務(wù)代碼開(kāi)始做菜原文地址背景需求分析背景某日,被后臺(tái)拿著一個(gè)別人實(shí)現(xiàn)好的管理系統(tǒng)說(shuō)道了一頓,說(shuō)需要實(shí)現(xiàn)得比某框架更好地址需求分析需求管理系統(tǒng)內(nèi)實(shí)現(xiàn)瀏覽器標(biāo)簽的功能分析切換不主動(dòng)更新頁(yè)面重點(diǎn)關(guān)閉活動(dòng)中的切換至后一個(gè)若關(guān)閉為最后一個(gè),
愈發(fā)純熟的業(yè)務(wù)代碼——開(kāi)始做菜
原文地址
1.背景 && 需求分析 1.1 背景某日,被后臺(tái)拿著一個(gè)別人實(shí)現(xiàn)好的管理系統(tǒng)說(shuō)道了一頓,說(shuō)需要實(shí)現(xiàn)得比某框架更好
地址:pig4cloud
1.2 需求分析需求:管理系統(tǒng)內(nèi)實(shí)現(xiàn)瀏覽器 Tag 標(biāo)簽的功能
分析:
切換 Tag 不主動(dòng)更新頁(yè)面(重點(diǎn))
關(guān)閉活動(dòng)中的 Tag 切換至后一個(gè)
若關(guān)閉 Tag 為最后一個(gè),切換至前一個(gè)
2. 實(shí)現(xiàn)邏輯技術(shù)棧:react + react-router + react-redux + react-saga
重點(diǎn):組件更新,頁(yè)面不變
上 demo :
2.1 內(nèi)存邏輯思路:卻分活動(dòng)狀態(tài)內(nèi)的存,和在打開(kāi)過(guò)的內(nèi)存,兩個(gè)內(nèi)存同事更新,切換 Tag 從打開(kāi)過(guò)的數(shù)組內(nèi)調(diào)取數(shù)據(jù),有數(shù)據(jù)使用該數(shù)據(jù),無(wú)數(shù)據(jù)則發(fā)起請(qǐng)求
tagList 側(cè)欄點(diǎn)擊過(guò)的 Tag 數(shù)組
activeTag 活動(dòng)狀態(tài)的 Tag
操作同歸在 Reduce 內(nèi),方便后續(xù) Tag 內(nèi)外部交互
/*. 目錄:/src/store/index.js */ const appReducer ={ tabListStatus: (state = { tabList: [], activeTab: null }, action) => { switch (action.type) { case "tabListChange": // case "tabListAdd": // case "tabListRemove": // case "tabListClear": // default: return state } }, // ... }
所有內(nèi)存初始狀態(tài),都在 App.js->componentDidUpdate 生命周期內(nèi)存操作
/* 目錄:/src/App.js */ componentDidUpdate(prevProps, prevState) { if (this.props.tabListStatus !== prevProps.tabListStatus) { const { tabList, activeTab } = this.props.tabListStatus sessionStorage.setItem("tabList", JSON.stringify(tabList)) sessionStorage.setItem("activeTab", JSON.stringify(activeTab)) this.setState({ tabList, activeTab: activeTab !== null ? activeTab.key : "/" }) } }2.2 外部交互邏輯
側(cè)欄邏輯,新增
點(diǎn)擊邏輯,切換 Tag
關(guān)閉 Tag
class App extends Component { // 點(diǎn)擊側(cè)欄 handleOnMenuItem = param => { const { tabListAdd, tabListStatus } = this.props const { tabList } = tabListStatus const userMenu = menuDataSource const menu = this.menuItemFilter(userMenu, `/nav_${param.key}`) let paramTab = { title: menu.name, key: menu.path, queryParam: {}, dataSource: {} } //判斷是否為新增 let pushBol = true tabList.map(tab => { if (tab.key === paramTab.key) { pushBol = false paramTab = Object.assign({},paramTab,tab) } return tab }) if (pushBol) { tabList.push(paramTab) } tabListAdd({ tabList, activeTab: paramTab }) this.toPath(`nav_${param.key}`) } // 點(diǎn)擊 Tag onChange = activeKey => { // console.log("....", activeKey) const { tabListStatus, tabListAdd } = this.props const { tabList } = tabListStatus const userMenu = tabList const menu = this.menuChangeFilter(userMenu, activeKey) const paramTab = { ...menu } tabListAdd({ tabList, activeTab: paramTab }) this.toPath(activeKey) } // 關(guān)閉邏輯 remove = targetKey => { let activeKey = this.state.activeTab let panes = this.state.tabList let lastIndex panes.forEach((pane, i) => { if (pane.key === targetKey) { lastIndex = panes.length - 1 === i ? i - 1 : i } }) const panesFilter = panes.filter(pane => pane.key !== targetKey) if (panesFilter.length && activeKey === targetKey) { if (lastIndex >= 0) { activeKey = panesFilter[lastIndex] } else { activeKey = panesFilter[0] } } else { activeKey = null } this.props.tabListAdd({ tabList: panesFilter, activeTab: activeKey }) this.toPath(activeKey !== null ? activeKey.key : "/") } // ... }2.3 內(nèi)部交互邏輯
判斷是否新增
操作更新 onChange, onClear, onSubmit
使用標(biāo)記符號(hào),或者直接判斷一個(gè) key 值是否存在值,來(lái)發(fā)送請(qǐng)求,demo 內(nèi)使用 dataSource 是否存在為空來(lái)判斷是否需要發(fā)送請(qǐng)求
componentDidMount() { const { tabListStatus, musicList_query_param, musicList } = this.props const { dataSource } = tabListStatus.activeTab if (!Object.keys(dataSource).length) { musicList(musicList_query_param) } }
操作更新 onChange, onClear, onSubmit 除了這一些以外還會(huì)存在不同的操作,demo 大致分了這幾個(gè)操作,均使用 reducer 操作,App.js 內(nèi)監(jiān)聽(tīng)操作,更改內(nèi)存,模塊內(nèi)不參與內(nèi)存更改
onChange = (tabList, e) => { e.persist() if (!e || !e.target) { return } const { target } = e const operateParam = operateQuery(tabList, { [target.id]: target.type === "checkbox" ? target.checked : target.value }) this.props.tabListChange(operateParam) }3. 對(duì)比 3.1 Vue 的實(shí)現(xiàn)
技術(shù)棧:vue + vue-router + vuex
UI 框架:ant-design
關(guān)鍵:keep-alive
3.2 React 的實(shí)現(xiàn)技術(shù)棧:react + react-router + redux
UI 框架:ant-design
關(guān)鍵:redux 與內(nèi)存處理
4. 總結(jié)實(shí)現(xiàn)上面肯定是 Vue 更快實(shí)現(xiàn)的,但對(duì)使用 React 內(nèi)存的控制也是一件非常好玩的事情,如果項(xiàng)目大了,就更好玩了
實(shí)際上這種實(shí)現(xiàn)有點(diǎn)雞肋,因?yàn)橛脩粢粋€(gè)不留意,關(guān)了頁(yè)面,這些 Tag 就不存在了,無(wú)論是那種管理系統(tǒng),這個(gè)實(shí)現(xiàn)如果配合到后臺(tái),可能就更好玩了
感謝 @白白,感謝 @同事,都提供了很不錯(cuò)的思路
感謝閱讀,代碼很爛,請(qǐng)輕噴
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/106544.html
摘要:的展示非常炫酷,絕對(duì)是運(yùn)維提升逼格的一大利器。另外的可視化功能比強(qiáng)得多,而且以上版本將集成報(bào)警功能。它由寫(xiě)成,著力于高性能地查詢與存儲(chǔ)時(shí)序型數(shù)據(jù)。被廣泛應(yīng)用于存儲(chǔ)系統(tǒng)的監(jiān)控?cái)?shù)據(jù),行業(yè)的實(shí)時(shí)數(shù)據(jù)等場(chǎng)景。 原有監(jiān)控系統(tǒng) showImg(https://segmentfault.com/img/remote/1460000011082384); 整個(gè)系統(tǒng)以 Graphite (carbon ...
摘要:而今,我們就已經(jīng)實(shí)現(xiàn)了這樣的功能使用標(biāo)簽來(lái)實(shí)現(xiàn)數(shù)據(jù)的聚合和分組。數(shù)據(jù)聚合和分組在中,我們實(shí)現(xiàn)了數(shù)據(jù)的聚合和分組。指所需聚合的的查詢條件。所以,與會(huì)聚合為一條曲線,而和的關(guān)系是分組的關(guān)系。 遙想 2015 年 8 月 17 日,Cloud Insight 還在梳理功能原型,暢想 Cloud Insight 存在的意義:為什么阿里云用戶需要使用 Cloud Insight 來(lái)加強(qiáng)管理。 而...
摘要:目前此系統(tǒng)僅支持類系統(tǒng)下使用,不支持系統(tǒng)什么是這是一個(gè)獲取各種系統(tǒng)的監(jiān)控?cái)?shù)據(jù)的。監(jiān)控?cái)?shù)據(jù)上報(bào)公有的跟官方社區(qū)的思想一致采集的系統(tǒng)監(jiān)控信息如內(nèi)存等等一百多種沒(méi)有任何信息其他的業(yè)務(wù)系統(tǒng)的監(jiān)控都會(huì)打上。 OpenFalcon-SuitAgent 項(xiàng)目地址:github 版本說(shuō)明 本系統(tǒng)版本劃分如下 alpha:內(nèi)部測(cè)試版(不建議使用于生產(chǎn)環(huán)境) beta:公開(kāi)測(cè)試版(不建議使用于生產(chǎn)環(huán)境)...
摘要:目前此系統(tǒng)僅支持類系統(tǒng)下使用,不支持系統(tǒng)什么是這是一個(gè)獲取各種系統(tǒng)的監(jiān)控?cái)?shù)據(jù)的。監(jiān)控?cái)?shù)據(jù)上報(bào)公有的跟官方社區(qū)的思想一致采集的系統(tǒng)監(jiān)控信息如內(nèi)存等等一百多種沒(méi)有任何信息其他的業(yè)務(wù)系統(tǒng)的監(jiān)控都會(huì)打上。 OpenFalcon-SuitAgent 項(xiàng)目地址:github 版本說(shuō)明 本系統(tǒng)版本劃分如下 alpha:內(nèi)部測(cè)試版(不建議使用于生產(chǎn)環(huán)境) beta:公開(kāi)測(cè)試版(不建議使用于生產(chǎn)環(huán)境)...
閱讀 3260·2021-10-13 09:40
閱讀 3779·2019-08-30 15:54
閱讀 1343·2019-08-30 13:20
閱讀 3025·2019-08-30 11:26
閱讀 508·2019-08-29 11:33
閱讀 1125·2019-08-26 14:00
閱讀 2390·2019-08-26 13:58
閱讀 3400·2019-08-26 10:39