index.tsx 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. import {
  2. defineComponent,
  3. onBeforeUnmount,
  4. reactive,
  5. ref,
  6. onMounted
  7. } from 'vue';
  8. import loginStyles from './images/login_styles.png';
  9. import loginLeft from './images/login-left.png';
  10. import loginRight from './images/loginright.png';
  11. import colLogo from './images/colLogo.png';
  12. import CodeLogin from './components/codeLogin';
  13. import PwdLogin from './components/pwdLogin';
  14. import {
  15. NTabs,
  16. NTabPane,
  17. useDialog,
  18. NModal,
  19. NButton,
  20. NSpace,
  21. NAlert,
  22. NImage
  23. } from 'naive-ui';
  24. import styles from './index.module.less';
  25. import ForgotPassword from './components/forgotPassword';
  26. import moveTop from './images/moveTopBg.png';
  27. import dingPng from './images/ding.png';
  28. import closeAble from './images/closeAble.png';
  29. import infoIcon from './images/infoIcon.png';
  30. import { state } from '/src/state';
  31. export default defineComponent({
  32. name: 'login-page',
  33. setup() {
  34. const isForgot = ref(false);
  35. const NavsValue = ref('pwdLogin');
  36. const pwdLoginRef = ref();
  37. const forgotPasswordRef = ref();
  38. const popEvent = ref();
  39. const dialog = useDialog();
  40. const showModalMask = ref(false);
  41. const checkInstall = async (event: any) => {
  42. event.preventDefault();
  43. console.log('checkInstall', event);
  44. popEvent.value = event;
  45. console.log('beforeoutcome');
  46. // const { outcome } = await event.userChoice;
  47. // console.log(outcome, 'outcome')
  48. // setTimeout(async function () {
  49. // try {
  50. // const { outcome } = await event.userChoice;
  51. // console.log(outcome, 'outcome')
  52. // } catch (e) {
  53. // console.log(e)
  54. // }
  55. // }, 2000)
  56. if (window.matchMedia('(display-mode: standalone)').matches) {
  57. state.application = window.matchMedia(
  58. '(display-mode: standalone)'
  59. ).matches;
  60. } else {
  61. console.log(popEvent.value, 'popEvent.value');
  62. if (popEvent.value) {
  63. showModalMask.value = true;
  64. setTimeout(() => {
  65. const btn = document.querySelector('#submitBtn');
  66. console.log(btn);
  67. if (btn) {
  68. btn.addEventListener('click', () => {
  69. showModalMask.value = false;
  70. if (!popEvent.value) {
  71. return;
  72. }
  73. popEvent.value.prompt();
  74. popEvent.value.userChoice.then((choiceResult: any) => {
  75. if (choiceResult.outcome === 'accepted') {
  76. console.log('用户已同意添加到桌面');
  77. showModalMask.value = false;
  78. } else {
  79. console.log('用户已取消添加到桌面');
  80. showModalMask.value = false;
  81. }
  82. });
  83. });
  84. }
  85. }, 500);
  86. }
  87. }
  88. };
  89. window.addEventListener('beforeinstallprompt', checkInstall, {
  90. once: true
  91. });
  92. onBeforeUnmount(() => {
  93. window.removeEventListener('beforeinstallprompt', checkInstall);
  94. });
  95. onMounted(async () => {
  96. // const relatedApps = await navigator?.getInstalledRelatedApps();
  97. //
  98. });
  99. const downChrome = () => {
  100. const agent = navigator.userAgent.toLowerCase();
  101. const isMac = (function () {
  102. return /macintosh|mac os x/i.test(navigator.userAgent);
  103. })();
  104. if (agent.indexOf('win32') >= 0 || agent.indexOf('wow32') >= 0) {
  105. window.open(
  106. 'https://appstore.ks3-cn-beijing.ksyuncs.com/ChromeStandaloneSetup32.exe'
  107. );
  108. }
  109. if (agent.indexOf('win64') >= 0 || agent.indexOf('wow64') >= 0) {
  110. window.open(
  111. 'https://appstore.ks3-cn-beijing.ksyuncs.com/ChromeStandaloneSetup64.exe'
  112. );
  113. }
  114. if (isMac) {
  115. window.open(
  116. 'https://appstore.ks3-cn-beijing.ksyuncs.com/googlechrome-mac.dmg'
  117. );
  118. }
  119. };
  120. return () => (
  121. <div class={styles['view-account']}>
  122. <div class={styles['view-account-container']}>
  123. <img src={loginLeft} class={styles.loginLeft} alt="" />
  124. <img src={loginRight} class={styles.loginRight} alt="" />
  125. <div class={styles['stylesWrap']}>
  126. <img src={loginStyles} alt="" />
  127. </div>
  128. </div>
  129. <div class={styles['view-account-form']}>
  130. <img class={styles.colLogo} src={colLogo}></img>
  131. {isForgot.value ? (
  132. <NTabs
  133. key="forgotPassword"
  134. default-value={NavsValue.value}
  135. class={[styles.loginTabs, styles.loginForgot]}
  136. ref={forgotPasswordRef}
  137. justify-content="center">
  138. <NTabPane name="forgotPassword" tab="重置密码">
  139. <ForgotPassword
  140. onChangType={() => {
  141. isForgot.value = false;
  142. NavsValue.value = 'pwdLogin';
  143. // pwdLoginRef.value.syncBarPosition();
  144. }}></ForgotPassword>
  145. </NTabPane>
  146. </NTabs>
  147. ) : (
  148. <NTabs
  149. key="pwdLogin"
  150. ref={pwdLoginRef}
  151. default-value={NavsValue.value}
  152. class={[styles.loginTabs]}
  153. justify-content="center">
  154. <NTabPane name="pwdLogin" tab="密码登录">
  155. <PwdLogin
  156. onChangType={() => {
  157. isForgot.value = true;
  158. NavsValue.value = 'forgotPassword';
  159. // forgotPasswordRef.value.syncBarPosition();
  160. }}></PwdLogin>
  161. </NTabPane>
  162. <NTabPane name="codeLogin" tab="短信验证">
  163. <CodeLogin></CodeLogin>
  164. </NTabPane>
  165. </NTabs>
  166. )}
  167. <div class={styles.alertWrap}>
  168. <div class={styles.alertInfo}>
  169. <NImage
  170. src={infoIcon}
  171. class={styles.infoIcon}
  172. previewDisabled></NImage>
  173. 为了您更好的上课体验,推荐使用Chrome浏览器
  174. </div>
  175. <div class={styles.down} onClick={downChrome}>
  176. 立即下载
  177. </div>
  178. </div>
  179. </div>
  180. <NModal v-model:show={showModalMask.value}>
  181. <div class={styles.downMove}>
  182. <img src={dingPng} class={styles.dingPng} alt="" />
  183. <img src={moveTop} class={styles.downMoveBg} alt="" />
  184. <img
  185. src={closeAble}
  186. class={styles.closeAble}
  187. onClick={() => {
  188. showModalMask.value = false;
  189. }}
  190. alt=""
  191. />
  192. <h2>温馨提示</h2>
  193. <p>
  194. 检测到您尚未安装“音乐数字课堂”应用程序,为了更好的使用体验,是否立即下载?
  195. </p>
  196. {/* <NButton>确定</NButton> */}
  197. <NSpace style={{ padding: '25px 0 0 0' }} justify="center">
  198. <NButton
  199. {...{ id: 'submitBtn' }}
  200. class={styles.submitAppBtn}
  201. round
  202. type="primary">
  203. 立即下载
  204. </NButton>
  205. </NSpace>
  206. </div>
  207. </NModal>
  208. </div>
  209. );
  210. }
  211. });