login.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. <template>
  2. <page-meta :page-font-size="fontValue+'px'" :root-font-size="fontValue+'px'"></page-meta>
  3. <view class="loginV">
  4. <view class="content">
  5. <!-- 头部logo -->
  6. <view class="header">
  7. <image :src="logoImage"></image>
  8. <view class="appName">
  9. <text style="letter-spacing: 4rpx;font-style: italic;">AIIM</text>
  10. </view>
  11. </view>
  12. <!-- 主体表单 -->
  13. <view class="main" v-if="showLogin">
  14. <!-- <view class="main"> -->
  15. <view style="margin-top: 30px;">
  16. <text style="font-size: 28upx;font-weight: bold;">账号</text>
  17. <view class="main-list oBorder">
  18. <input class="main-input" v-model="form.name" placeholder="请输入账号"/>
  19. </view>
  20. </view>
  21. <view style="margin-top: 10px;">
  22. <text style="font-size: 28upx;font-weight: bold;">密码</text>
  23. <view class="main-list oBorder">
  24. <input type="password" class="main-input" v-model="form.password" placeholder="请输入密码"/>
  25. </view>
  26. </view>
  27. <view style="margin-top: 10px;">
  28. <text style="font-size: 28upx;font-weight: bold;">验证码</text>
  29. <view class="contentInRowS">
  30. <view class="main-list oBorder" style="margin-right: 10px;">
  31. <input type="number" class="main-input" v-model="form.code" placeholder="请输入验证码"/>
  32. </view>
  33. <image :src="codeUrl" mode="widthFix" class="img" @tap="getCode"></image>
  34. </view>
  35. </view>
  36. <view style="margin-top: 10px;">
  37. <view class="contentInRowS">
  38. <view class="contentInRowL">
  39. <uni-icons custom-prefix="custom-icon" color="#6E75FB" type="checkbox" size="19"></uni-icons>
  40. <text style="font-size: 24upx;">记住我</text>
  41. </view>
  42. <text style="font-size: 26upx;color: #6E75FB;" @click="resetPassword">忘记密码?</text>
  43. </view>
  44. </view>
  45. <button class="cu-btn bg-zblue lg margin-top" style="border-radius: 40upx;" @click.native="submit()">登录</button>
  46. <view class="contentInRowC" style="font-size: 26upx;margin-top: 20px;" @click="register">
  47. <text style="color:darkgray;">没有账号?</text>
  48. <text style="color: #6E75FB;">去注册</text>
  49. </view>
  50. </view>
  51. <view v-if="!showLogin" class="loading" style="margin-top: 40rpx;">
  52. <!-- <image :src="loading"></image> -->
  53. <!-- <image style="width: 100%;" src="/static/loadingBg.png" mode="aspectFit"></image> -->
  54. </view>
  55. </view>
  56. </view>
  57. </template>
  58. <script setup lang="ts">
  59. import {reactive, ref} from "vue";
  60. import Auth from "@/api/Auth";
  61. import {useUserStore} from "@/store/userStore";
  62. import UserApi from "@/api/UserApi";
  63. import {getCodeImg, login,savelogin,clearVoipTk} from "@/api/Login";
  64. import {onLoad,onShow} from '@dcloudio/uni-app';
  65. import {useWsStore} from "@/store/WsStore";
  66. import dbApi from '@/api/DBactApi'
  67. const userStore = useUserStore()
  68. const logoImage = ref('/static/logo512.png')
  69. const form = reactive({
  70. name: "",
  71. password: "",
  72. code: "",
  73. uuid: "",
  74. });
  75. // 验证码开关
  76. const captchaOnOff = ref(true);
  77. const codeUrl = ref("");
  78. const show = ref(false);
  79. //是否展示登录界面
  80. const showLogin = ref(false);
  81. const fontValue=ref(Auth.getfontSize());
  82. function errorOpt() {
  83. showLogin.value = true;
  84. closeWebsocket()
  85. }
  86. onLoad(() => {
  87. Auth.isLogin()
  88. .then((res) => {
  89. if (res) {
  90. UserApi.currentUser()
  91. .then((res) => {
  92. userStore.setUser(res.data);
  93. uni.setStorageSync('userName', res.data.name);
  94. uni.setStorageSync('userId', res.data.id)
  95. dbApi.createMSGtable();
  96. dbApi.createchattable();
  97. dbApi.createLocalMSGtable();
  98. setTimeout(function() {
  99. // 这里写要延时执行的代码
  100. uni.reLaunch({
  101. url: "/pages/index/index"
  102. })
  103. }, 300);
  104. })
  105. .catch(() => {
  106. errorOpt()
  107. })
  108. } else {
  109. errorOpt()
  110. }
  111. })
  112. .catch(() => {
  113. errorOpt()
  114. })
  115. })
  116. const closeWebsocket = () => {
  117. //如果回到登录界面,需要关闭websocket链接
  118. var voipTk = Auth.getvoipTk();
  119. if(voipTk!=''){
  120. var data={
  121. "voipTk":voipTk
  122. }
  123. clearVoipTk(JSON.stringify(data)).then((res)=>{
  124. console.log('clearVoipTk',res);
  125. useWsStore().close(true)
  126. })
  127. .catch((err) => {
  128. useWsStore().close(true)
  129. console.log('clearVoipTk',err);
  130. });
  131. }
  132. else{
  133. useWsStore().close(true);
  134. }
  135. }
  136. const submit = () => {
  137. uni.showLoading();
  138. var savePassw = uni.getStorageSync(form.name);
  139. console.log(savePassw,form.name);
  140. if(savePassw==null||savePassw==''||savePassw==undefined){
  141. }else{
  142. if(savePassw==form.password){//安全密码登录,清除数据
  143. //先清空数据
  144. console.log('先清空数据');
  145. dbApi.delmsglistTable(form.name);
  146. dbApi.delchatlistTable(form.name);
  147. dbApi.delLocalmsglistTable(form.name);
  148. //MessageUtils.message('密码错误!')
  149. //dbApi.createMSGtable();
  150. savelogin(form.name, form.password, form.code, form.uuid)
  151. .then((res: any) => {
  152. Auth.setToken(res.token);
  153. uni.hideLoading()
  154. return UserApi.currentUser();
  155. })
  156. .then((res) => {
  157. if(Auth.getregisterID()&&Auth.getregisterID()!=''){
  158. var platformType='a';
  159. var data;
  160. if(uni.getSystemInfoSync().platform == "ios"){
  161. platformType='i';
  162. data={
  163. "userId": res.data?.id,
  164. "registrationId":'',
  165. "platformType":platformType,//a---(android),i---(ios)
  166. "voipTk":'',
  167. }
  168. }
  169. else{
  170. data={
  171. "userId": res.data?.id,
  172. "registrationId":'',
  173. "platformType":platformType,//a---(android),i---(ios)
  174. "voipTk":'',
  175. }
  176. }
  177. UserApi.setUser(JSON.stringify(data)).then((res)=>{
  178. console.log('setuser',res);
  179. });
  180. }
  181. userStore.setUser(res.data);
  182. uni.setStorageSync('userName', res.data.name);
  183. uni.setStorageSync('userId', res.data.id);
  184. dbApi.createMSGtable();
  185. dbApi.createLocalMSGtable();
  186. uni.reLaunch({
  187. url: "/pages/index/index"
  188. })
  189. });
  190. uni.hideLoading()
  191. return;
  192. }
  193. }
  194. login(form.name, form.password, form.code, form.uuid)
  195. .then((res: any) => {
  196. Auth.setToken(res.token);
  197. uni.hideLoading()
  198. return UserApi.currentUser();
  199. })
  200. .then((res) => {
  201. var platformType='a';
  202. var data;
  203. if(uni.getSystemInfoSync().platform == "ios"){
  204. platformType='i';
  205. data={
  206. "userId": res.data?.id,
  207. "registrationId":Auth.getregisterID(),
  208. "platformType":platformType,//a---(android),i---(ios)
  209. "voipTk":Auth.getvoipTk(),
  210. }
  211. }
  212. else{
  213. data={
  214. "userId": res.data?.id,
  215. "registrationId":Auth.getregisterID(),
  216. "platformType":platformType,//a---(android),i---(ios)
  217. "voipTk":Auth.getvoipTk(),
  218. }
  219. }
  220. console.log(data);
  221. UserApi.setUser(JSON.stringify(data)).then((res)=>{
  222. console.log('setuser',res);
  223. });
  224. userStore.setUser(res.data);
  225. uni.setStorageSync('userName', res.data.name);
  226. uni.setStorageSync('userId', res.data.id);
  227. dbApi.createMSGtable();
  228. dbApi.createLocalMSGtable();
  229. uni.reLaunch({
  230. url: "/pages/index/index"
  231. })
  232. });
  233. uni.hideLoading()
  234. }
  235. const register = () => {
  236. uni.reLaunch({
  237. url: "/pages/login/register"
  238. })
  239. }
  240. const resetPassword = () => {
  241. uni.navigateTo({
  242. url: '/pages/mine/zhpassword'
  243. })
  244. }
  245. const getCode = () => {
  246. getCodeImg().then((res: any) => {
  247. captchaOnOff.value = res.captchaOnOff === undefined ? true : res.captchaOnOff;
  248. if (captchaOnOff.value) {
  249. codeUrl.value = "data:image/gif;base64," + res.img;
  250. form.uuid = res.uuid;
  251. }
  252. });
  253. }
  254. getCode();
  255. </script>
  256. <style>
  257. @import url('@/static/css/main.css');
  258. .main-list {
  259. display: flex;
  260. flex-direction: row;
  261. justify-content: space-between;
  262. align-items: center;
  263. height: 80upx;
  264. /* Input 高度 */
  265. color: #333333;
  266. padding: 0 32upx;
  267. margin-top: 24upx;
  268. margin-bottom: 24upx;
  269. }
  270. .img {
  271. width: 200upx;
  272. height: 80upx;
  273. font-size: 32upx;
  274. background-color: #eee;
  275. z-index: 99999999999999;
  276. }
  277. .main-input {
  278. flex: 1;
  279. text-align: left;
  280. font-size: 28upx;
  281. /* line-height: 100upx; */
  282. padding-right: 10upx;
  283. margin-left: 20upx;
  284. }
  285. .oBorder {
  286. border: none;
  287. border-radius: 8px;
  288. border: 1rpx solid #6E75FB;
  289. -webkit-box-shadow: 0 0 60upx 0 rgba(43, 86, 112, .1);
  290. box-shadow: 0 0 60upx 0 rgba(43, 86, 112, .1);
  291. }
  292. .loading{
  293. display: flex;
  294. justify-content: center;
  295. align-items: center;
  296. }
  297. </style>