Electromembrane water treatment technologies are attracting attention for their energy efficiency and precise separation of counterions. However, ion-exchange membranes exhibit low ionic conductance and selectivity for ions with similar charges. In this study, we developed a novel ZIF-8 composite membrane with amine-modified nanochannels through an in situ PEI-assisted seeding and secondary growth method. An integral and uniform selective layer was formed, and the amine-modified nanochannels induced differential transport of Li+, Na+, K+, and Mg2+ via the dehydration-hydration process. The composite membrane possessed a lower energy barrier for Na+ transport (Ea = 13 kJ mol-1) compared to Mg2+ (Ea = 17 kJ mol-1), showing a Na+ flux of 3.7 × 10-8 mol·cm-2·s-1 and a Na+/Mg2+ permselectivity of 52 (∼60 times higher than the commercial membrane). The physicochemical and electrochemical properties of the composite membranes were systematically characterized, revealing the significant role of the Mg2+ layer in increasing Mg2+ repulsion and facilitating Na+ diffusion. Besides, DFT simulation and interaction energy calculation elucidated that a moderate binding energy and compensation effect between ions and nanochannels, which can be precisely regulated by PEI incorporation, are crucial for the favorable passage of Na+ while maintaining high Mg2+ rejection. The membrane also demonstrated performance stability during a 5-day test and maintained high selectivity across varying salinity and pH conditions. This work advances the development of efficient cation separation membranes for sustainable desalination and resource recovery.