chat-app/src/uni_modules/tmui/interface.ts

688 lines
23 KiB
TypeScript
Raw Normal View History

2024-11-11 06:46:14 +00:00
import 'pinia';
import { ComponentInternalInstance, ComponentPublicInstance } from "vue"
interface Data {
[key: string]: any;
}
/**渐变方向 left:右->左right:左->右。top:下->上bottom:上->下。 */
export type linearType = 'left' | 'right' | 'bottom' | 'top' | ''
/**渐变色调light,dark,accent亮系渐变和深色渐变。 */
export type linearDeepType = "accent" | "dark" | "light"
/**边线的访问 */
export type borderDirectionType = "all" | "bottom" | "bottomleft" | "bottomright" | "left" | "leftright" | "right" | "right" | "top" | "topbottom" | "topleft" | "topright" | "x" | "y"
/**边线的样式 */
export type borderStyleType = "solid" | "dashed" | "dotted"
type componentKey = 'app' | 'button' | 'card' | 'tag' | 'sheet'
/**定义对象字段的键值只能是规定的组件名称。 */
type componentKeys = Partial<Record<componentKey, Tmui.components.all>>
declare global {
interface Uni {
/**
* tmui3.0
* https://tmui.design
*/
$tm: tmUtil,
}
namespace UniNamespace {
interface CanvasToTempFilePathOptions {
// @ts-ignore
canvas?: CanvasContext
}
interface CanvasContext {
width: number,
height: number,
/**dpr,屏幕的倍率 */
dpr: number,
/**nvue的gcanvas函数 */
toTempFilePath(any0: any, any1: any, any2: any, any3: any, any4: any, any5: any, any6: any, any7: any, any8: any): void
}
interface NodesRef {
/**节点,微信小程序上 */
node(callback?: (result: any) => void): SelectorQuery,
/**需要读取的字段属性 */
fields(fields: NodeField, callback?: (result: NodeInfo) => void): SelectorQuery;
}
interface NodeField {
/**包含的节点,部分小程序上会返回。 */
node?: boolean
}
}
namespace Tmui {
interface fetchNetConfigType {
/**
* query,body
*/
data?:any,
/**
*
*/
header?:any;
/**
*
*/
method?:fetchConfigMethod,
/**
*
*/
statusCode?:number,
/**
*
*
* {code,data,msg},['data'],data数据
* ['data',code],{data,code}
*/
pick?:string[],
/**
*
*/
watchRefresh?:boolean,
/**
* ,all
*/
toast?:'fail'|'success'|'all',
/**
* ,true
*/
showToast?:boolean,
/**
* msg
*/
toastKey?:string,
/**
* ,true
*/
showLoading?:boolean,
}
/**tmui配置表 */
interface tmuiConfig {
/** 自动跟随系统暗黑 */
autoDark?: boolean,
/** 开启全局分离功能,默认关闭 */
shareDisable?: boolean,
/**主题列表 */
theme?: {},
/**细化全局的主题配置表 */
themeConfig?: {
/**暗黑模式下的一些统一配置 */
dark?: {
/**一般的卡片项目暗黑背景 */
cardColor?: string,
/**输入框,表单等暗黑背景 */
inputColor?: string,
/**禁用输入框,表单等暗黑背景 */
disableColor?: string,
/**暗黑下的页面背景 */
bodyColor?: string,
/**文本禁用色. */
textDisableColor?: string,
},
/**
* app整体字体大小的调整比例
* 使tm-text组件以及自身组件的字号才会有效果
*
* */
globalFontSizeRatio?: number,
/** 是否关闭弹层背景的模糊 */
overflowBlur?: false,
/**
*
*
*/
theme?: {
/**如果该组件默认有值就会使用下列属性如果组件默认为0不会使用。 */
[key: string]: {
/**待考虑编辑2023-2-18 00:23:35 */
}
},
/**各个组件的统一配置 */
component?: componentKeys
},
/**router路由拦截代替外置文件 */
router?: {
/**页面访问前执行 */
useTmRouterBefore(arg: beforeRouterOpts): void,
/**页面访问后执行 */
useTmRouterAfter(arg: beforeRouterOpts): void,
},
/**用户自定义全局数据 */
custom?: {
[key: string]: any
}
}
interface beforeRouterOpts {
path: string | null,//当前页面路径,不含前缀 /
opts?: any,//页面参数
openType?: string,//当前页面打开的类型
context: ComponentPublicInstance | null,
}
/**actionMenu组件项目类型 */
interface tmActionMenu {
text?: string,
disabled?: boolean,
/** 各家小程序的openType。 */
openType?: string
[key: string]: any;
}
interface tmAlert {
icon?: string,
title?: string,
content?: string
}
interface tabs {
key?: string | number,
title?: string,
icon?: string,
dot?: boolean,
count?: string | number
dotColor?: string,
[key: string]: any
}
interface skuItem {
title: string,
id: string | number,
num: number,
children: skuItem[]
}
interface sku {
data: skuItem[],
product: {
id: string,
title: string,
num: number,
max_buy: number,
/** 原价 */
price: number,
/** 优惠价 */
salePrice: 54,
tip: string,
img: string
}[]
}
interface tmFormSubmitResult {
data: { [key: string]: any };
isPass: boolean,
result: {
message: string,//校验后的提示文本
validator: boolean,//是否校验通过
}[]
}
interface tmFormRules {
validator?: Function | boolean,//检验函数。可以是Promise异步回调。
required?: boolean,//是否必填。
message?: string,//检验不合格时的文本
type?: string,//校验类型.
[key: string]: any
}
/**组件的配置 */
namespace components {
type all = button & sheet
interface button {
round?: number,
shadow?: number,
color?: string
}
interface sheet {
}
}
}
}
declare module 'pinia' {
export interface PiniaCustomProperties {
tmuiConfig: Tmui.tmuiConfig,
}
export interface PiniaCustomStateProperties {
tmuiConfig: Tmui.tmuiConfig
}
}
export type pagesCustomType = 'default' | 'custom'
export interface pagesType {
//页面地址
path: string,
//导航栏模式
custom: pagesCustomType,
navigationBarBackgroundColor: string,
navigationBarTextStyle: string,
subPackages?: Array<any>
}
export interface tabBarItemType {
pagePath: string,
iconPath: string,
selectedIconPath: string,
text: string
}
export interface tabBarType {
color: string,
selectedColor: string,
borderStyle: string,
backgroundColor: string,
list?: Array<tabBarItemType>
}
export interface beforeRouterOpts {
path: string | null,//当前页面路径,不含前缀 /
opts?: any,//页面参数
openType?: string,//当前页面打开的类型
context: ComponentPublicInstance | null,
}
type fetchConfigResponseType = "arraybuffer" | "text";
type fetchConfigDataType = "json" | "text";
type fetchConfigMethod = "GET" | "POST" | "PUT" | "DELETE" | "CONNECT" | "HEAD" | "OPTIONS" | "TRACE";
interface fetchConfigSuccessType {
data: object | string | ArrayBuffer,
statusCode: number,
header: object,
cookies: Array<string>
}
interface fetchConfig {
url?: string,
data?: object | string | ArrayBuffer,
header?: object,
method?: fetchConfigMethod,
timeout?: number,
dataType?: fetchConfigDataType,
responseType?: fetchConfigResponseType,
sslVerify?: boolean,
withCredentials?: boolean,
firstIpv4?: boolean,
success?: Function,
fail?: Function,
complete?: Function
}
type openUrlType = "navigate" | "redirect" | "reLaunch" | "switchTab" | "navigateBack"
declare interface Touch {
readonly clientX: number;
readonly clientY: number;
readonly force: number;
readonly identifier: number;
readonly pageX: number;
readonly pageY: number;
readonly radiusX: number;
readonly radiusY: number;
readonly rotationAngle: number;
readonly screenX: number;
readonly screenY: number;
readonly target: EventTarget;
readonly x: number;
readonly y: number;
}
declare interface TouchEvent {
readonly changedTouches: TouchList
}
type tmUtil = {
//pagejson下的pages配置。
pages: Array<{ path: string, custom: 'custom' | 'default' }>,
//pagejson下的配置。
tabBar: tabBarType,
globalNavStyle: "custom" | "default",
/**
*
* @param color
*/
isColor(color: string): boolean,
/**
*
* @param key
* @return
*/
language(key: string): string,
fetch: {
/**
* GET请求
* @param url
* @param data
* @param opts
* @help https://tmui.design/doc/JSTool/fetch.html
*/
get(url: string, data?: object, opts?: fetchConfig): Promise<UniApp.GeneralCallbackResult | UniApp.RequestSuccessCallbackResult>,
/**
* POST请求
* @param url
* @param data
* @param opts
* @help https://tmui.design/doc/JSTool/fetch.html
*/
post(url: string, data?: object, opts?: fetchConfig): Promise<UniApp.GeneralCallbackResult | UniApp.RequestSuccessCallbackResult>,
/**
*
* @param cog
* @param beforeFun
* @param afterFun
* @param complete
* @help https://tmui.design/doc/JSTool/fetch.html
*/
request(cog: fetchConfig, beforeFun?: Function, afterFun?: Function, complete?: Function): Promise<UniApp.GeneralCallbackResult | UniApp.RequestSuccessCallbackResult>,
},
/**
* tmui3.0
*/
u: {
/**
*
* @param arg
* @param defaultNum 0,
* @returns number类型数值
*/
isNumber(arg: string | number | undefined | null, defaultNum: number): number,
/**
*
* @param arg
* @param defaultNum "",
* @returns
*/
isString(arg: string | number | undefined | null, defaultStr: string): string,
/**
*
* @param total
* @param pageSize
* @returns
*/
paginate(total: number, pageSize: number): number[],
/**
*
* @example getValue(data,"a.b.c")
* @param data
* @param keys
* @returns
* @description
*/
getValue(data: Data, keys: string): any,
/**
*
* @example setValue(data,"a.b.c","haha")
* @param data
* @param keys
* @returns
* @description
*/
setValue(data: Data, keys: string, value: any): void,
/**
*
* @param data
* @returns
*/
getMaxDepth(data: Data): number,
/**
*
* @param {Object} url
* @param {Object} list url数组["http:url"] or [{url:"https:url",...}]
* @param {Object} rangKey list是对象数组url字段
*/
preview(url: string, list?: Array<string>, rangKey?: string): void,
/**
*
* @param {Array} oArr -
* @param {Number} length -
* @return {Array} arr -
*/
splitData<T>(arr: Array<T>, size: number): Array<T[]>,
/**
*
* @param {Number} t -
* @return {Object} format -
*/
timeMuch(t: number): string,
/**
*
* @param timestamp
* @return 1
*/
getDateToNewData(timestamp?: number | string | Date): string,
/**
*
* @param {String<Number>} phoneNumber -
* @return Promise<boolean>
*/
callPhone(phoneNumber: string): Promise<boolean | any>,
/**
*
* @param {Boolean} onlyFromCamera true
* @param {Array<string>} scanType ['barCode', 'qrCode', 'datamatrix','datamatrix']
* @returns Promise
*/
scanCode(onlyFromCamera: boolean, scanType: Array<any>): Promise<UniApp.ScanCodeSuccessRes | string>,
/**
*
* @param {String} data
* @returns Promise true/false
*/
setClipboardData(data: string): Promise<boolean | string>,
/**
*
* @returns Promise
*/
getClipboardData(): Promise<string | boolean>,
/**
* cookie数据
* @param {String} key
* @param {String} data
* @returns Boolean
*/
setCookie(key: string, data: any): boolean,
/**
* cookie
* @param {String} key
* @returns Boolean
*/
delCookie(key: string): boolean,
/**
* cookie数据
* string返回的也是字符串
* @param {String} key
* @returns json/string
*/
getCookie(key: string): Object | string,
/**
*
* @param {string} uri
* @param {string} key
* @param {string} value
* @returns
*/
httpUrlAddKey(uri: string, key: string, value: string): string,
/**
* url参数
* @param {string} uri
* @param {string} key
* @returns string|undefined
*/
getQueryString(url: string, key: string): string,
/**
*
* @param rdix 1
* @param length 12
* @param isAddStr false ,
* @returns String
*/
getUid(rdix?: number, length?: number, isAddStr?: boolean): number | string,
/**
*
* wait毫秒后才执行函数
* @param {Function} func
* @param {Number} wait
* @param {Boolean} immediate
*/
debounce(func: Function, wait?: number, immediate?: boolean): void,
/**
*
*
* @param {Function} func
* @param {Number} wait
* @param {Boolean} immediate
* @return void
*/
throttle(func: Function, wait?: number, immediate?: boolean, timer?: number, flags?: boolean): void,
/**
*
* @param {T} data
* @return {T} any
*/
deepClone<T>(data: T): T,
/**
* queryDom
*/
quereyDom(t: ComponentInternalInstance, node: string): Promise<UniApp.NodeInfo | UniApp.NodeInfo[]>,
/**
*
* @param t Vue上下文对象
* @param node #id比如'#id',nvue中应该是元素上写明ref='id'
* @returns vue页面返回查询的节点信息nvue返回weex的节点信息
*/
queryDom(t: ComponentInternalInstance, node: string): Promise<UniApp.NodeInfo | UniApp.NodeInfo[]>,
/**
*
* @param FirstOBJ
* @param SecondOBJ
* @returns
*/
deepObjectMerge(FirstOBJ: Record<string, any>, SecondOBJ: Record<string, any>): Record<string, any>,
/**
*
* @param phone
* @returns Boolean
*/
isPhone(phone: string | number): boolean,
/**
*
* @param s
* @returns Boolean
*/
isChina(s: string): boolean,
/**
*
* @description null, undefaind
* @param s
*/
isEmpty(s: any): boolean,
/**
*
* @param s
* @returns Boolean
*/
isEmail(s: string): boolean,
/**
*
* @param val
* @returns Boolean
* @author https://cloud.tencent.com/developer/article/1114323
*/
isIdCard(val: string | number): boolean,
/**
*
* @description 5绿6
* @param s
* @returns Boolean
*/
isIdCar(s: string): boolean,
/**
*
* @param s
* @param len 6
* @param maxLen 20
* @returns Boolean
*/
isPasswordOfNumber(s: number | string, le: number, maxLen: number): boolean,
/**
*
* @param s
* @param len 6
* @param maxLen 20
* @param model 012
* @returns Boolean
*/
isPasswordOfOther(s: string | number, len: number, maxLen: number, model: number): boolean,
/**
*
* @param s
* @returns Boolean
*/
isDate(s: string | number | Date): boolean,
/**
*
* @param word
* @param mask 穿
* @param icon
*/
toast(word: string, mask?: boolean, icon?: any): void,
/**
*
* uni获取有效高度而烦恼
* onMounted或者onLoad中调用h5端
* @return {height,width,top,isCustomHeader,sysinfo}
*/
getWindow(): { width: number, height: number, top: number, bottom: number, statusBarHeight: number, isCustomHeader: Boolean, sysinfo: UniApp.GetSystemInfoResult },
/**
*
* @param url string
* @param type openUrlType "navigate" | "redirect" | "reLaunch" | "switchTab" | "navigateBack"
*/
routerTo(url: string, type?: openUrlType): void,
/**
* rpx转换为px
* @param v
* @param screenWidth
* @return number
*/
torpx(v: number, screenWidth?: number): number
/**
* rpx转换为px
* @param v
* @return number
*/
topx(v: number, screenWidth?: number): number,
/**
*
* @param callback
* @returns id值cancelAnimationFrame(id)
*/
requestAnimationFrame(callback: Function): number,
/**
*
* @param id requestAnimationFrame产生的id
*/
cancelAnimationFrame(id: number): void
},
tmicon: Array<{
font: string,
prefix: string,
fontJson: Array<{
icon_id: string,
name: string,
font_class: string,
unicode: string,
unicode_decimal: number
}>
}>,
/**tmui3.0的全局配置以代替router,theme等的外围文件夹。解耦相关目录 */
config: Tmui.tmuiConfig
}