utils-uniapp 1.0.10 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,29 @@
1
+ // alipaySubmit.d.ts
2
+
3
+ /**
4
+ * 生成input表单项
5
+ * @param key 表单name
6
+ * @param data 表单数据源对象
7
+ * @param form 挂载form表单
8
+ */
9
+ declare function createFormInputNode(key: string, data: Record<string, any>, form: HTMLFormElement): void;
10
+
11
+ interface AlipaySubmitOptions {
12
+ /** pay | charge | string,pay模式过滤 sn、id,默认 pay */
13
+ type?: 'pay' | 'charge' | string;
14
+ /** 支付宝网关地址,默认 https://mapi.alipay.com/gateway.do */
15
+ alipayGateway?: string;
16
+ }
17
+
18
+ /**
19
+ * 【纯支付执行函数】只接收后端返回数据,不发起网络请求,仅H5环境
20
+ * @param data 后端返回的data对象
21
+ * @param options 配置项
22
+ */
23
+ export declare function alipaySubmit(data: Record<string, any>, options?: AlipaySubmitOptions): void;
24
+
25
+ declare const _default: {
26
+ alipaySubmit: typeof alipaySubmit;
27
+ };
28
+
29
+ export default _default;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function m(e,o,a){let t=document.createElement("input");t.name=e,t.value=o[e],a.append(t)}function r(e){let o=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(typeof document>"u"){console.warn("alipaySubmit:仅支持H5环境");return}if(!e||typeof e!="object"){console.error("alipaySubmit:入参data必须为对象");return}const{type:a="pay",alipayGateway:t="https://mapi.alipay.com/gateway.do"}=o,n=document.createElement("form");n.action=t;const u=a==="pay"?["sn","id"]:[];Object.keys(e).forEach(i=>{u.includes(i)||m(i,e,n)}),document.getElementsByTagName("body")[0].append(n),n.submit(),setTimeout(()=>{n.remove()},100)}exports.alipaySubmit=r;
package/lib/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./array/index.js"),n=require("./date/index.js"),t=require("./fs/index.js"),s=require("./getLocation/index.js"),r=require("./http/index.js"),e=require("./index-b81565a7.js"),i=require("./object/index.js"),o=require("./validate/index.js"),c=require("./index-9456b3d9.js"),d=require("./lodash");Object.assign(exports,d);exports.exchangeArrP=a.exchangeArrP;exports.filterTree=a.filterTree;exports.findTreeItem=a.findTreeItem;exports.flatWithKey=a.flatWithKey;exports.getTreePath=a.getTreePath;exports.groupBy=a.groupBy;exports.reverseForEach=a.reverseForEach;exports.treeItemSetParent=a.treeItemSetParent;exports.dateFormat=n.dateFormat;exports.getDate=n.getDate;exports.$fs=t.$fs;exports.chooseImg=t.chooseImg;exports.getArraybufferTempPath=t.getArraybufferTempPath;exports.getImgBase64Prefix=t.getImgBase64Prefix;exports.readFile=t.readFile;exports.saveImageToPhotosAlbum=t.saveImageToPhotosAlbum;exports.writeFile=t.writeFile;exports.getLocation=s.getLocation;exports.openLocation=s.openLocation;exports.CONTENT_TYPES=r.CONTENT_TYPES;exports.CancelToken=r.CancelToken;exports.createDownloadFile=r.createDownloadFile;exports.createRequest=r.createRequest;exports.createUploadFile=r.createUploadFile;exports.endLoading=r.endLoading;exports.promisifyRequest=r.promisifyRequest;exports.startLoading=r.startLoading;exports.compareVersion=e.compareVersion;exports.compose=e.compose;exports.composeAsync=e.composeAsync;exports.debounce=e.debounce;exports.debouncePromise=e.debouncePromise;exports.decodeURIParams=e.decodeURIParams;exports.encodeURIParams=e.encodeURIParams;exports.getCache=e.getCache;exports.getOnLoadParams=e.getOnLoadParams;exports.getPascalCase=e.getPascalCase;exports.getQueryParams=e.getQueryParams;exports.getQueryParamsFromHash=e.getQueryParamsFromHash;exports.getQueryParamsFromSearch=e.getQueryParamsFromSearch;exports.getRandom=e.getRandom;exports.getRandomStr=e.getRandomStr;exports.pipe=e.pipe;exports.pipeAsync=e.pipeAsync;exports.randomColor=e.randomColor;exports.removeCache=e.removeCache;exports.renewCache=e.renewCache;exports.setCache=e.setCache;exports.throttle=e.throttle;exports.toQueryString=e.toQueryString;exports.cloneDeepWithDescriptors=i.cloneDeepWithDescriptors;exports.getRawType=i.getRawType;exports.hasOwnProperty=i.hasOwnProperty;exports.isExternal=o.isExternal;exports.validDate=o.validDate;exports.validIDCard=o.validIDCard;exports.validPhone=o.validPhone;exports.validPostalCode=o.validPostalCode;exports.validURL=o.validURL;exports.wx=c.index;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./aliPay/index.js"),a=require("./array/index.js"),n=require("./date/index.js"),t=require("./fs/index.js"),s=require("./getLocation/index.js"),r=require("./http/index.js"),e=require("./index-b81565a7.js"),i=require("./object/index.js"),o=require("./validate/index.js"),d=require("./index-9456b3d9.js"),m=require("./lodash");Object.assign(exports,m);exports.alipaySubmit=c.alipaySubmit;exports.exchangeArrP=a.exchangeArrP;exports.filterTree=a.filterTree;exports.findTreeItem=a.findTreeItem;exports.flatWithKey=a.flatWithKey;exports.getTreePath=a.getTreePath;exports.groupBy=a.groupBy;exports.reverseForEach=a.reverseForEach;exports.treeItemSetParent=a.treeItemSetParent;exports.dateFormat=n.dateFormat;exports.getDate=n.getDate;exports.$fs=t.$fs;exports.chooseImg=t.chooseImg;exports.getArraybufferTempPath=t.getArraybufferTempPath;exports.getImgBase64Prefix=t.getImgBase64Prefix;exports.readFile=t.readFile;exports.saveImageToPhotosAlbum=t.saveImageToPhotosAlbum;exports.writeFile=t.writeFile;exports.getLocation=s.getLocation;exports.openLocation=s.openLocation;exports.CONTENT_TYPES=r.CONTENT_TYPES;exports.CancelToken=r.CancelToken;exports.createDownloadFile=r.createDownloadFile;exports.createRequest=r.createRequest;exports.createUploadFile=r.createUploadFile;exports.endLoading=r.endLoading;exports.promisifyRequest=r.promisifyRequest;exports.startLoading=r.startLoading;exports.compareVersion=e.compareVersion;exports.compose=e.compose;exports.composeAsync=e.composeAsync;exports.debounce=e.debounce;exports.debouncePromise=e.debouncePromise;exports.decodeURIParams=e.decodeURIParams;exports.encodeURIParams=e.encodeURIParams;exports.getCache=e.getCache;exports.getOnLoadParams=e.getOnLoadParams;exports.getPascalCase=e.getPascalCase;exports.getQueryParams=e.getQueryParams;exports.getQueryParamsFromHash=e.getQueryParamsFromHash;exports.getQueryParamsFromSearch=e.getQueryParamsFromSearch;exports.getRandom=e.getRandom;exports.getRandomStr=e.getRandomStr;exports.pipe=e.pipe;exports.pipeAsync=e.pipeAsync;exports.randomColor=e.randomColor;exports.removeCache=e.removeCache;exports.renewCache=e.renewCache;exports.setCache=e.setCache;exports.throttle=e.throttle;exports.toQueryString=e.toQueryString;exports.cloneDeepWithDescriptors=i.cloneDeepWithDescriptors;exports.getRawType=i.getRawType;exports.hasOwnProperty=i.hasOwnProperty;exports.isExternal=o.isExternal;exports.validDate=o.validDate;exports.validIDCard=o.validIDCard;exports.validPhone=o.validPhone;exports.validPostalCode=o.validPostalCode;exports.validURL=o.validURL;exports.wx=d.index;
@@ -0,0 +1,134 @@
1
+ import Vue from 'vue';
2
+
3
+ /**
4
+ * 返回守卫弹窗配置项
5
+ * @property title 弹窗标题
6
+ * @property content 弹窗主体提示文案
7
+ * @property confirmText 确认按钮文字
8
+ * @property cancelText 取消按钮文字
9
+ */
10
+ export interface BackGuardOptions {
11
+ title: string;
12
+ content: string;
13
+ confirmText: string;
14
+ cancelText: string;
15
+ }
16
+
17
+ /**
18
+ * Mixin注入的响应式状态
19
+ * @property backGuard 控制 page‑container 组件 show 显示/隐藏
20
+ * @property guardActive 业务内部标记:是否真正开启返回防护;业务禁止直接修改,统一调用 enableBackGuard / disableBackGuard
21
+ * @property backGuardOptions 返回确认弹窗配置对象;运行时通过 setBackGuardOptions 更新文案
22
+ */
23
+ export interface BackGuardMixinState {
24
+ backGuard: boolean;
25
+ guardActive: boolean;
26
+ backGuardOptions: BackGuardOptions;
27
+ }
28
+
29
+ /**
30
+ * Mixin注入的实例方法
31
+ */
32
+ export interface BackGuardMixinMethods {
33
+ /**
34
+ * page‑container @before‑leave 绑定事件回调
35
+ * 小程序点击左上角返回 / 物理返回键触发此事件
36
+ * - 未开启防护直接放行;开启防护弹出确认框
37
+ * - 确认离开执行 uni.navigateBack;取消则维持页面不跳转
38
+ */
39
+ onBeforeLeave(): Promise<void>;
40
+
41
+ /**
42
+ * 封装 uni.showModal,转为Promise调用
43
+ * @param options 弹窗配置,支持部分字段
44
+ * @returns Promise<boolean> true=确认离开,false=取消
45
+ */
46
+ handleBackGuardConfirm(options: Partial<BackGuardOptions>): Promise<boolean>;
47
+
48
+ /**
49
+ * 运行时更新挽留弹窗配置,浅合并对象,支持只传部分字段
50
+ * @example
51
+ * this.setBackGuardOptions({ content: '问诊会话未结束,确定离开吗?' })
52
+ * @param customOpts 自定义弹窗配置
53
+ */
54
+ setBackGuardOptions(customOpts: Partial<BackGuardOptions>): void;
55
+
56
+ /**
57
+ * 【业务API】开启返回挽留防护;表单编辑、会话进行中调用
58
+ * @example
59
+ * this.enableBackGuard()
60
+ */
61
+ enableBackGuard(): void;
62
+
63
+ /**
64
+ * 【业务API】关闭返回挽留防护;保存成功、会话结束调用
65
+ * @example
66
+ * this.disableBackGuard()
67
+ */
68
+ disableBackGuard(): void;
69
+ }
70
+
71
+ /**
72
+ * 返回守卫 Mixin(微信小程序 page‑container 实现返回拦截)
73
+ *
74
+ * ## 说明
75
+ * 1. mixin 内部自动注入 onShow / onUnload 生命周期,页面无需处理
76
+ * 2. 仅微信小程序有效;H5/App不支持该组件能力
77
+ *
78
+ * ## 模板使用(页面template必须引入该组件)
79
+ * ```html
80
+ * <page-container
81
+ * :show="backGuard"
82
+ * overlay="false"
83
+ * duration="0"
84
+ * @beforeleave="onBeforeLeave"
85
+ * />
86
+ * ```
87
+ *
88
+ * ## 业务代码调用示例(和截图保持一致)
89
+ * ```js
90
+ * // 会话开始,开启防护 + 修改弹窗提示文案
91
+ * this.enableBackGuard()
92
+ * this.setBackGuardOptions({
93
+ * content: '问诊会话未结束,确定离开吗?'
94
+ * })
95
+ *
96
+ * // 会话结束/保存成功,关闭防护
97
+ * this.disableBackGuard()
98
+ * ```
99
+ */
100
+ declare const backGuardMixin: Vue.ComponentOptions<Vue> & {
101
+ /** mixin内部data函数,返回响应式状态 */
102
+ data(): BackGuardMixinState;
103
+ /** mixin内部方法集合 */
104
+ methods: BackGuardMixinMethods;
105
+ };
106
+
107
+ export default backGuardMixin;
108
+
109
+ /**
110
+ * 【可选全局Vue实例扩展】
111
+ * 开启后,所有页面 this.xxx 自动获得类型提示;
112
+ * ⚠️风险:全局污染,多个mixin会出现字段冲突;不需要请注释
113
+ */
114
+ // declare module 'vue/types/vue' {
115
+ // interface Vue extends BackGuardMixinState, BackGuardMixinMethods {}
116
+ // }
117
+
118
+ /**
119
+ * 不开启全局扩展时,页面手动标注this类型示例
120
+ * ```ts
121
+ * import Vue from 'vue'
122
+ * import backGuardMixin, { BackGuardMixinState, BackGuardMixinMethods } from '@/common/mixins/backGuard.mixin'
123
+ *
124
+ * type PageThis = Vue & BackGuardMixinState & BackGuardMixinMethods;
125
+ * export default {
126
+ * mixins: [backGuardMixin],
127
+ * methods: {
128
+ * demo(this: PageThis) {
129
+ * this.enableBackGuard()
130
+ * }
131
+ * }
132
+ * }
133
+ * ```
134
+ */
@@ -0,0 +1,65 @@
1
+ export default {
2
+ data() {
3
+ return {
4
+ backGuard: false,
5
+ // 内部源状态:是否需要开启返回防护,业务不直接修改
6
+ guardActive: false,
7
+ backGuardOptions: {
8
+ title: '提示',
9
+ content: '内容尚未保存,确定放弃编辑?',
10
+ confirmText: '确定离开',
11
+ cancelText: '取消'
12
+ }
13
+ };
14
+ },
15
+ onShow() {
16
+ this.backGuard = this.guardActive;
17
+ },
18
+ onUnload() {
19
+ this.backGuard = false;
20
+ },
21
+ methods: {
22
+ async onBeforeLeave() {
23
+ // 容器由代码关闭(disableBackGuard 置 show=false)时直接放行,不弹确认框
24
+ if (!this.guardActive) return;
25
+ this.backGuard = false;
26
+ const shouldLeave = await this.handleBackGuardConfirm(this.backGuardOptions);
27
+ if (shouldLeave === true) {
28
+ uni.navigateBack();
29
+ } else {
30
+ this.$nextTick(() => {
31
+ this.backGuard = this.guardActive;
32
+ });
33
+ }
34
+ },
35
+
36
+ async handleBackGuardConfirm(options) {
37
+ return new Promise(resolve => {
38
+ uni.showModal({
39
+ title: options.title,
40
+ content: options.content,
41
+ confirmText: options.confirmText,
42
+ cancelText: options.cancelText,
43
+ success: res => resolve(res.confirm)
44
+ });
45
+ });
46
+ },
47
+
48
+ setBackGuardOptions(customOpts) {
49
+ this.backGuardOptions = {
50
+ ...this.backGuardOptions,
51
+ ...customOpts
52
+ };
53
+ },
54
+
55
+ // ========== 对外API,业务只调用这两个 ==========
56
+ enableBackGuard() {
57
+ this.guardActive = true;
58
+ this.backGuard = true;
59
+ },
60
+ disableBackGuard() {
61
+ this.guardActive = false;
62
+ this.backGuard = false;
63
+ }
64
+ }
65
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "utils-uniapp",
3
- "version": "1.0.10",
3
+ "version": "1.1.0",
4
4
  "description": "aubyn's utils for uniapp",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",