rexma-design 2.0.2 → 2.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,82 @@
1
+ {
2
+ "globals": {
3
+ "Component": true,
4
+ "ComponentPublicInstance": true,
5
+ "ComputedRef": true,
6
+ "DirectiveBinding": true,
7
+ "EffectScope": true,
8
+ "ExtractDefaultPropTypes": true,
9
+ "ExtractPropTypes": true,
10
+ "ExtractPublicPropTypes": true,
11
+ "InjectionKey": true,
12
+ "MaybeRef": true,
13
+ "MaybeRefOrGetter": true,
14
+ "PropType": true,
15
+ "Ref": true,
16
+ "Slot": true,
17
+ "Slots": true,
18
+ "VNode": true,
19
+ "WritableComputedRef": true,
20
+ "computed": true,
21
+ "createApp": true,
22
+ "customRef": true,
23
+ "defineAsyncComponent": true,
24
+ "defineComponent": true,
25
+ "effectScope": true,
26
+ "getCurrentInstance": true,
27
+ "getCurrentScope": true,
28
+ "h": true,
29
+ "inject": true,
30
+ "isProxy": true,
31
+ "isReactive": true,
32
+ "isReadonly": true,
33
+ "isRef": true,
34
+ "markRaw": true,
35
+ "nextTick": true,
36
+ "onActivated": true,
37
+ "onBeforeMount": true,
38
+ "onBeforeRouteLeave": true,
39
+ "onBeforeRouteUpdate": true,
40
+ "onBeforeUnmount": true,
41
+ "onBeforeUpdate": true,
42
+ "onDeactivated": true,
43
+ "onErrorCaptured": true,
44
+ "onMounted": true,
45
+ "onRenderTracked": true,
46
+ "onRenderTriggered": true,
47
+ "onScopeDispose": true,
48
+ "onServerPrefetch": true,
49
+ "onUnmounted": true,
50
+ "onUpdated": true,
51
+ "onWatcherCleanup": true,
52
+ "provide": true,
53
+ "reactive": true,
54
+ "readonly": true,
55
+ "ref": true,
56
+ "resolveComponent": true,
57
+ "shallowReactive": true,
58
+ "shallowReadonly": true,
59
+ "shallowRef": true,
60
+ "toRaw": true,
61
+ "toRef": true,
62
+ "toRefs": true,
63
+ "toValue": true,
64
+ "triggerRef": true,
65
+ "unref": true,
66
+ "useAttrs": true,
67
+ "useCssModule": true,
68
+ "useCssVars": true,
69
+ "useId": true,
70
+ "useLink": true,
71
+ "useModel": true,
72
+ "useRoute": true,
73
+ "useRouter": true,
74
+ "useSlots": true,
75
+ "useTemplateRef": true,
76
+ "watch": true,
77
+ "watchEffect": true,
78
+ "watchPostEffect": true,
79
+ "watchSyncEffect": true,
80
+ "xh": true
81
+ }
82
+ }
package/gulpfile.js ADDED
@@ -0,0 +1,135 @@
1
+ const gulp = require('gulp');
2
+ const ts = require('gulp-typescript');
3
+ const cleanCSS = require('gulp-clean-css');
4
+ const uglify = require('gulp-uglify');
5
+ const rename = require('gulp-rename');
6
+ const fs = require('fs');
7
+ const path = require('path');
8
+
9
+ // 创建两个独立的 TypeScript 项目实例
10
+ const tsProjectJS = ts.createProject('tsconfig.lib.json', {
11
+ declaration: false,
12
+ emitDeclarationOnly: false
13
+ });
14
+
15
+ const tsProjectDTS = ts.createProject('tsconfig.lib.json', {
16
+ declaration: true,
17
+ emitDeclarationOnly: true
18
+ });
19
+
20
+ // 清理 lib 目录
21
+ function clean(cb) {
22
+ const libPath = path.join(__dirname, 'lib');
23
+ if (fs.existsSync(libPath)) {
24
+ fs.rmSync(libPath, { recursive: true, force: true });
25
+ }
26
+ cb();
27
+ }
28
+
29
+ // 只编译 TypeScript 文件(排除原始 index.ts)
30
+ function compileTS() {
31
+ return gulp.src(['src/packages/**/*.ts', '!src/packages/index.ts'])
32
+ .pipe(tsProjectJS())
33
+ .js.pipe(gulp.dest('lib'));
34
+ }
35
+
36
+ // 生成类型声明文件
37
+ function generateDTS() {
38
+ return gulp.src(['src/packages/**/*.ts', '!src/packages/index.ts'])
39
+ .pipe(tsProjectDTS())
40
+ .dts.pipe(gulp.dest('lib'));
41
+ }
42
+
43
+ // 复制 Vue 文件
44
+ function copyVue() {
45
+ return gulp.src('src/packages/**/*.vue')
46
+ .pipe(gulp.dest('lib'));
47
+ }
48
+
49
+ // 动态生成入口文件
50
+ function createIndex(cb) {
51
+ const packagesDir = path.join(__dirname, 'src/packages');
52
+ const items = fs.readdirSync(packagesDir, { withFileTypes: true });
53
+
54
+ let jsExports = [];
55
+ let dtsExports = [];
56
+
57
+ items.forEach(item => {
58
+ if (item.isDirectory()) {
59
+ const dirPath = path.join(packagesDir, item.name);
60
+ const indexTsPath = path.join(dirPath, 'index.ts');
61
+ const indexVuePath = path.join(dirPath, 'index.vue');
62
+
63
+ if (fs.existsSync(indexTsPath)) {
64
+ // TypeScript 模块
65
+ jsExports.push(`export { default as ${item.name} } from './${item.name}';`);
66
+ dtsExports.push(`export { default as ${item.name} } from './${item.name}';`);
67
+ } else if (fs.existsSync(indexVuePath)) {
68
+ // Vue 组件
69
+ jsExports.push(`export { default as ${item.name} } from './${item.name}/index.vue';`);
70
+ dtsExports.push(`export { default as ${item.name} } from './${item.name}/index.vue';`);
71
+ // jsExports.push(`export const ${item.name} = () => import('./${item.name}/index.vue');`);
72
+ // dtsExports.push(`export declare const ${item.name}: () => Promise<any>;`);
73
+ }
74
+ }
75
+ });
76
+
77
+ // 生成 JS 入口文件
78
+ const jsContent = jsExports.join('\n') + '\n';
79
+ fs.writeFileSync(path.join(__dirname, 'lib', 'index.js'), jsContent);
80
+
81
+ // 生成 TypeScript 声明文件
82
+ const dtsContent = dtsExports.join('\n') + '\n';
83
+ fs.writeFileSync(path.join(__dirname, 'lib', 'index.d.ts'), dtsContent);
84
+
85
+ cb();
86
+ }
87
+
88
+ // 复制其他资源文件
89
+ function copyAssets() {
90
+ return gulp.src(['src/packages/**/*.css', 'src/packages/**/*.scss', 'src/packages/**/*.less'])
91
+ .pipe(gulp.dest('lib'));
92
+ }
93
+
94
+ // 压缩 CSS 文件
95
+ function minifyCSS() {
96
+ return gulp.src('lib/**/*.css')
97
+ .pipe(cleanCSS())
98
+ .pipe(rename({ suffix: '.min' }))
99
+ .pipe(gulp.dest('lib'));
100
+ }
101
+
102
+ // 压缩 JS 文件
103
+ function minifyJS() {
104
+ return gulp.src('lib/**/*.js')
105
+ .pipe(uglify())
106
+ .pipe(rename({ suffix: '.min' }))
107
+ .pipe(gulp.dest('lib'));
108
+ }
109
+
110
+ // 监听文件变化
111
+ function watch() {
112
+ gulp.watch('src/packages/**/*.ts', gulp.series(compileTS, generateDTS, createIndex));
113
+ gulp.watch('src/packages/**/*.vue', gulp.series(copyVue, createIndex));
114
+ gulp.watch('src/packages/**/*.{css,scss,less}', gulp.series(copyAssets, minifyCSS));
115
+ }
116
+
117
+ // 构建任务
118
+ const build = gulp.series(
119
+ clean,
120
+ gulp.parallel(compileTS, generateDTS, copyVue, copyAssets),
121
+ createIndex
122
+ );
123
+
124
+ // 构建并压缩
125
+ const buildProd = gulp.series(
126
+ build,
127
+ gulp.parallel(minifyCSS, minifyJS)
128
+ );
129
+
130
+ // 导出任务
131
+ exports.clean = clean;
132
+ exports.build = build;
133
+ exports.buildProd = buildProd;
134
+ exports.watch = watch;
135
+ exports.default = build;
@@ -8,6 +8,10 @@ declare class XinhuaClient {
8
8
  private static initOptions;
9
9
  static init(options: IXinhuaClientInitOptions): void;
10
10
  private static stateInit;
11
+ /**
12
+ * 设置数据
13
+ */
14
+ static setState(state: Partial<Pick<IXinhuaClientState, 'userId' | 'statusBarHeight'>>): void;
11
15
  /**
12
16
  * 使用数据状态
13
17
  */
@@ -114,6 +114,17 @@ var XinhuaClient = /** @class */ (function () {
114
114
  });
115
115
  }
