dbsd_kczx/src/views/site/utils/index.ts

97 lines
2.6 KiB
TypeScript

import { defHttp } from '/@/utils/http/axios';
import { useUserStore } from '/@/store/modules/user';
import md5 from 'md5';
import { useMessage } from '/@/hooks/web/useMessage';
/**
* 项目名称
*/
export const projectName = import.meta.env.VITE_GLOB_APP_TITLE;
/**
* 是否开启单点登录
*/
export const isOpenSSO = import.meta.env.VITE_GLOB_APP_OPEN_SSO == 'true'?true:false;
export const getUserId = () => {
console.log(`🚀 ~ file: index.ts:17 ~ getUserId ~ isOpenSSO:`, isOpenSSO)
if(isOpenSSO){
console.log(`🚀 ~ file: index.ts:17 ~ getUserId ~ isOpenSSO1:`, isOpenSSO)
const { userInfo } = useUserStore();
//正常取用户
return userInfo?.username;
}else{
console.log(`🚀 ~ file: index.ts:17 ~ getUserId ~ isOpenSSO2:`, isOpenSSO)
//固定某值
return '2016900057';//教师
// return '2022010920';//学生
}
}
//S:学生 T:教师
export const getUserSf = () => {
const { userInfo } = useUserStore();
if(userInfo?.userIdentity == 1){
return 'S';
}else if(userInfo?.userIdentity == 2){
return 'T';
}
}
/**
* 获取当前登录用户信息
*/
export const getUserInfo = () => {
const { userInfo } = useUserStore();
return userInfo??{};
}
// export const getSysConfig = () => defHttp.get({ url: '/kcSysConfig/kcSysConfig/queryById', params:{id:'1'} })
export const getSysConfig = ():any => {
const { sysConfigInfo } = useUserStore();
return sysConfigInfo??{};
}
export const getMd5Str = ( str:string ) :string => {
return md5(str);
}
export const get16BitStr = ( str:string ) :string => {
let val="";
for(let i = 0; i < str.length; i++){
if(val == "")
val = str.charCodeAt(i).toString(16);
else
// val += "," + str.charCodeAt(i).toString(16);
val += str.charCodeAt(i).toString(16);
}
return val;
}
export const getAvyCtrlBaseUrl = ( ip:string, user:string, pwd:string ) :string => {
//pam.push(`live_setParam_enable=`)
return `http://${ip}/cgi-bin/plat.cgi?action=9&user=${user}&pwsd=${getMd5Str(pwd)}&command=1`;
}
/**
* 获取奥威亚开启直播/关闭直播接口
* @param ip
* @param user
* @param pwd
* @param isEnable
* @returns
*/
export const getAvyCtrlLiveOpenOrCloseUrl = ( ip:string, user:string, pwd:string, isEnable:boolean ) :string => {
let paramStr = `live_setParam_enable=${isEnable?1:0}`;
return `${getAvyCtrlBaseUrl(ip,user,pwd)}&data=${get16BitStr(paramStr)}`;
}
export const execAvyApi = (url:string, cellback?):void => {
// const { createMessage } = useMessage();
defHttp.get({ url }).then(res => {
cellback?cellback(res):null;
console.log('奥威亚返回内容',res);
// createMessage.success("操作成功");
})
}