login.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <template>
  2. <view class="login-page">
  3. <view class="com-model">
  4. <view class="top-box">
  5. <image class="pic" src="/static/images/shade.png"></image>
  6. <text class="title-top" @click="openModal">你好,</text>
  7. <text class="title-buttom">欢迎使用追踪方法学系统</text>
  8. </view>
  9. <view class="main-content">
  10. <input class="uni-input-box"
  11. placeholder="请输入账号"
  12. placeholder-style="color: #A1A7B3"
  13. v-model="username" />
  14. <input class="uni-input-box"
  15. placeholder="请输入密码"
  16. placeholder-style="color: #A1A7B3"
  17. password
  18. v-model="password" />
  19. <com-button class="login-button"
  20. :width="998" :height="120" :fontSize="48" :background="isLogin?'#A3B1CC':''" btnText="登录" @btnClick="login" />
  21. </view>
  22. </view>
  23. <tm-modal v-if="showInputModal" @click="clickModalhandle">
  24. <view class="checkItemResultModal">
  25. <view class="modalContent">
  26. <view class="modalBar">开发者模式</view>
  27. <input class="keyInutArea" type="text" v-model="appHospSign" @input='setHospSign' placeholder="请输入hospSign" />
  28. <image @click="openScanner" class="scanBtn" src="../../static/scancodeIcon.png" mode=""></image>
  29. <button class="commitActBtn" @click="updateHospSign(true)" type="default">确定</button>
  30. <!-- <button class="commitActBtn" @click="updateHospSign(false)" type="default">确定</button> -->
  31. </view>
  32. </view>
  33. </tm-modal>
  34. </view>
  35. </template>
  36. <script>
  37. import encryption from "../../utils/crypto.js";
  38. export default {
  39. data() {
  40. return {
  41. index:0,
  42. appHospSign:'tYAoFaa20yCAgaiy',//app端更新hospSign 8CJYqxlGIdLEIwaG
  43. showInputModal:false,
  44. hospSign: '', // 医院标识
  45. username: '', // 用户名
  46. password: '', // 密码
  47. rolList: [
  48. {permission: 1, name: '管理员', pagePath: 'pages/situationsCenter/situationsCenter'}, // targetIndexs:targetList种对应的下标
  49. {permission: 2, name: '查核组长',pagePath: 'pages/situationsCenter/situationsCenter'},
  50. {permission: 3, name: '查核组员', pagePath: 'pages/situationsCenter/situationsCenter'},
  51. {permission: 4, name: '单位负责人', pagePath: 'pages/mission/mission'},
  52. {permission: 5, name: '改善者', pagePath: 'pages/mission/mission'}
  53. ]
  54. }
  55. },
  56. onLoad({ hospSign }){
  57. this.hospSign = hospSign;
  58. // #ifdef APP-PLUS
  59. const hospSignFromLocal = uni.getStorageSync('hospSign');
  60. console.log({hospSignFromLocal});
  61. if(hospSignFromLocal != ''){
  62. this.appHospSign = hospSignFromLocal;
  63. }
  64. // #endif
  65. },
  66. mounted(){
  67. },
  68. methods: {
  69. openScanner(){
  70. // 只允许通过相机扫码
  71. uni.scanCode({
  72. onlyFromCamera: true,
  73. success:(res)=>{
  74. console.log('条码类型:' + res.scanType);
  75. console.log('条码内容:' + res.result);
  76. this.appHospSign = res.result;
  77. }
  78. });
  79. },
  80. setHospSign(e){
  81. this.appHospSign = e.target.value
  82. },
  83. openModal(){
  84. // #ifdef APP-PLUS
  85. this.index = this.index + 1;
  86. if(this.index==3)this.showInputModal = true;
  87. // #endif
  88. },
  89. updateHospSign(bool){
  90. if(bool){
  91. this.hospSign = this.appHospSign;
  92. }
  93. this.index=0;
  94. this.showInputModal = false;
  95. },
  96. login() {
  97. if(this.isLogin) return;
  98. const nowPermission = uni.getStorageSync('nowPermission');
  99. // #ifdef APP-PLUS
  100. const hospSign = this.appHospSign;
  101. // #endif
  102. // #ifdef H5
  103. const hospSign = this.hospSign;
  104. // #endif
  105. this.$store.dispatch({
  106. type: 'login/commActions',
  107. payload: {
  108. key: 'login',
  109. data: {
  110. username: encryption(this.username),
  111. password: encryption(this.password),
  112. hospSign:hospSign,
  113. nowPermission:nowPermission
  114. // hospSign:'tYAoFaa20yCAgaiy'
  115. }
  116. }
  117. }).then((data) => {
  118. if (data) {
  119. uni.setStorageSync('hiId', data.hiId);
  120. uni.setStorageSync('permissions', data.permissions);
  121. uni.setStorageSync('token', data.token);
  122. uni.setStorageSync('code', data.code);
  123. uni.setStorageSync('nowPermission', data.nowPermission);
  124. uni.setStorageSync('id', data.id);
  125. uni.setStorageSync('name', data.name);
  126. uni.setStorageSync('hospSign',hospSign);
  127. this.rolToTarget(data.nowPermission)
  128. }
  129. });
  130. },
  131. clickModalhandle(){
  132. },
  133. //角色和对应的跳转页面
  134. rolToTarget(nowPermission) {
  135. if(nowPermission != 0){
  136. let current = this.rolList.find(item => item.permission == nowPermission);
  137. if(current){
  138. // 页面跳转
  139. uni.redirectTo({
  140. url: `/${current.pagePath}`
  141. });
  142. }
  143. }
  144. }
  145. },
  146. computed:{
  147. //判断是否输入了用户名和密码
  148. isLogin(){
  149. return !this.username || !this.password;
  150. }
  151. }
  152. }
  153. </script>
  154. <style lang="less" scoped>
  155. .login-page {
  156. height:100vh;
  157. background-color: #FFFFFF;
  158. .checkItemResultModal {
  159. display: flex;
  160. height: 100%;
  161. justify-content: center;
  162. align-items: center;
  163. overflow: hidden;
  164. .modalContent {
  165. position: relative;
  166. width: 90%;
  167. height:500rpx;
  168. border-radius: 20rpx;
  169. overflow: hidden;
  170. background-color: #FFFFFF;
  171. .modalBar{
  172. display: flex;
  173. justify-content: center;
  174. align-items: center;
  175. height: 80rpx;
  176. color: #4E78FF;
  177. font-size: 22.5rpx;
  178. border-bottom: 0.1rpx solid #E5E5E5;
  179. }
  180. .keyInutArea {
  181. height: 80rpx;
  182. color: #4E78FF;
  183. font-size: 22.5rpx;
  184. padding: 0 20rpx;
  185. border: 0.1rpx solid #E5E5E5;
  186. }
  187. .scanBtn {
  188. position: absolute;
  189. display: block;
  190. width:25rpx;
  191. height: 25rpx;
  192. top:105rpx;
  193. right:30rpx;
  194. z-index: 10;
  195. }
  196. .commitActBtn {
  197. position: absolute;
  198. width: 100%;
  199. bottom: 0;
  200. border-radius: 0;
  201. }
  202. }
  203. }
  204. .top-box {
  205. display: flex;
  206. flex-direction: column;
  207. padding-left: 62.5rpx;
  208. .pic{
  209. position: absolute;
  210. top: 0;
  211. right: 0;
  212. width: 430rpx;
  213. height: 281.25rpx;
  214. }
  215. .title-top{
  216. height: 45rpx;
  217. font-size: 45rpx;
  218. font-weight: bold;
  219. margin-top: 250rpx;
  220. font-family: SourceHanSansCN-Bold, SourceHanSansCN;
  221. color: #2E2F33;
  222. }
  223. .title-buttom{
  224. margin-top: 40rpx;
  225. height: 45rpx;
  226. font-size: 45rpx;
  227. font-family: SourceHanSansCN-Bold, SourceHanSansCN;
  228. font-weight: bold;
  229. color: #2E2F33;
  230. }
  231. }
  232. .main-content{
  233. margin-top: 37.5rpx;
  234. float: left;
  235. }
  236. .uni-input-box{
  237. width: 625rpx;
  238. float: left;
  239. margin-left: 62.5rpx;
  240. margin-top: 62.5rpx;
  241. font-size: 30rpx;
  242. padding-bottom: 25rpx;
  243. border-bottom:1.25rpx solid #E6EAF2 ;
  244. }
  245. .login-button{
  246. float: left;
  247. margin-left: 62.5rpx;
  248. margin-top: 62.5rpx;
  249. background-color: #A3B1CC;
  250. }
  251. }
  252. </style>