| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- import {
- axios,
- userLogin,
- uploadFile as uploadFileUrl,
- userInfo,
- } from "@/request";
- import { encodePwd } from "@/util";
- import { user } from "./user";
- import { refreshRole } from "./role";
- import { appConstant } from "@/app";
- import { ref, watchEffect, reactive } from "vue";
- export type LoginProps = {
- phoneNum: string;
- code: string;
- password: string;
- deptId?: string;
- };
- export const title = ref(appConstant.title);
- export const desc = ref(appConstant.desc);
- console.log('appConstant', appConstant, title.value + (desc.value ? " | " + desc.value : ""));
- watchEffect(
- () => (document.title = title.value + (desc.value ? " | " + desc.value : ""))
- );
- const refreshUserInfo = async (data: any) => {
- user.value.info = data;
- await refreshRole();
- };
- export const login = async (props: LoginProps) => {
- const res = await axios.post(userLogin, {
- deptId: appConstant.deptId,
- ...props,
- password: encodePwd(props.password),
- });
- user.value.token = res.data.token;
- refreshUserInfo(res.data.tmUser);
- };
- if (user.value.token) {
- axios.get(userInfo).then((res) => {
- refreshUserInfo(res.data);
- });
- }
- export const uploadFile = async (file: File) => {
- return (await axios.post<string>(uploadFileUrl, { file })).data;
- };
- export const appEl = ref<HTMLDivElement | null>(null);
- let currentTempIndex = 0;
- export const isTemploraryID = (id: string) =>
- id.includes("__currentTempIndex__");
- export const createTemploraryID = () =>
- `__currentTempIndex__${currentTempIndex++}`;
- export const recordFragments = ref<any>([])
- export const getRecordFragments = (record: any) => recordFragments.value.filter(fragment => fragment.recordId === record.id)
- export const getRecordFragmentBlobs = (record) => getRecordFragments(record)
- .filter(fragment => typeof fragment.url !== 'string')
- .map(fragment => fragment.url as Blob)
- export const createRecordFragment = (recordFragment: Partial<any> = {}): any => ({
- id: createTemploraryID(),
- recordId: '',
- cover: '',
- url: '',
- sort: Math.min(...recordFragments.value.map(item => item.sort)) + 1,
- ...recordFragment
- })
- // 字符串转params对象
- export const strToParams = (str: string) => {
- if (str[0] === '?') {
- str = str.substr(1)
- }
- const result: { [key: string]: string } = {}
- const splitRG = /([^=&]+)(?:=([^&]*))?&?/
- let rgRet
- while ((rgRet = str.match(splitRG))) {
- result[rgRet[1]] = rgRet[2] === undefined ? '' : rgRet[2]
- str = str.substr(rgRet[0].length)
- }
- return result
- }
- export const params = reactive(
- strToParams(location.search)
- ) as any
- export const baseURL = params.baseURL ? params.baseURL : "";
- export const getResource = (uri: string) => {
- if (~uri.indexOf("base64") || ~uri.indexOf("bolb") || ~uri.indexOf("//"))
- return uri;
- if (uri[0] === "/") {
- return `${baseURL}${uri}`;
- } else {
- return `${baseURL}/${uri}`;
- }
- };
|