116
116
  });
117
+ /**
118
+ * 设置数据
119
+ */
120
+ Object.defineProperty(XinhuaClient, "setState", {
121
+ enumerable: false,
122
+ configurable: true,
123
+ writable: true,
124
+ value: function (state) {
125
+ this.state = __assign(__assign({}, this.state), state);
126
+ }
127
+ });
117
128
  /**
118
129
  * 使用数据状态
119
130
  */
package/lib/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
- export { default as getValueFromUA } from './getValueFromUA';
2
1
  export { default as XinhuaClient } from './XinhuaClient';
2
+ export { default as getValueFromUA } from './getValueFromUA';
3
+ export { default as usePullDownRefresh } from './usePullDownRefresh';
package/lib/index.js CHANGED
@@ -1,10 +1,3 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.XinhuaClient = exports.getValueFromUA = void 0;
7
- var getValueFromUA_1 = require("./getValueFromUA");
8
- Object.defineProperty(exports, "getValueFromUA", { enumerable: true, get: function () { return __importDefault(getValueFromUA_1).default; } });
9
- var XinhuaClient_1 = require("./XinhuaClient");
10
- Object.defineProperty(exports, "XinhuaClient", { enumerable: true, get: function () { return __importDefault(XinhuaClient_1).default; } });
1
+ export { default as XinhuaClient } from './XinhuaClient';
2
+ export { default as getValueFromUA } from './getValueFromUA';
3
+ export { default as usePullDownRefresh } from './usePullDownRefresh';
@@ -0,0 +1,45 @@
1
+ export interface PullDownRefreshOptions {
2
+ /** 触发下拉刷新的距离阈值,默认 60px */
3
+ threshold?: number;
4
+ /** 最大下拉距离,默认 120px */
5
+ maxDistance?: number;
6
+ /** 下拉刷新的回调函数 */
7
+ onRefresh?: () => Promise<void> | void;
8
+ /** 是否禁用下拉刷新,默认 false */
9
+ disabled?: boolean;
10
+ /** 是否显示顶部指示器,默认 true */
11
+ showIndicator?: boolean;
12
+ }
13
+ export interface PullDownRefreshState {
14
+ /** 当前下拉状态 */
15
+ status: 'normal' | 'pulling' | 'loosing' | 'loading' | 'success';
16
+ /** 当前下拉距离 */
17
+ distance: number;
18
+ /** 指示器是否可见 */
19
+ indicatorVisible: boolean;
20
+ /** 指示器透明度 */
21
+ indicatorOpacity: number;
22
+ /** 指示器旋转角度 */
23
+ indicatorRotation: number;
24
+ }
25
+ declare function usePullDownRefresh(options?: PullDownRefreshOptions | (() => Promise<void> | void)): {
26
+ /** 当前状态 */
27
+ state: Readonly<import("vue").Ref<{
28
+ readonly status: "success" | "normal" | "pulling" | "loosing" | "loading";
29
+ readonly distance: number;
30
+ readonly indicatorVisible: boolean;
31
+ readonly indicatorOpacity: number;
32
+ readonly indicatorRotation: number;
33
+ }, {
34
+ readonly status: "success" | "normal" | "pulling" | "loosing" | "loading";
35
+ readonly distance: number;
36
+ readonly indicatorVisible: boolean;
37
+ readonly indicatorOpacity: number;
38
+ readonly indicatorRotation: number;
39
+ }>>;
40
+ /** 手动触发刷新 */
41
+ refresh: () => void;
42
+ /** 重置状态 */
43
+ resetState: () => void;
44
+ };
45
+ export default usePullDownRefresh;
@@ -0,0 +1,266 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ var vue_1 = require("vue");
40
+ function usePullDownRefresh(options) {
41
+ var _this = this;
42
+ if (options === void 0) { options = {}; }
43
+ // 处理参数:如果直接传递函数,则认为是 onRefresh 回调
44
+ var normalizedOptions = typeof options === 'function' ? { onRefresh: options } : options;
45
+ var _a = normalizedOptions.threshold, threshold = _a === void 0 ? 60 : _a, _b = normalizedOptions.maxDistance, maxDistance = _b === void 0 ? 120 : _b, onRefresh = normalizedOptions.onRefresh, _c = normalizedOptions.disabled, disabled = _c === void 0 ? false : _c, _d = normalizedOptions.showIndicator, showIndicator = _d === void 0 ? true : _d;
46
+ // 响应式状态
47
+ var state = (0, vue_1.ref)({
48
+ status: 'normal',
49
+ distance: 0,
50
+ indicatorVisible: false,
51
+ indicatorOpacity: 0,
52
+ indicatorRotation: 0,
53
+ });
54
+ // 触摸相关状态
55
+ var startY = 0;
56
+ var currentY = 0;
57
+ var isTracking = false;
58
+ var originalBodyStyle = '';
59
+ var indicatorElement = null;
60
+ // 创建顶部指示器元素
61
+ var createIndicator = function () {
62
+ if (!showIndicator || indicatorElement)
63
+ return;
64
+ indicatorElement = document.createElement('div');
65
+ indicatorElement.className = 'pull-refresh-indicator';
66
+ indicatorElement.innerHTML = "\n <div class=\"indicator-circle\">\n <div class=\"indicator-icon\">\n <svg width=\"20\" height=\"20\" viewBox=\"0 0 24 24\" fill=\"none\">\n <path d=\"M12 4L12 20M12 4L8 8M12 4L16 8\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>\n </svg>\n </div>\n </div>\n ";
67
+ // 添加样式
68
+ var style = document.createElement('style');
69
+ style.textContent = "\n .pull-refresh-indicator {\n position: fixed;\n top: 20px;\n left: 50%;\n transform: translateX(-50%) translateY(-100px);\n z-index: 9999;\n opacity: 0;\n transition: opacity 0.3s ease, transform 0.3s ease;\n pointer-events: none;\n }\n \n .pull-refresh-indicator.visible {\n opacity: 1;\n }\n \n .indicator-circle {\n width: 40px;\n height: 40px;\n background: #ffffff;\n border-radius: 50%;\n display: flex;\n align-items: center;\n justify-content: center;\n box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);\n border: 1px solid rgba(0, 0, 0, 0.06);\n }\n \n .indicator-icon {\n display: flex;\n align-items: center;\n justify-content: center;\n width: 20px;\n height: 20px;\n color: #1677ff;\n transition: transform 0.3s ease;\n }\n \n .indicator-icon.rotate {\n transform: rotate(180deg);\n }\n \n .indicator-icon.loading {\n animation: spin 1s linear infinite;\n }\n \n @keyframes spin {\n from { transform: rotate(0deg); }\n to { transform: rotate(360deg); }\n }\n ";
70
+ document.head.appendChild(style);
71
+ document.body.appendChild(indicatorElement);
72
+ };
73
+ // 更新指示器
74
+ var updateIndicator = function () {
75
+ if (!indicatorElement || !showIndicator)
76
+ return;
77
+ var iconElement = indicatorElement.querySelector('.indicator-icon');
78
+ if (iconElement) {
79
+ iconElement.className = 'indicator-icon';
80
+ if (state.value.status === 'loading') {
81
+ iconElement.classList.add('loading');
82
+ iconElement.innerHTML = "\n <svg width=\"20\" height=\"20\" viewBox=\"0 0 24 24\" fill=\"none\">\n <circle cx=\"12\" cy=\"12\" r=\"10\" stroke=\"currentColor\" stroke-width=\"2\" stroke-dasharray=\"31.416\" stroke-dashoffset=\"31.416\">\n <animate attributeName=\"stroke-dasharray\" dur=\"2s\" values=\"0 31.416;15.708 15.708;0 31.416\" repeatCount=\"indefinite\"/>\n <animate attributeName=\"stroke-dashoffset\" dur=\"2s\" values=\"0;-15.708;-31.416\" repeatCount=\"indefinite\"/>\n </circle>\n </svg>\n ";
83
+ }
84
+ else if (state.value.status === 'success') {
85
+ iconElement.innerHTML = "\n <svg width=\"20\" height=\"20\" viewBox=\"0 0 24 24\" fill=\"none\">\n <path d=\"M20 6L9 17L4 12\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>\n </svg>\n ";
86
+ }
87
+ else {
88
+ if (state.value.status === 'loosing') {
89
+ iconElement.classList.add('rotate');
90
+ }
91
+ iconElement.innerHTML = "\n <svg width=\"20\" height=\"20\" viewBox=\"0 0 24 24\" fill=\"none\">\n <path d=\"M12 4L12 20M12 4L8 8M12 4L16 8\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>\n </svg>\n ";
92
+ }
93
+ }
94
+ // 更新指示器位置和透明度
95
+ var progress = Math.min(state.value.distance / threshold, 1);
96
+ var translateY = -100 + progress * 120; // 从 -100px 移动到 20px
97
+ indicatorElement.style.transform = "translateX(-50%) translateY(".concat(translateY, "px)");
98
+ indicatorElement.className = "pull-refresh-indicator ".concat(state.value.distance > 0 ? 'visible' : '');
99
+ };
100
+ // 移除指示器
101
+ var removeIndicator = function () {
102
+ if (indicatorElement) {
103
+ indicatorElement.remove();
104
+ indicatorElement = null;
105
+ }
106
+ };
107
+ // 更新状态
108
+ var updateState = function (status, distance) {
109
+ state.value.status = status;
110
+ state.value.distance = distance;
111
+ state.value.indicatorVisible = distance > 0;
112
+ state.value.indicatorOpacity = Math.min(distance / threshold, 1);
113
+ switch (status) {
114
+ case 'pulling':
115
+ state.value.indicatorRotation = 0;
116
+ break;
117
+ case 'loosing':
118
+ state.value.indicatorRotation = 180;
119
+ break;
120
+ case 'loading':
121
+ state.value.indicatorRotation = 0;
122
+ break;
123
+ case 'success':
124
+ state.value.indicatorRotation = 0;
125
+ break;
126
+ default:
127
+ state.value.indicatorRotation = 0;
128
+ state.value.indicatorVisible = false;
129
+ state.value.indicatorOpacity = 0;
130
+ }
131
+ updateIndicator();
132
+ };
133
+ // 禁用页面弹性效果
134
+ var disableBodyBounce = function () {
135
+ originalBodyStyle = document.body.style.cssText;
136
+ document.body.style.overscrollBehavior = 'none';
137
+ document.body.style.touchAction = 'pan-x pan-down pinch-zoom';
138
+ document.documentElement.style.overscrollBehavior = 'none';
139
+ document.documentElement.style.touchAction = 'pan-x pan-down pinch-zoom';
140
+ };
141
+ // 恢复页面弹性效果
142
+ var restoreBodyBounce = function () {
143
+ document.body.style.cssText = originalBodyStyle;
144
+ document.documentElement.style.overscrollBehavior = '';
145
+ document.documentElement.style.touchAction = '';
146
+ };
147
+ // 检查是否可以下拉(页面级检查)
148
+ var canPullDown = function () {
149
+ if (disabled)
150
+ return false;
151
+ // 检查页面是否滚动到顶部
152
+ var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
153
+ return scrollTop === 0;
154
+ };
155
+ // 触摸开始
156
+ var onTouchStart = function (event) {
157
+ if (!canPullDown())
158
+ return;
159
+ startY = event.touches[0].clientY;
160
+ isTracking = true;
161
+ };
162
+ // 触摸移动
163
+ var onTouchMove = function (event) {
164
+ if (!isTracking || !canPullDown())
165
+ return;
166
+ currentY = event.touches[0].clientY;
167
+ var deltaY = currentY - startY;
168
+ if (deltaY > 0) {
169
+ // 阻止默认滚动行为和弹性效果
170
+ event.preventDefault();
171
+ // 计算下拉距离,使用阻尼效果
172
+ var distance = Math.min(deltaY * 0.6, maxDistance);
173
+ if (distance >= threshold && state.value.status !== 'loosing') {
174
+ updateState('loosing', distance);
175
+ }
176
+ else if (distance < threshold && state.value.status !== 'pulling') {
177
+ updateState('pulling', distance);
178
+ }
179
+ else {
180
+ state.value.distance = distance;
181
+ updateIndicator();
182
+ }
183
+ }
184
+ };
185
+ // 触摸结束
186
+ var onTouchEnd = function () {
187
+ if (!isTracking)
188
+ return;
189
+ isTracking = false;
190
+ if (state.value.status === 'loosing') {
191
+ // 触发刷新
192
+ triggerRefresh();
193
+ }
194
+ else {
195
+ // 重置状态
196
+ resetState();
197
+ }
198
+ };
199
+ // 触发刷新
200
+ var triggerRefresh = function () { return __awaiter(_this, void 0, void 0, function () {
201
+ var error_1;
202
+ return __generator(this, function (_a) {
203
+ switch (_a.label) {
204
+ case 0:
205
+ updateState('loading', threshold);
206
+ _a.label = 1;
207
+ case 1:
208
+ _a.trys.push([1, 4, , 5]);
209
+ if (!onRefresh) return [3 /*break*/, 3];
210
+ return [4 /*yield*/, onRefresh()];
211
+ case 2:
212
+ _a.sent();
213
+ _a.label = 3;
214
+ case 3:
215
+ // 显示成功状态
216
+ updateState('success', threshold);
217
+ // 延迟重置状态
218
+ setTimeout(function () {
219
+ resetState();
220
+ }, 500);
221
+ return [3 /*break*/, 5];
222
+ case 4:
223
+ error_1 = _a.sent();
224
+ console.error('下拉刷新失败:', error_1);
225
+ resetState();
226
+ return [3 /*break*/, 5];
227
+ case 5: return [2 /*return*/];
228
+ }
229
+ });
230
+ }); };
231
+ // 重置状态
232
+ var resetState = function () {
233
+ updateState('normal', 0);
234
+ };
235
+ // 手动触发刷新
236
+ var refresh = function () {
237
+ if (disabled || state.value.status === 'loading')
238
+ return;
239
+ triggerRefresh();
240
+ };
241
+ // 组件挂载时添加事件监听和禁用弹性效果
242
+ (0, vue_1.onMounted)(function () {
243
+ disableBodyBounce();
244
+ createIndicator();
245
+ document.addEventListener('touchstart', onTouchStart, { passive: false });
246
+ document.addEventListener('touchmove', onTouchMove, { passive: false });
247
+ document.addEventListener('touchend', onTouchEnd);
248
+ });
249
+ // 组件卸载时移除事件监听和恢复弹性效果
250
+ (0, vue_1.onUnmounted)(function () {
251
+ restoreBodyBounce();
252
+ removeIndicator();
253
+ document.removeEventListener('touchstart', onTouchStart);
254
+ document.removeEventListener('touchmove', onTouchMove);
255
+ document.removeEventListener('touchend', onTouchEnd);
256
+ });
257
+ return {
258
+ /** 当前状态 */
259
+ state: (0, vue_1.readonly)(state),
260
+ /** 手动触发刷新 */
261
+ refresh: refresh,
262
+ /** 重置状态 */
263
+ resetState: resetState,
264
+ };
265
+ }
266
+ exports.default = usePullDownRefresh;
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "rexma-design",
3
- "version": "2.0.2",
3
+ "version": "2.1.0",
4
4
  "scripts": {
5
5
  "start": "vue-cli-service serve",
6
6
  "build": "vue-cli-service build",
7
- "build:lib": "rm -rf lib && tsc --project tsconfig.lib.json",
7
+ "build:lib": "gulp build",
8
8
  "lint": "vue-cli-service lint",
9
9
  "prepare": "husky install"
10
10
  },
