login.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. <template>
  2. <view class="login-page">
  3. <image class="bgImage" src="/static/images/shade.png" mode="widthFix"></image>
  4. <view class="form-area" :style="{ paddingBottom: (keyboardHeight > 0 ? (keyboardPadding + 'px') : '100rpx') }">
  5. <view class="inputArea">
  6. <image class="inputIcon" src="/static/images/login_account_icon.png" mode="aspectFit"></image>
  7. <input class="inputTag" type="text" placeholder="请输入账号" placeholder-class="inputTagHolderPlace"
  8. v-model="username" />
  9. </view>
  10. <view class="inputArea pwd">
  11. <image class="inputIcon" src="/static/images/login_pwd_icon.png" mode="aspectFit"></image>
  12. <input class="inputTag" password="true" type="text" placeholder="请输入密码"
  13. placeholder-class="inputTagHolderPlace" v-model="password" />
  14. </view>
  15. <button id="loginBtn" :class="[isInput?'loginBtn on':'loginBtn']" type="default" @click="login">登录</button>
  16. <tm-modal v-if="showInputModal" @click="clickModalhandle">
  17. <view class="checkItemResultModal">
  18. <view class="modalContent">
  19. <view class="modalBar">{{`开发者模式(v${version})`}}</view>
  20. <input class="keyInutArea" type="text" v-model="appHospSign" @input='setHospSign'
  21. placeholder="请输入hospSign" />
  22. <image v-if="enableAppScan" @click="openScanner" class="scanBtn" src="../../static/scancodeIcon.png" mode=""></image>
  23. <view>{{deviceInfo}}</view>
  24. <button class="commitActBtn" @click="updateHospSign(true)" type="default">确定</button>
  25. <!-- <button class="commitActBtn" @click="updateHospSign(false)" type="default">确定</button> -->
  26. </view>
  27. </view>
  28. </tm-modal>
  29. </view>
  30. </view>
  31. </template>
  32. <script>
  33. import encryption from "../../utils/crypto.js";
  34. import {
  35. mapState
  36. } from "vuex";
  37. import {
  38. loginAfterHandle
  39. } from '../../utils/loginHandle.js';
  40. export default {
  41. data() {
  42. return {
  43. index: 0,
  44. appHospSign: 'gKMa7SLw9hRglxm5', //app端更新hospSign
  45. showInputModal: false,
  46. hospSign: '', // 医院标识
  47. username: '', // 用户名
  48. password: '', // 密码
  49. version: '',
  50. deviceInfo: {},
  51. enableAppScan: false,
  52. keyboardHeight: 0, // 软键盘高度(px)
  53. keyboardPadding: 0 // 计算后的底部最小必要留白(px)
  54. }
  55. },
  56. computed: {
  57. isInput: function() {
  58. return (this.username.length > 0 && this.password.length > 0) ? true : false
  59. },
  60. isPad:function(){
  61. return getApp().globalData.isPad
  62. },
  63. },
  64. onLoad({
  65. hospSign
  66. }) {
  67. this.hospSign = hospSign;
  68. // #ifdef APP-PLUS
  69. const hospSignFromLocal = uni.getStorageSync('hospSign');
  70. if (hospSignFromLocal != '') {
  71. this.appHospSign = hospSignFromLocal;
  72. }
  73. this.deviceInfo = uni.getSystemInfoSync();
  74. //获取版本号
  75. plus.runtime.getProperty(plus.runtime.appid, (inf) => {
  76. this.version = inf.version;
  77. });
  78. // #endif
  79. },
  80. onReady() {
  81. // APP端设置键盘模式为adjustPan
  82. // #ifdef APP-PLUS
  83. try {
  84. plus.webview.currentWebview().setStyle({
  85. softinputMode: 'adjustPan'
  86. });
  87. } catch (e) {}
  88. // #endif
  89. // 监听键盘高度变化,动态计算最小必要留白
  90. if (typeof uni.onKeyboardHeightChange === 'function') {
  91. uni.onKeyboardHeightChange((res) => {
  92. this.keyboardHeight = res && res.height ? res.height : 0;
  93. if (this.keyboardHeight <= 0) {
  94. this.keyboardPadding = 0;
  95. return;
  96. }
  97. this.$nextTick(() => {
  98. // 获取登录按钮的位置,计算与键盘顶部的距离
  99. const query = uni.createSelectorQuery();
  100. query.select('#loginBtn').boundingClientRect();
  101. query.exec((resRects) => {
  102. if (!resRects || !resRects[0]) {
  103. this.keyboardPadding = this.keyboardHeight;
  104. return;
  105. }
  106. const btnRect = resRects[0];
  107. const windowInfo = uni.getSystemInfoSync();
  108. const windowHeight = windowInfo.windowHeight; // px
  109. const keyboardTop = windowHeight - this.keyboardHeight; // 键盘顶部y
  110. const btnBottom = btnRect.bottom; // 按钮底部y
  111. const gap = keyboardTop - btnBottom; // 需要留白的空间
  112. const safeInset = (windowInfo.safeAreaInsets && windowInfo.safeAreaInsets.bottom) ? windowInfo.safeAreaInsets.bottom : 0;
  113. // 仅当gap<安全间距时,补齐差值与安全区,避免过大留白
  114. this.keyboardPadding = gap < 8 ? (8 + safeInset) : (safeInset);
  115. // 保底不为负
  116. if (this.keyboardPadding < 0) this.keyboardPadding = 0;
  117. // 边缘场景:若输入框获得焦点且更靠下,允许适度滚动
  118. if (gap < 0) {
  119. uni.pageScrollTo({ scrollTop: 999999, duration: 0 });
  120. }
  121. });
  122. });
  123. });
  124. }
  125. },
  126. methods: {
  127. openScanner() {
  128. // 只允许通过相机扫码
  129. uni.scanCode({
  130. onlyFromCamera: true,
  131. success: (res) => {
  132. console.log('条码类型:' + res.scanType);
  133. console.log('条码内容:' + res.result);
  134. this.appHospSign = res.result;
  135. }
  136. });
  137. },
  138. setHospSign(e) {
  139. this.appHospSign = e.target.value
  140. },
  141. openModal() {
  142. // #ifdef APP-PLUS
  143. this.index = this.index + 1;
  144. if (this.index == 3) this.showInputModal = true;
  145. // #endif
  146. },
  147. updateHospSign(bool) {
  148. if (bool) {
  149. this.hospSign = this.appHospSign;
  150. }
  151. this.index = 0;
  152. this.showInputModal = false;
  153. },
  154. login() {
  155. if (this.isLogin) return;
  156. const nowPermission = uni.getStorageSync('nowPermission');
  157. let hospSign = '';
  158. // #ifdef APP-PLUS
  159. hospSign = uni.getStorageSync('hospSign') || this.appHospSign;
  160. // #endif
  161. // #ifdef H5
  162. hospSign = this.hospSign;
  163. // #endif
  164. this.$store.dispatch({
  165. type: 'login/commActions',
  166. payload: {
  167. key: 'login',
  168. data: {
  169. username: encryption(this.username),
  170. password: encryption(this.password),
  171. hospSign: hospSign,
  172. nowPermission: nowPermission
  173. }
  174. }
  175. }).then((data) => {
  176. if (data) {
  177. loginAfterHandle(data, hospSign);
  178. }
  179. });
  180. },
  181. }
  182. }
  183. </script>
  184. <style lang="less" scoped>
  185. .login-page {
  186. display: flex;
  187. flex-direction: column;
  188. justify-content: flex-start;
  189. min-height: 100vh; // 使用最小高度避免键盘弹出时整体被压缩
  190. height: auto; // 允许内容在需要时溢出并滚动
  191. padding-bottom: 100rpx;
  192. background-color: #FFFFFF;
  193. .bgImage {
  194. width: 100%;
  195. display: block;
  196. flex-shrink: 0; // 禁止在弹出键盘时被压缩
  197. // 不设置height,自动按比例撑开
  198. // 去掉position、top、right等定位属性
  199. }
  200. .row {
  201. position: relative;
  202. z-index: 100;
  203. font-size: 45rpx;
  204. font-family: SourceHanSansCN-Bold, SourceHanSansCN;
  205. font-weight: bold;
  206. color: #2E2F33;
  207. line-height: 67.5rpx;
  208. }
  209. .titleTwo {
  210. margin-bottom: 75rpx;
  211. }
  212. .form-area {
  213. padding: 0 62.5rpx;
  214. }
  215. .inputArea {
  216. display: flex;
  217. align-items: center;
  218. height: 80rpx;
  219. margin-bottom: 37.5rpx;
  220. border-bottom: 1.25rpx solid #E6EAF2;
  221. input {
  222. -webkit-box-shadow: 0 0 0 1000px white inset;
  223. }
  224. .inputIcon {
  225. width: 36rpx;
  226. height: 36rpx;
  227. margin-right: 20rpx;
  228. flex-shrink: 0;
  229. }
  230. .inputTag {
  231. height: 100%;
  232. width: 100%;
  233. font-size: 30rpx;
  234. font-family: SourceHanSansCN-Medium, SourceHanSansCN;
  235. font-weight: 500;
  236. color: #292C33;
  237. // &.-internal-autofill-selected {
  238. // background-color:#FFFFFF;
  239. // }
  240. }
  241. // /deep/.inputTag .uni-input-input {
  242. // font-size: 30rpx;
  243. // font-family: SourceHanSansCN-Medium, SourceHanSansCN;
  244. // font-weight: 500;
  245. // color: #292C33;
  246. // box-shadow: 0 0 0 54rpx #fff inset;
  247. // }
  248. .inputTagHolderPlace {
  249. font-size: 30rpx;
  250. font-family: SourceHanSansCN-Normal, SourceHanSansCN;
  251. font-weight: 400;
  252. color: #B8BECC;
  253. }
  254. // /deep/.inputTag .uni-input-placeholder {
  255. // font-size: 30rpx;
  256. // }
  257. &.pwd {
  258. margin-bottom: 62.5rpx;
  259. }
  260. }
  261. .loginBtn {
  262. display: block;
  263. width: 100%;
  264. height: 75rpx;
  265. text-align: center;
  266. line-height: 75rpx;
  267. font-size: 30rpx;
  268. font-family: SourceHanSansCN-Normal, SourceHanSansCN;
  269. font-weight: 400;
  270. color: #FFFFFF;
  271. border-radius: 37.5rpx;
  272. border: none;
  273. background: #A3B1CC; // 默认灰色
  274. // background-color: #A3B1CC; // 建议去掉,避免和渐变冲突
  275. &.on {
  276. background: linear-gradient(90deg, #3377FF 0%, #4D97FF 100%) !important; // 渐变,优先级高
  277. }
  278. }
  279. .checkItemResultModal {
  280. display: flex;
  281. height: 100%;
  282. justify-content: center;
  283. align-items: center;
  284. overflow: hidden;
  285. .modalContent {
  286. position: relative;
  287. width: 90%;
  288. height: 500rpx;
  289. border-radius: 20rpx;
  290. overflow: hidden;
  291. background-color: #FFFFFF;
  292. .modalBar {
  293. display: flex;
  294. justify-content: center;
  295. align-items: center;
  296. height: 80rpx;
  297. color: #4E78FF;
  298. font-size: 22.5rpx;
  299. border-bottom: 0.1rpx solid #E5E5E5;
  300. }
  301. .keyInutArea {
  302. height: 80rpx;
  303. color: #4E78FF;
  304. font-size: 22.5rpx;
  305. padding: 0 20rpx;
  306. border: 0.1rpx solid #E5E5E5;
  307. }
  308. .scanBtn {
  309. position: absolute;
  310. display: block;
  311. width: 25rpx;
  312. height: 25rpx;
  313. top: 105rpx;
  314. right: 30rpx;
  315. z-index: 10;
  316. }
  317. .commitActBtn {
  318. position: absolute;
  319. width: 100%;
  320. bottom: 0;
  321. border-radius: 0;
  322. }
  323. }
  324. }
  325. }
  326. </style>