login.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. <template>
  2. <image src="./static/login.png" mode="" class="containerImg"></image>
  3. <view class="header">
  4. <view class="p1">欢迎登录</view>
  5. <view class="p2">观星台服务应用</view>
  6. </view>
  7. <view class="content">
  8. <view class="title">
  9. <image src="../../static/登录.png" mode="" class="img"></image>
  10. <view>用户登录</view>
  11. </view>
  12. <up-form labelPosition="left" :model="state.userFrom" :rules="state.rules" ref="uFormRef">
  13. <up-form-item prop="staffName">
  14. <up-input v-model="state.userFrom.account" border="none" :customStyle="customStyle"
  15. placeholder="请输入LDAP账号">
  16. <template #prefix style="margin-right: 30rpx;">
  17. <image src="../../static/账号.png" mode="" style="width: 35rpx;height: 40rpx;margin-left: 35rpx;">
  18. </image>
  19. </template>
  20. <template #suffix style="margin-right: 30rpx;">
  21. @999.com.cn
  22. </template>
  23. </up-input>
  24. </up-form-item>
  25. <up-form-item prop="staffPass" borderBottom>
  26. <up-input v-if="passeye==false" v-model="state.userFrom.password" type="password" border="none"
  27. :customStyle="customStyle" placeholder="请输入密码">
  28. <template #prefix style="margin-right: 30rpx;">
  29. <image src="../../static/密码.png" mode="" style="width: 35rpx;height: 40rpx;margin-left: 35rpx;">
  30. </image>
  31. </template>
  32. <template #suffix>
  33. <view style="margin-right: 30rpx;">
  34. <up-icon name="eye" @click="passeye=true" size="40rpx"></up-icon>
  35. </view>
  36. </template>
  37. </up-input>
  38. <up-input v-if="passeye==true" v-model="state.userFrom.password" type="text" border="none"
  39. :customStyle="customStyle" placeholder="请输入密码">
  40. <template #prefix style="margin-right: 30rpx;">
  41. <image src="../../static/密码.png" mode="" style="width: 35rpx;height: 40rpx;margin-left: 35rpx;">
  42. </image>
  43. </template>
  44. <template #suffix>
  45. <view style="margin-right: 30rpx;">
  46. <up-icon name="eye" @click="passeye=false" size="40rpx"></up-icon>
  47. </view>
  48. </template>
  49. </up-input>
  50. </up-form-item>
  51. <up-form-item prop="verifyCode" borderBottom>
  52. <up-input v-model="state.userFrom.verifyCode" border="none" :customStyle="customStyle"
  53. placeholder="请输入验证码">
  54. <template #prefix style="margin-right: 30rpx;">
  55. <image src="../../static/密码.png" mode="" style="width: 35rpx;height: 40rpx;margin-left: 35rpx;">
  56. </image>
  57. </template>
  58. <template #suffix style="margin-right: 30rpx;">
  59. <view
  60. style="border-left: 1rpx solid #038CFF;color: #038CFF;height: 100rpx;padding-left: 20rpx;">
  61. <!-- apex -->
  62. <image style="width: 150rpx;height: 100rpx;" :src="imgUrl" mode=""
  63. @click="getgenerateCode()"></image>
  64. </view>
  65. </template>
  66. </up-input>
  67. <view style="width: 100%;text-align: right;font-size: 26rpx;color:#a5b1be ;margin-top: 20rpx;">
  68. 注:验证码不区分大小写
  69. </view>
  70. </up-form-item>
  71. </up-form>
  72. <up-button type="primary" @click="submit" :customStyle="customStyle2">登录</up-button>
  73. <view class="footer">
  74. 注:该小程序仅限公司内部员工使用,账号由公司分配。
  75. </view>
  76. </view>
  77. </template>
  78. <script setup>
  79. import {
  80. ref,
  81. reactive,
  82. getCurrentInstance
  83. } from 'vue';
  84. import {
  85. onReady,
  86. onShow,
  87. onLoad,
  88. } from '@dcloudio/uni-app'
  89. import JSEncrypt from '@/uni_modules/jsencrypt/lib/index.js';
  90. const {
  91. proxy
  92. } = getCurrentInstance()
  93. import {
  94. Storage
  95. } from '@/service/storage'
  96. const storage = new Storage()
  97. const state = reactive({
  98. userFrom: {
  99. account: '',
  100. password: "",
  101. verifyCode: "",
  102. verifyId: ''
  103. },
  104. rules: {
  105. 'account': {
  106. type: 'string',
  107. required: true,
  108. message: '注:重要项必须输入',
  109. trigger: ['blur'],
  110. },
  111. 'password': {
  112. type: 'string',
  113. required: true,
  114. message: '注:重要项必须输入',
  115. trigger: ['blur'],
  116. },
  117. 'verifyCode': {
  118. type: 'string',
  119. len: 4,
  120. message: '注:输入4位数验证码',
  121. trigger: ['blur'],
  122. },
  123. },
  124. });
  125. const customStyle = reactive({
  126. backgroundColor: '#ebf3fb',
  127. height: '100rpx'
  128. })
  129. const customStyle2 = reactive({
  130. height: '112rpx',
  131. fontSize: '32rpx',
  132. borderRadius: '20rpx',
  133. marginTop: '50rpx'
  134. });
  135. // 使用 ref 创建响应式引用
  136. const formRef = ref(null);
  137. const passeye = ref(false)
  138. const uFormRef = ref(null);
  139. const code = ref()
  140. const imgUrl = ref('')
  141. const baseUrl = ref()
  142. onLoad(() => {
  143. baseUrl.value = import.meta.env.VITE_APP_API_BASEURL
  144. if (storage.getToken()) {
  145. uni.setStorageSync('subscript', true);
  146. uni.reLaunch({
  147. url: '/components/tabbar/tabbar'
  148. })
  149. }
  150. getgenerateCode()
  151. })
  152. const getgenerateCode = async () => {
  153. let a = generateUUID();
  154. state.userFrom.verifyId = a, uni.request({
  155. url: `${baseUrl.value}/v1/api/login/generateCode`,
  156. data: {
  157. data: {
  158. codeId: a
  159. }
  160. },
  161. responseType: "arraybuffer",
  162. method: "post",
  163. header: {
  164. accessToken: storage.getStorageSync("accessToken")
  165. },
  166. success: a => {
  167. if (200 === a.statusCode) {
  168. let b = uni.arrayBufferToBase64(a.data);
  169. imgUrl.value = "data:image/jpeg;base64," + b
  170. }
  171. }
  172. })
  173. }, generateUUID = () => {
  174. const a = Array(16);
  175. for (let b = 0; 16 > b; b++) a[b] = Math.floor(256 * Math.random());
  176. return a[6] = 64 | 15 & a[6], a[8] = 128 | 63 & a[8], a.map((a, b) => (4 === b || 6 === b || 8 === b ||
  177. 10 === b ? "-" : "") + ("0" + a.toString(16)).slice(-2)).join("")
  178. };
  179. const submit = () => {
  180. uFormRef.value.validate().then(valid => {
  181. if (valid) {
  182. login()
  183. }
  184. }).catch(() => {
  185. // 处理验证错误
  186. uni.$u.toast('请完善输入框的信息')
  187. });
  188. }
  189. const login = async () => {
  190. const pubKey =
  191. "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAJIMt6SCsx+KiBuagZmEtYBo+OnMJBCgKLWsJ1dw7k6bzzRWmDA2AQFxNo2xYkMrDkKOQpNXbUyrw1/mxKI3amsCAwEAAQ==",
  192. encryptor = new JSEncrypt;
  193. encryptor.setPublicKey(
  194. "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAJIMt6SCsx+KiBuagZmEtYBo+OnMJBCgKLWsJ1dw7k6bzzRWmDA2AQFxNo2xYkMrDkKOQpNXbUyrw1/mxKI3amsCAwEAAQ=="
  195. );
  196. let rsaPassWord = encryptor.encrypt(`${state.userFrom.password}`),
  197. data = {
  198. ...state.userFrom,
  199. password: rsaPassWord
  200. };
  201. uni.showLoading({
  202. title: '登录中,请稍后...'
  203. });
  204. // 加密调用登录
  205. let res = await proxy.$api.login.logins({
  206. data
  207. })
  208. if (res.code == 0) {
  209. storage.setToken(res.data)
  210. uni.login({
  211. success(res3) {
  212. console.log('微信code信息', res3.code);
  213. code.value = res3.code
  214. proxy.$api.login.getOpenId(code.value)
  215. uni.setStorageSync('subscript', false);
  216. proxy.$api.login.getInfo().then((res) => {
  217. uni.setStorageSync('userInfo', res.data)
  218. uni.hideLoading();
  219. uni.reLaunch({
  220. url: '/components/tabbar/tabbar'
  221. })
  222. })
  223. }
  224. })
  225. }
  226. }
  227. </script>
  228. <style lang="scss">
  229. .footer {
  230. color: ghostwhite;
  231. margin-top: 260rpx;
  232. font-size: 24rpx;
  233. }
  234. .container {
  235. width: 100%;
  236. height: 100%;
  237. position: absolute;
  238. z-index: -1;
  239. }
  240. .containerImg {
  241. width: 100%;
  242. height: 100%;
  243. position: absolute;
  244. }
  245. .header {
  246. width: 90%;
  247. margin: auto;
  248. height: 180rpx;
  249. position: absolute;
  250. z-index: 1;
  251. top: 180rpx;
  252. left: 0;
  253. right: 0;
  254. display: flex;
  255. flex-wrap: wrap;
  256. justify-content: center;
  257. align-items: center;
  258. .p1 {
  259. width: 100%;
  260. font-size: 50rpx;
  261. font-weight: bold;
  262. }
  263. .p2 {
  264. width: 100%;
  265. font-size: 38rpx;
  266. font-weight: bold;
  267. }
  268. }
  269. .content {
  270. width: 85%;
  271. // margin: auto;
  272. position: absolute;
  273. z-index: 2;
  274. top: 460rpx;
  275. left: 0;
  276. right: 0;
  277. margin: auto;
  278. .title {
  279. display: flex;
  280. align-items: center;
  281. font-size: 36rpx;
  282. margin-bottom: 20rpx;
  283. .img {
  284. width: 50rpx;
  285. height: 50rpx;
  286. margin-right: 15rpx;
  287. }
  288. }
  289. }
  290. </style>