@@ -43,15 +43,16 @@
43
43
  "eslint-plugin-prettier": "^4.0.0",
44
44
  "eslint-plugin-vue": "^8.0.3",
45
45
  "eslint-webpack-plugin": "3.2.0",
46
+ "gulp": "^5.0.1",
47
+ "gulp-clean-css": "^4.3.0",
48
+ "gulp-rename": "^2.1.0",
49
+ "gulp-typescript": "^6.0.0-alpha.1",
50
+ "gulp-uglify": "^3.0.2",
46
51
  "husky": "8.0.3",
47
52
  "ky": "^1.8.1",
48
53
  "lib-flexible": "^0.3.2",
49
- "pinia": "^3.0.3",
50
- "vant": "^4.9.20",
51
- "vue": "^3.2.13",
52
- "vue-router": "^4.0.3",
53
- "xinhua-sdk": "^1.15.8",
54
54
  "lint-staged": "13.3.0",
55
+ "pinia": "^3.0.3",
55
56
  "postcss-pxtorem": "^6.1.0",
56
57
  "prettier": "^2.4.1",
57
58
  "prettier-plugin-organize-imports": "^4.1.0",
@@ -60,6 +61,10 @@
60
61
  "typescript": "~4.5.5",
61
62
  "unplugin-auto-import": "^19.3.0",
62
63
  "unplugin-vue-components": "^28.7.0",
63
- "vue-tsc": "^2.2.10"
64
+ "vant": "^4.9.20",
65
+ "vue": "^3.2.13",
66
+ "vue-router": "^4.0.3",
67
+ "vue-tsc": "^2.2.10",
68
+ "xinhua-sdk": "^1.15.8"
64
69
  }
65
70
  }