api增加ts

This commit is contained in:
xiangheng
2024-06-07 15:45:15 +08:00
parent 3ba60a3d49
commit f8e51648d3
35 changed files with 401 additions and 127 deletions

View File

@@ -9,7 +9,8 @@
"preview": "vite preview --port 4173",
"build": "node ./scripts/build.mjs",
"type-check": "vue-tsc --noEmit --checkJs true --skipLibCheck",
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore"
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",
"preinstall": "npx only-allow pnpm"
},
"dependencies": {
"@element-plus/icons-vue": "^2.3.1",

View File

@@ -0,0 +1,71 @@
import request from '@/utils/request'
import type { Pages } from '@/utils/request'
import config from '@/config'
import queryString from 'query-string'
import { getToken } from '@/utils/auth'
type album_cate = {
id?: number
pid?: number
type?: number
name?: string
isDelete?: number
createTime?: string
updateTime?: string
deleteTime?: string
}
// 查询
type album_cate_query = {
pid?: number
type?: number
name?: string
createTime?: string
updateTime?: string
}
// 添加编辑
type album_cate_edit = {
id?: number
pid?: number
type?: number
name?: string
}
// 相册分类列表
export function album_cate_list(params?: album_cate_query) {
return request.get<Pages<album_cate>>({ url: '/album_cate/list', params })
}
// 相册分类列表-所有
export function album_cate_list_all(params?: album_cate_query) {
return request.get<Pages<album_cate>>({ url: '/album_cate/listAll', params })
}
// 相册分类详情
export function album_cate_detail(id: number | string) {
return request.get<album_cate>({ url: '/album_cate/detail', params: { id } })
}
// 相册分类新增
export function album_cate_add(data: album_cate_edit) {
return request.post<null>({ url: '/album_cate/add', data })
}
// 相册分类编辑
export function album_cate_edit(data: album_cate_edit) {
return request.post<null>({ url: '/album_cate/edit', data })
}
// 相册分类删除
export function album_cate_delete(id: number | string) {
return request.post<null>({ url: '/album_cate/del', data: { id } })
}
// 相册分类导入
export const album_cate_import_file = '/album_cate/ImportFile'
// 相册分类导出
export function album_cate_export_file(params: any) {
return (window.location.href =
`${config.baseUrl}${config.urlPrefix}/album_cate/ExportFile?token=${getToken()}&` +
queryString.stringify(params))
}

View File

@@ -67,8 +67,8 @@
* VerifyPoints
* @description 点选
* */
import { resetSize } from './../utils/util'
import { aesEncrypt } from './../utils/ase'
import { resetSize } from '../utils/util'
import { aesEncrypt } from '../utils/ase'
import { reqGet, reqCheck } from '../api/index'
import { onMounted, reactive, ref, nextTick, toRefs, getCurrentInstance } from 'vue'
export default {

View File

@@ -94,7 +94,7 @@
* VerifySlide
* @description 滑块
* */
import { aesEncrypt } from './../utils/ase'
import { aesEncrypt } from '../utils/ase'
import { resetSize } from './../utils/util'
import { reqGet, reqCheck } from './../api/index'
import { computed, onMounted, reactive, ref, nextTick, toRefs, getCurrentInstance } from 'vue'

View File

@@ -13,6 +13,18 @@ import type { AxiosResponse } from 'axios'
import router from '@/router'
import { PageEnum } from '@/enums/pageEnum'
export interface Pages<T> {
count: number
lists: T[]
pageNo: number
pageSize: number
}
export interface Response<T> {
code: number
message: string
data: T
}
// 处理axios的钩子函数
const axiosHooks: AxiosHooks = {
requestInterceptorsHook(config) {

View File

@@ -1,6 +1,21 @@
import { isObject } from '@vue/shared'
import { cloneDeep } from 'lodash-es'
// import { md5 } from 'js-md5'
import MD5 from 'crypto-js/md5'
/**
* 密码加密
* @param {String} password 密码
* @param {String} beforeSalt 前置盐
* @param {String} afterSalt 后置盐
* @returns {String} 加密后的密码
*/
export const encryptPassword = (
password: string,
beforeSalt = 'opuoaqwehjkyuisdf',
afterSalt = 'asdjioewurtjfgiopu'
): string => {
return MD5(beforeSalt + MD5(password).toString() + afterSalt).toString()
}
/**
* @description 添加单位
* @param {String | Number} value 值 100

View File

@@ -22,8 +22,8 @@ type {{{ title (toCamelCase .ModuleName) }}}Handler struct {}
{{{- range .Columns }}}
{{{- if .IsQuery }}}
{{{- if eq .HtmlType "datetime" }}}
// @Param {{{ title (toCamelCase .ColumnName) }}}Start query {{{ .GoType }}} false "{{{ .ColumnComment }}}."
// @Param {{{ title (toCamelCase .ColumnName) }}}End query {{{ .GoType }}} false "{{{ .ColumnComment }}}."
// @Param {{{ toCamelCase .GoField }}}Start query {{{ .GoType }}} false "{{{ .ColumnComment }}}."
// @Param {{{ toCamelCase .GoField }}}End query {{{ .GoType }}} false "{{{ .ColumnComment }}}."
{{{- else }}}
// @Param {{{ toCamelCase .GoField }}} query {{{ .GoType }}} false "{{{ .ColumnComment }}}."
{{{- end }}}
@@ -51,8 +51,8 @@ func (hd {{{ title (toCamelCase .ModuleName) }}}Handler) List(c *gin.Context) {
{{{- range .Columns }}}
{{{- if .IsQuery }}}
{{{- if eq .HtmlType "datetime" }}}
// @Param {{{ title (toCamelCase .ColumnName) }}}Start query {{{ .GoType }}} false "{{{ .ColumnComment }}}."
// @Param {{{ title (toCamelCase .ColumnName) }}}End query {{{ .GoType }}} false "{{{ .ColumnComment }}}."
// @Param {{{ toCamelCase .GoField }}}Start query {{{ .GoType }}} false "{{{ .ColumnComment }}}."
// @Param {{{ toCamelCase .GoField }}}End query {{{ .GoType }}} false "{{{ .ColumnComment }}}."
{{{- else }}}
// @Param {{{ toCamelCase .GoField }}} query {{{ .GoType }}} false "{{{ .ColumnComment }}}."
{{{- end }}}

View File

@@ -1,17 +1,44 @@
import { request } from '@/utils/request'
import type { Pages } from '@/utils/request'
type {{{.ModuleName}}} = {
{{{- range .Columns }}}
{{{ toCamelCase .GoField }}}: {{{goToTsType .GoType}}};
{{{- end }}}
}
// 查询
type {{{.ModuleName}}}_query = {
{{{- range .Columns }}}
{{{- if .IsQuery }}}
{{{- if eq .HtmlType "datetime" }}}
{{{ toCamelCase .GoField }}}Start: string;
{{{ toCamelCase .GoField }}}End: string;
{{{- else }}}
{{{ toCamelCase .GoField }}}?: {{{goToTsType .GoType}}};
{{{- end }}}
{{{- end }}}
{{{- end }}}
}
// 添加编辑
type {{{.ModuleName}}}_edit = {
{{{- range .Columns }}}
{{{- if or .IsEdit .IsInsert }}}
{{{ toCamelCase .GoField }}}?: {{{goToTsType .GoType}}};
{{{- end }}}
{{{- end }}}
}
// {{{.FunctionName}}}列表
export function {{{.ModuleName}}}_list(params?: Record<string, any>) {
return request({
export function {{{.ModuleName}}}_list(params?: {{{.ModuleName}}}_query) {
return request<Pages<{{{.ModuleName}}}>>({
url: '/{{{.ModuleName}}}/list',
method: 'GET',
data: params
})
}
// {{{.FunctionName}}}列表-所有
export function {{{.ModuleName}}}_list_all(params?: Record<string, any>) {
return request({
export function {{{.ModuleName}}}_list_all(params?: {{{.ModuleName}}}_query) {
return request<{{{.ModuleName}}}[]>({
url: '/{{{.ModuleName}}}/listAll',
method: 'GET',
data: params
@@ -20,7 +47,7 @@ export function {{{.ModuleName}}}_list_all(params?: Record<string, any>) {
// {{{.FunctionName}}}详情
export function {{{.ModuleName}}}_detail({{{ .PrimaryKey }}}: number | string) {
return request({
return request<{{{.ModuleName}}}>({
url: '/{{{.ModuleName}}}/detail',
method: 'GET',
data: { {{{ .PrimaryKey }}} }
@@ -28,8 +55,8 @@ export function {{{.ModuleName}}}_detail({{{ .PrimaryKey }}}: number | string) {
}
// {{{.FunctionName}}}新增
export function {{{.ModuleName}}}_add(data: Record<string, any>) {
return request({
export function {{{.ModuleName}}}_add(data: {{{.ModuleName}}}_edit) {
return request<null>({
url: '/{{{.ModuleName}}}/add',
method: "POST",
data,
@@ -37,8 +64,8 @@ export function {{{.ModuleName}}}_add(data: Record<string, any>) {
}
// {{{.FunctionName}}}编辑
export function {{{.ModuleName}}}_edit(data: Record<string, any>) {
return request({
export function {{{.ModuleName}}}_edit(data: {{{.ModuleName}}}_edit) {
return request<null>({
url: '/{{{.ModuleName}}}/edit',
method: "POST",
data,
@@ -47,7 +74,7 @@ export function {{{.ModuleName}}}_edit(data: Record<string, any>) {
// {{{.FunctionName}}}删除
export function {{{.ModuleName}}}_delete({{{ .PrimaryKey }}}: number | string) {
return request({
return request<null>({
url: '/{{{.ModuleName}}}/del',
method: "POST",
data:{

View File

@@ -56,7 +56,13 @@
toPath
} from "@/utils/utils";
let form = ref({});
let form = ref({
{{{- range .Columns }}}
{{{- if or .IsList .IsPk }}}
{{{ toCamelCase .GoField }}}: "",
{{{- end }}}
{{{- end }}}
});
{{{- if ge (len .DictFields) 1 }}}
{{{- $dictSize := sub (len .DictFields) 1 }}}
const { dictData } = useDictData([{{{- range .DictFields }}}'{{{ . }}}'{{{- if ne (index $.DictFields $dictSize) . }}},{{{- end }}}{{{- end }}}])

View File

@@ -71,8 +71,16 @@ import { {{{ .ModuleName }}}_list } from "@/api/{{{ .ModuleName }}}";
import { usePaging } from "@/hooks/usePaging";
import { toPath } from "@/utils/utils";
const queryParams = reactive({
key: "",
{{{- range .Columns }}}
{{{- if .IsQuery }}}
{{{- if eq .HtmlType "datetime" }}}
{{{ (toCamelCase .GoField) }}}Start: '',
{{{ (toCamelCase .GoField) }}}End: '',
{{{- else }}}
{{{ (toCamelCase .GoField) }}}: '',
{{{- end }}}
{{{- end }}}
{{{- end }}}
});
let fromSearch=ref(false);
onLoad((e) => {

View File

@@ -1,36 +1,64 @@
import request from '@/utils/request'
import type { Pages } from '@/utils/request'
import config from '@/config'
import queryString from 'query-string'
import { getToken } from '@/utils/auth'
type {{{.ModuleName}}} = {
{{{- range .Columns }}}
{{{ toCamelCase .GoField }}}: {{{goToTsType .GoType}}};
{{{- end }}}
}
// 查询
type {{{.ModuleName}}}_query = {
{{{- range .Columns }}}
{{{- if .IsQuery }}}
{{{- if eq .HtmlType "datetime" }}}
{{{ toCamelCase .GoField }}}Start: string;
{{{ toCamelCase .GoField }}}End:string;
{{{- else }}}
{{{ toCamelCase .GoField }}}?: {{{goToTsType .GoType}}};
{{{- end }}}
{{{- end }}}
{{{- end }}}
}
// 添加编辑
type {{{.ModuleName}}}_edit = {
{{{- range .Columns }}}
{{{- if or .IsEdit .IsInsert }}}
{{{ toCamelCase .GoField }}}?: {{{goToTsType .GoType}}};
{{{- end }}}
{{{- end }}}
}
// {{{.FunctionName}}}列表
export function {{{.ModuleName}}}_list(params?: Record<string, any>) {
return request.get({ url: '/{{{.ModuleName}}}/list', params })
export function {{{.ModuleName}}}_list(params?: {{{.ModuleName}}}_query) {
return request.get<Pages<{{{.ModuleName}}}>>({ url: '/{{{.ModuleName}}}/list', params })
}
// {{{.FunctionName}}}列表-所有
export function {{{.ModuleName}}}_list_all(params?: Record<string, any>) {
return request.get({ url: '/{{{.ModuleName}}}/listAll', params })
export function {{{.ModuleName}}}_list_all(params?: {{{.ModuleName}}}_query) {
return request.get<Pages<{{{.ModuleName}}}>>({ url: '/{{{.ModuleName}}}/listAll', params })
}
// {{{.FunctionName}}}详情
export function {{{.ModuleName}}}_detail({{{ .PrimaryKey }}}: number | string) {
return request.get({ url: '/{{{.ModuleName}}}/detail', { {{{ .PrimaryKey }}} } })
return request.get<{{{.ModuleName}}}>({ url: '/{{{.ModuleName}}}/detail', params: { {{{ .PrimaryKey }}} } })
}
// {{{.FunctionName}}}新增
export function {{{.ModuleName}}}_add(data: Record<string, any>) {
return request.post({ url: '/{{{.ModuleName}}}/add', data })
export function {{{.ModuleName}}}_add(data: {{{.ModuleName}}}_edit) {
return request.post<null>({ url: '/{{{.ModuleName}}}/add', data })
}
// {{{.FunctionName}}}编辑
export function {{{.ModuleName}}}_edit(data: Record<string, any>) {
return request.post({ url: '/{{{.ModuleName}}}/edit', data })
export function {{{.ModuleName}}}_edit(data: {{{.ModuleName}}}_edit) {
return request.post<null>({ url: '/{{{.ModuleName}}}/edit', data })
}
// {{{.FunctionName}}}删除
export function {{{.ModuleName}}}_delete({{{ .PrimaryKey }}}: number | string) {
return request.post({ url: '/{{{.ModuleName}}}/del', { {{{ .PrimaryKey }}} } })
return request.post<null>({ url: '/{{{.ModuleName}}}/del', data: { {{{ .PrimaryKey }}} } })
}
// {{{.FunctionName}}}导入

View File

@@ -23,6 +23,7 @@ var TemplateUtil = templateUtil{
"toSnakeCase": util.StringUtil.ToSnakeCase,
"toCamelCase": util.StringUtil.ToCamelCase,
"contains": util.ToolsUtil.Contains,
"goToTsType": util.ToolsUtil.GoToTsType,
}),
}

View File

@@ -106,14 +106,14 @@ func Copy(toValue interface{}, fromValue interface{}) interface{} {
// Ok 正常响应
func Ok(c *gin.Context) {
Result(c, Success, []string{})
Result(c, Success, nil)
}
// OkWithMsg 正常响应附带msg
func OkWithMsg(c *gin.Context, message string) {
resp := Success
resp.message = message
Result(c, resp, []string{})
Result(c, resp, nil)
}
// OkWithData 正常响应附带data
@@ -133,14 +133,14 @@ func respLogger(resp RespType, template string, args ...interface{}) {
// Fail 错误响应
func Fail(c *gin.Context, resp RespType) {
respLogger(resp, "Request Fail: url=[%s], resp=[%+v]", c.Request.URL.Path, resp)
Result(c, resp, []string{})
Result(c, resp, nil)
}
// FailWithMsg 错误响应附带msg
func FailWithMsg(c *gin.Context, resp RespType, message string) {
resp.message = message
respLogger(resp, "Request FailWithMsg: url=[%s], resp=[%+v]", c.Request.URL.Path, resp)
Result(c, resp, []string{})
Result(c, resp, nil)
}
// FailWithData 错误响应附带data
@@ -159,7 +159,7 @@ func IsFailWithResp(c *gin.Context, err error) bool {
case RespType:
data := v.Data()
if data == nil {
data = []string{}
data = nil
}
FailWithData(c, v, data)
// 其他类型

View File

@@ -69,6 +69,34 @@ func (tu toolsUtil) Contains(src interface{}, elem interface{}) bool {
return false
}
/**
* @description: Go类型转TS类型
*/
func (tu toolsUtil) GoToTsType(s string) string {
if s == "int" || s == "int8" || s == "int16" || s == "int32" || s == "int64" {
return "number"
} else if s == "float" || s == "float32" || s == "float64" {
return "number"
} else if s == "string" {
return "string"
} else if s == "bool" {
return "boolean"
} else if s == "time.Time" {
return "Date"
} else if s == "[]byte" {
return "string"
} else if s == "[]string" {
return "string[]"
} else if s == "[]int" {
return "number[]"
} else if s == "[]float" {
return "number[]"
} else if s == "core.TsTime" {
return "string"
}
return "string"
}
// Round float四舍五入
func (tu toolsUtil) Round(val float64, n int) float64 {
base := math.Pow(10, float64(n))

View File

@@ -1,17 +1,24 @@
import { request } from '@/utils/request'
import type { Pages } from '@/utils/request'
type monitor_project= {
id?: number;
projectName?: string;
projectType?: string;
projectKey?: string;
updateTime?: string;
createTime?: string;
}
// 监控项目列表
export function monitor_project_list(params?: Record<string, any>) {
return request({
export function monitor_project_list(params?: monitor_project) {
return request<Pages<monitor_project>>({
url: '/monitor_project/list',
method: 'GET',
data: params
})
}
// 监控项目列表-所有
export function monitor_project_list_all(params?: Record<string, any>) {
return request({
export function monitor_project_list_all(params?: monitor_project) {
return request<monitor_project[]>({
url: '/monitor_project/listAll',
method: 'GET',
data: params
@@ -20,7 +27,7 @@ export function monitor_project_list_all(params?: Record<string, any>) {
// 监控项目详情
export function monitor_project_detail(id: number | string) {
return request({
return request<monitor_project>({
url: '/monitor_project/detail',
method: 'GET',
data: { id }
@@ -28,8 +35,8 @@ export function monitor_project_detail(id: number | string) {
}
// 监控项目新增
export function monitor_project_add(data: Record<string, any>) {
return request({
export function monitor_project_add(data: monitor_project) {
return request<null>({
url: '/monitor_project/add',
method: "POST",
data,
@@ -37,8 +44,8 @@ export function monitor_project_add(data: Record<string, any>) {
}
// 监控项目编辑
export function monitor_project_edit(data: Record<string, any>) {
return request({
export function monitor_project_edit(data: monitor_project) {
return request<null>({
url: '/monitor_project/edit',
method: "POST",
data,
@@ -47,7 +54,7 @@ export function monitor_project_edit(data: Record<string, any>) {
// 监控项目删除
export function monitor_project_delete(id: number | string) {
return request({
return request<null>({
url: '/monitor_project/del',
method: "POST",
data:{

View File

@@ -1,29 +0,0 @@
import {request} from '@/utils/request';
export function login(data) {
return request({
url: '/system/login',
method: 'POST',
data
})
}
export function getInfo(token) {
return request({
url: '/system/admin/self',
method: 'GET',
data: {
token
}
})
}
export function logout() {
return request({
url: '/system/logout',
method: 'GET'
})
}

44
x_admin_app/api/user.ts Normal file
View File

@@ -0,0 +1,44 @@
import { request } from "@/utils/request";
// import type {Response} from '@/utils/request';
export function login(data: any) {
return request<{
token: string;
}>({
url: "/system/login",
method: "POST",
data,
});
}
export function getInfo(token: string) {
return request<{
permissions: string[];
user: {
avatar: string;
createTime: string;
dept: string;
id: number;
isDisable: number;
lastLoginIp: string;
lastLoginTime: string;
nickname: string;
role: string;
updateTime: string;
username: string;
};
}>({
url: "/system/admin/self",
method: "GET",
data: {
token,
},
});
}
export function logout() {
return request({
url: "/system/logout",
method: "GET",
});
}

View File

@@ -1,5 +1,5 @@
import { perms } from "@/utils/perms.js";
import { toPath } from "@/utils/utils.js";
import { perms } from "@/utils/perms";
import { toPath } from "@/utils/utils";
import env from "@/utils/env";
/**

View File

@@ -13,7 +13,7 @@
</view>
</template>
<script setup>
<script setup lang="ts">
import {
ref
} from "vue";
@@ -23,7 +23,7 @@
toast,
scanCode,
queryToObj,
} from "@/utils/utils.js";
} from "@/utils/utils";
let list = [
"https://cdn.uviewui.com/uview/swiper/swiper1.png",

View File

@@ -50,11 +50,12 @@
<script lang="ts" setup>
import { ref, reactive ,shallowRef} from "vue";
import uvForm from "@/uni_modules/uv-form/components/uv-form/uv-form.vue";
import Verify from "@/components/verify/verify.vue";
import { login } from "@/api/user.js";
import { setLocalStorage } from "@/utils/storage.js";
import { alert } from "@/utils/utils.js";
import { login } from "@/api/user";
import { setLocalStorage } from "@/utils/storage";
import { alert ,encryptPassword} from "@/utils/utils";
// import appicon from "@/static/appicon.png";
import { useUserStore } from "@/stores/user";
@@ -108,7 +109,7 @@ function VerifySuccess(e) {
function handleSubmit(verify) {
let data = {
username: model.username,
password: model.password,
password:(model.password),
...verify,
};

View File

@@ -60,7 +60,14 @@
toPath
} from "@/utils/utils";
let form = ref({});
let form = ref({
id: 0,
projectKey: "",
projectName: "",
projectType: "",
createTime: "",
updateTime: "",
});
onLoad((e) => {
console.log("onLoad", e);
getDetails(e.id);
@@ -77,7 +84,7 @@
monitor_project_detail(id).then((res) => {
uni.stopPullDownRefresh();
if (res.code == 200) {
if (res?.data) {
if (res.data) {
form.value = res?.data
}
} else {

View File

@@ -1,7 +1,7 @@
import { defineStore } from "pinia";
import { logout, getInfo } from "@/api/user";
import { getLocalStorage, removeLocalStorage } from "@/utils/storage.js";
import { getLocalStorage, removeLocalStorage } from "@/utils/storage";
export const useUserStore = defineStore("user", {
state: () => {
@@ -55,7 +55,7 @@ export const useUserStore = defineStore("user", {
.then(() => {
// resetRouter();
this.resetToken();
resolve();
resolve(true);
})
.catch((error) => {
reject(error);
@@ -67,10 +67,12 @@ export const useUserStore = defineStore("user", {
resetToken() {
return new Promise((resolve) => {
// this.token = "";
this.name = "";
this.nickname = '';
this.username = "";
this.avatar = "";
removeLocalStorage("token");
resolve();
resolve(true);
});
},
},

View File

@@ -8,7 +8,7 @@
"stores/**/*",
"utils/**/*",
"typings/**/*.d.ts",
"hooks/usePaging.ts"
"hooks/**/*"
],
"exclude": ["dist", "node_modules", "uni_modules", "unpackage"],
@@ -24,6 +24,6 @@
"paths": {
"@/*": ["./*"]
},
"types": ["@dcloudio/types", "@uni-helper/uni-app-types"]
"types": ["@dcloudio/types", "@uni-helper/uni-app-types","./uni_modules/wot-design-uni/global.d.ts"]
}
}

View File

@@ -1,6 +1,8 @@
declare module 'vue' {
interface ComponentCustomProperties {
$filePath: (typeof import('@/methods/index'))['filePath']
$filePath: (typeof import('@/methods/index'))['filePath'],
$perms: (typeof import('@/utils/perms'))['perms']
}
}

View File

@@ -1,5 +1,11 @@
import { toast } from "@/utils/utils";
/**
*
* @param {number} lat: 纬度gcj02
* @param {number} lon: 经度
* @param {string} title: 地址
*/
export function openMap(lat, lon, title) {
// #ifdef APP-PLUS
openGaoDe(lat, lon, title).catch(() => {
@@ -36,7 +42,7 @@ function openGaoDe(lat, lon, title) {
reject();
});
setTimeout(() => {
resolve();
resolve(true);
}, 1000);
});
}
@@ -57,12 +63,15 @@ function openBaidu(lat, lon, title) {
reject();
});
setTimeout(() => {
resolve();
resolve(true);
}, 1000);
});
}
/**
*
* @param {number} lat: 纬度gcj02
* @param {number} lon: 经度
* @param {string} title: 地址
*/
function openGaoDeWeb(lat, lon, title) {
let gaodeURl = `https://uri.amap.com/marker?position=${lon},${lat}&name=${title}&src=uni.UNIF9B953B&coordinate=gaode&callnative=1`;

View File

@@ -1,6 +1,6 @@
import { useUserStore } from "@/stores/user";
export const perms = (perms) => {
export const perms = (perms:string) => {
if (!perms) return true;
const userStore = useUserStore();
const auth = userStore.auth;

View File

@@ -1,27 +1,39 @@
import env from "@/utils/env";
import {
getLocalStorage
} from "@/utils/storage.js";
let requestNumber = 0; // 请求计数
function openLoading() {
if (requestNumber <= 0) {
uni.showLoading({
title: "请求中",
mask: true,
});
}
requestNumber++;
}
} from "@/utils/storage";
// let requestNumber = 0; // 请求计数
// function openLoading() {
// if (requestNumber <= 0) {
// uni.showLoading({
// title: "请求中",
// mask: true,
// });
// }
// requestNumber++;
// }
function closeLoading() {
// requestNumber--;
// if (requestNumber == 0) {
// uni.hideLoading();
// } else {
// }
}
// function closeLoading() {
// requestNumber--;
// if (requestNumber == 0) {
// uni.hideLoading();
// } else {
// }
// }
export function request(options = {}) {
export interface Pages<T> {
count: number;
lists: T[];
pageNo: number ;
pageSize: number;
}
export interface Response<T> {
code:number,
message:string,
data:T
}
export function request<T>(options:Record<string,any> = {}):Promise<Response<T>> {
options.url = `${env.baseUrl}${env.urlPrefix}${options.url}`;
var token = getLocalStorage("token");
var opts = {
@@ -41,6 +53,7 @@ export function request(options = {}) {
uni.request({
...opts,
...options,
url: options.url,
success: function(res) {
// requestNumber--;
// uni.hideLoading()
@@ -48,6 +61,7 @@ export function request(options = {}) {
request: options,
response: res.data
});
var data=res.data as Response<T>;
if (res.statusCode == 401) {
// token过期
// reject(new Error('登录失效,请重新登录'));
@@ -55,9 +69,9 @@ export function request(options = {}) {
url: "/pages/login/login",
});
} else if (res.statusCode !== 200) {
reject(new Error(res.data.message));
reject(new Error(data?.message));
} else {
resolve(res.data);
resolve(data);
}
},
@@ -73,7 +87,7 @@ export function request(options = {}) {
});
});
}
export function upload(options = {}) {
export function upload(options:Record<string,any> = {}) {
options.url = `${env.baseUrl}${options.url}`;
var token = getLocalStorage("token");
@@ -85,7 +99,9 @@ export function upload(options = {}) {
// 发送 HTTP 请求
uni.uploadFile({
name: "file",
...options,
url: options.url,
header: {
...header,
},
@@ -111,7 +127,7 @@ export function upload(options = {}) {
});
}
export function download(options = {}) {
export function download(options:Record<string,any> = {}) {
options.url = `${env.baseUrl}${options.url}`;
var token = getLocalStorage("token");
@@ -127,6 +143,7 @@ export function download(options = {}) {
header: {
...header,
},
url: options.url,
success: function(res) {
// console.log("Content-Disposition", res.header["Content-Disposition"]);
// var fileName = decodeURIComponent(
@@ -135,7 +152,9 @@ export function download(options = {}) {
if (res.statusCode !== 200) {
// var data = JSON.parse(res.data);
reject("失败");
} else {}
} else {
resolve(true)
}
},
fail: function(err) {
// requestNumber--;

View File

@@ -3,14 +3,14 @@
* @param {string} key
* @param {*} data
*/
export function setLocalStorage(key, data) {
export function setLocalStorage(key :string, data:any) {
uni.setStorageSync(key, JSON.stringify(data))
}
/**
* key
* @param {string} key
* */
export function getLocalStorage(key) {
export function getLocalStorage(key:string) {
var val = uni.getStorageSync(key)
try {
if (val) {
@@ -26,6 +26,6 @@ export function getLocalStorage(key) {
* key
* @param {string} key
**/
export function removeLocalStorage(key) {
export function removeLocalStorage(key:string) {
return uni.removeStorageSync(key)
}

View File

@@ -1,5 +1,20 @@
// import env from "../utils/env";
import MD5 from 'crypto-js/md5'
/**
*
* @param {String} password
* @param {String} beforeSalt
* @param {String} afterSalt
* @returns {String}
*/
export const encryptPassword = (
password: string,
beforeSalt = 'opuoaqwehjkyuisdf',
afterSalt = 'asdjioewurtjfgiopu'
): string => {
return MD5(beforeSalt + MD5(password).toString() + afterSalt).toString()
}
/**
*
@@ -54,7 +69,7 @@ export function scanCode(onlyFromCamera = true) {
});
}
export function queryToObj(path) {
export function queryToObj(path:string|any):Record<string, string|any>{
const res = {};
const search = path.substr(path.indexOf("?") + 1);
search.split("&").forEach((paramStr) => {
@@ -124,7 +139,7 @@ export function toPath(path, query = {}) {
* @param {object} options
*
*/
export function alert(content, title = "提示", options = {}) {
export function alert(content, title = "提示", options:any = {}) {
return new Promise((resolve, reject) => {
uni.showModal({
title: title,