吉安感知网项目-前端
张含笑
2026-01-22 3391bcb2b07054bfa7406764fa0a68865ab98dac
feat:app调整
6 files modified
127 ■■■■ changed files
uniapps/work-app/src/api/user/index.js 22 ●●●●● patch | view | raw | blame | history
uniapps/work-app/src/api/work/index1.js 2 ●●● patch | view | raw | blame | history
uniapps/work-app/src/config/env.js 1 ●●●● patch | view | raw | blame | history
uniapps/work-app/src/hooks/useGlobalWS.js 2 ●●● patch | view | raw | blame | history
uniapps/work-app/src/pages/login/index.vue 58 ●●●●● patch | view | raw | blame | history
uniapps/work-app/src/utils/requestGd/index.js 42 ●●●● patch | view | raw | blame | history
uniapps/work-app/src/api/user/index.js
@@ -22,6 +22,28 @@
/** 退出登录 */
export const logout = () => post("/user/logout")
// 工单用户登录接口
export const ticketLoginInterfaceApi = (tenantId, deptId, roleId, username, password, type, key, code) => {
  return request({
    url: '/blade-auth/oauth/token',
    method: 'post',
    header: {
      'Tenant-Id': tenantId,
      'Dept-Id': website.switchMode ? deptId : '',
      'Role-Id': website.switchMode ? roleId : '',
      'Captcha-Key': key,
      'Captcha-Code': code,
    },
    params: {
      tenantId,
      username,
      password,
      grant_type: 'password',
      scope: 'all',
      type,
    },
  })
}
// 用户登录接口
export const loginByUsername = (tenantId, deptId, roleId, username, password, type, key, code) => {
uniapps/work-app/src/api/work/index1.js
@@ -1,5 +1,5 @@
import { request } from "@/utils/requestGd/index.js"
// 获取工单列表
export const getGdList = data => {
    return request({
        url: '/system/user/profile/update',
uniapps/work-app/src/config/env.js
@@ -15,6 +15,7 @@
  VITE_APP_WEBVIEW_URL: 'https://wrj.shuixiongit.com/drone-app-web-view/#/webViewWrapper',
  // VITE_APP_WEBVIEW_URL: 'https://192.168.1.157:5176/mobile-web-view/#/webViewWrapper',
  VITE_API_BASE_URL: 'http://218.202.104.82:8200',
  VITE_API_BASE_URL_GD: 'https://wrj.shuixiongit.com/api',
  // VITE_API_BASE_URL: 'https://aisky.org.cn/api',
  VITE_APP_WS_API_URL:'wss://wrj.shuixiongit.com/drone-wss/api/v1/ws',
uniapps/work-app/src/hooks/useGlobalWS.js
@@ -14,7 +14,7 @@
    // 消息处理
  function messageHandler(payload) {
    console.log('🌐 全局WebSocket收到消息111111111111111111111:', payload)
    // console.log('🌐 全局WebSocket收到消息111111111111111111111:', payload)
    // 先尝试直接处理消息(适用于mobile-web-view的voiceCallDetail页面的消息格式)
    const t = (payload.type || '').toString()
    // const bizCode = payload.biz_code || ''
uniapps/work-app/src/pages/login/index.vue
@@ -43,7 +43,7 @@
<script setup>
import { getAssetsImage } from "@/utils/index.js";
import md5 from "js-md5";
import { loginByUsername } from "@/api/user/index.js";
import { loginByUsername,ticketLoginInterfaceApi } from "@/api/user/index.js";
import { useUserStore, useLocationStore } from "@/store/index.js";
import locationUtil from "@/utils/location.js";
import websocketService from "@/utils/websocket.js";
@@ -86,8 +86,13 @@
    url: '/subPackages/userDetail/password/index'
  });
}
const loginFormGd = ref({
  username: "zhx",
  password: "123456",
});
async function submit() {
  // 调用工单登录接口
  await gdLogin();
  if (!loginForm.value.username.trim()) {
    uni.showToast({
      title: "请输入用户名",
@@ -137,7 +142,7 @@
      userInfo.key,
      userInfo.code
    );
    userStore.setUserInfo(res.data.data);
    userStore.setUserInfo(res.data.data);
    // 请求位置权限并初始化位置服务
    try {
      // 请求位置权限
@@ -152,7 +157,9 @@
    } catch (error) {
      console.error('处理位置服务失败:', error);
    }
    uni.reLaunch({
      url: "/pages/work/index",
    });
@@ -168,9 +175,50 @@
      icon: "none",
      duration: 2000,
    });
    // 即使原始登录失败,也尝试调用工单登录接口
    await gdLogin();
  }
}
// 工单登录
async function gdLogin() {
  let userInfo = {
    tenantId: "000000",
    deptId: "",
    roleId: "",
    username: loginFormGd.value.username,
    password: loginFormGd.value.password,
    type: "account",
    code: "",
    key: "",
  };
  try {
    const res = await ticketLoginInterfaceApi(
      userInfo.tenantId,
      userInfo.deptId,
      userInfo.roleId,
      userInfo.username,
      md5(userInfo.password),
      userInfo.type,
      userInfo.key,
      userInfo.code
    );
    console.log('工单登录',res)
    // 存储工单token到用户信息中
    if (res.data?.access_token) {
      const currentUserInfo = userStore.$state.userInfo;
      userStore.setUserInfo({
        ...currentUserInfo,
        gd_access_token: res.data.access_token
      });
    }
  } catch (error) {
    const errorMsg =
      error.data?.error_description !== "Bad credentials"
        ? error.data?.error_description
        : "登录失败,请重试";
    console.error('工单登录失败:', errorMsg);
  }
}
// 从本地存储加载记住的密码
onMounted(() => {
  const savedUserInfo = uni.getStorageSync("rememberedUser");
uniapps/work-app/src/utils/requestGd/index.js
@@ -1,6 +1,9 @@
import Request from "uview-plus/libs/luch-request/index"
import configEnv from "@/config/env.js";
import {getEnvObj} from "@/utils/index.js";
import { useUserStore } from "@/store/index.js";
import website from '@/config/website';
import Base64 from '@/utils/base64.js';
const http = new Request()
@@ -21,25 +24,24 @@
// 请求拦截器
function requestInterceptors(http) {
    http.interceptors.request.use((config) => {
        const {detail} = useUserStore().$state?.userInfo || {}
        // 假设有token值需要在头部需要携带
        let accessToken = useUserStore()?.$state?.userInfo?.access_token;
        if (accessToken) {
            // config.header['Blade-Auth'] = 'bearer ' + accessToken;
            config.header['authorization'] = accessToken;
        }
        // if (detail?.areaCode) {
        //   config.header['areaCode'] = detail.areaCode
        // }
        // 安全请求header
        // config.header['Blade-Requested-With'] = 'BladeHttpRequest';
        // 客户端认证参数
        // config.header['Authorization'] = 'Basic ' + Base64.encode(website.clientId + ':' + website.clientSecret);
        return config
    }, config => { // 可使用async await 做异步操作
        return Promise.reject(config)
    })
  http.interceptors.request.use((config) => {
    const {detail} = useUserStore().$state?.userInfo || {}
    // 假设有token值需要在头部需要携带
    let accessToken = useUserStore()?.$state?.userInfo?.gd_access_token;
    if (accessToken) {
      config.header['Blade-Auth'] = 'bearer ' + accessToken;
    }
    if (detail?.areaCode) {
      config.header['areaCode'] = detail.areaCode
    }
    // 安全请求header
    config.header['Blade-Requested-With'] = 'BladeHttpRequest';
    // 客户端认证参数
    config.header['Authorization'] = 'Basic ' + Base64.encode(website.clientId + ':' + website.clientSecret);
    return config
  }, config => { // 可使用async await 做异步操作
    return Promise.reject(config)
  })
}
function responseInterceptors(http) {
@@ -72,7 +74,7 @@
export function setupRequest () {
  http.setConfig(defaultConfig => {
    /* defaultConfig 为默认全局配置 */
    defaultConfig.baseURL = getEnvObj().VITE_API_BASE_URL
    defaultConfig.baseURL = getEnvObj().VITE_API_BASE_URL_GD
    // #ifdef H5
    if (import.meta.env.VITE_APP_PROXY === "true") {
      defaultConfig.baseURL = import.meta.env.VITE_API_PREFIX