소스 검색

uniapp提交

lzj500 1 년 전
커밋
32acd9b6df

+ 22 - 0
uniapp/.gitignore

@@ -0,0 +1,22 @@
+# Logs
+logs
+*.log
+npm-debug.log*
+yarn-debug.log*
+yarn-error.log*
+pnpm-debug.log*
+lerna-debug.log*
+*.lock
+
+node_modules
+.DS_Store
+dist
+*.local
+
+# Editor directories and files
+.idea
+*.suo
+*.ntvs*
+*.njsproj
+*.sln
+*.sw?

+ 6 - 0
uniapp/.npmignore

@@ -0,0 +1,6 @@
+node_modules/
+test/
+*.lock
+发布教程.md
+test2.ts
+src/

+ 85 - 0
uniapp/package-lock.json

@@ -0,0 +1,85 @@
+{
+  "name": "@ycxxkj/uniapp",
+  "version": "1.0.9",
+  "lockfileVersion": 2,
+  "requires": true,
+  "packages": {
+    "": {
+      "name": "@ycxxkj/uniapp",
+      "version": "1.0.9",
+      "license": "ISC",
+      "dependencies": {
+        "await-to-js": "^3.0.0"
+      },
+      "devDependencies": {
+        "@dcloudio/types": "^3.3.3",
+        "typescript": "^5.1.6"
+      }
+    },
+    "C:/Programs/nvm/v16.17.1/node_modules/@ycxxkj/uniapp": {
+      "version": "1.0.0",
+      "extraneous": true,
+      "license": "ISC",
+      "dependencies": {
+        "await-to-js": "^3.0.0"
+      },
+      "devDependencies": {
+        "@dcloudio/types": "^3.3.3",
+        "@types/chai": "^4.3.5",
+        "@types/mocha": "^10.0.1",
+        "chai": "^4.3.7",
+        "mocha": "^10.2.0",
+        "typescript": "^5.1.6"
+      }
+    },
+    "node_modules/@dcloudio/types": {
+      "version": "3.3.3",
+      "resolved": "https://registry.npmjs.org/@dcloudio/types/-/types-3.3.3.tgz",
+      "integrity": "sha512-xfp88QOJ2fgCzv49HhEGrX0L+3xDsCyyvcoApL7z0J1Lr7tqPUkxqAVBe9zBlKsDX/mO9mNj7NzKIisHfp+fNQ==",
+      "dev": true,
+      "license": "Apache-2.0"
+    },
+    "node_modules/await-to-js": {
+      "version": "3.0.0",
+      "resolved": "https://registry.npmjs.org/await-to-js/-/await-to-js-3.0.0.tgz",
+      "integrity": "sha512-zJAaP9zxTcvTHRlejau3ZOY4V7SRpiByf3/dxx2uyKxxor19tpmpV2QRsTKikckwhaPmr2dVpxxMr7jOCYVp5g==",
+      "license": "MIT",
+      "engines": {
+        "node": ">=6.0.0"
+      }
+    },
+    "node_modules/typescript": {
+      "version": "5.1.6",
+      "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.1.6.tgz",
+      "integrity": "sha512-zaWCozRZ6DLEWAWFrVDz1H6FVXzUSfTy5FUMWsQlU8Ym5JP9eO4xkTIROFCQvhQf61z6O/G6ugw3SgAnvvm+HA==",
+      "dev": true,
+      "license": "Apache-2.0",
+      "bin": {
+        "tsc": "bin/tsc",
+        "tsserver": "bin/tsserver"
+      },
+      "engines": {
+        "node": ">=14.17"
+      }
+    }
+  },
+  "dependencies": {
+    "@dcloudio/types": {
+      "version": "3.3.3",
+      "resolved": "https://registry.npmjs.org/@dcloudio/types/-/types-3.3.3.tgz",
+      "integrity": "sha512-xfp88QOJ2fgCzv49HhEGrX0L+3xDsCyyvcoApL7z0J1Lr7tqPUkxqAVBe9zBlKsDX/mO9mNj7NzKIisHfp+fNQ==",
+      "dev": true
+    },
+    "await-to-js": {
+      "version": "3.0.0",
+      "resolved": "https://registry.npmjs.org/await-to-js/-/await-to-js-3.0.0.tgz",
+      "integrity": "sha512-zJAaP9zxTcvTHRlejau3ZOY4V7SRpiByf3/dxx2uyKxxor19tpmpV2QRsTKikckwhaPmr2dVpxxMr7jOCYVp5g=="
+    },
+    "typescript": {
+      "version": "5.1.6",
+      "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.1.6.tgz",
+      "integrity": "sha512-zaWCozRZ6DLEWAWFrVDz1H6FVXzUSfTy5FUMWsQlU8Ym5JP9eO4xkTIROFCQvhQf61z6O/G6ugw3SgAnvvm+HA==",
+      "dev": true
+    }
+  }
+}

+ 29 - 0
uniapp/package.json

@@ -0,0 +1,29 @@
+{
+  "name": "@ycxxkj/uniapp",
+  "version": "1.0.9",
+  "description": "ycxxkj uniapp libs",
+  "main": "./dist/index.js",
+  "types": "./dist/index.d.ts",
+  "scripts": {
+    "prepublish": "npm run build",
+    "test": "mocha --reporter spec",
+    "build": "npm version patch && tsc"
+  },
+  "repository": {
+    "type": "git",
+    "url": "https://github.com/sgsycxxkj/ycxxkj-uniapp"
+  },
+  "keywords": [
+    "uniapp"
+  ],
+  "type": "module",
+  "author": "ycxxkj",
+  "license": "ISC",
+  "devDependencies": {
+    "@dcloudio/types": "^3.3.3",
+    "typescript": "^5.1.6"
+  },
+  "dependencies": {
+    "await-to-js": "^3.0.0"
+  }
+}

+ 17 - 0
uniapp/src/index.ts

@@ -0,0 +1,17 @@
+// import Base64Heler from "./libs/Base64";
+// import RegHelper from "./libs/Reg";
+// import StorageHelper from "./libs/Storage";
+// import StringUtilHelper from "./libs/StringUtil";
+// import UniHelper from "./libs/UniHelper";
+// export const Base64=Base64Heler;
+// export const Reg = RegHelper;
+// export const Storage = StorageHelper;
+// export const StringUtil = StringUtilHelper;
+// export const Uniapp = UniHelper;
+import YcBase64 from "./libs/Base64";
+import YcReg from "./libs/Reg";
+import YcStorage from "./libs/Storage";
+import YcStringUtil from "./libs/StringUtil";
+import YcUniapp from "./libs/UniHelper";
+import Yc from "./libs/Yc";
+export { YcBase64, YcReg, YcStorage, YcStringUtil, YcUniapp, Yc };

+ 94 - 0
uniapp/src/libs/Base64.ts

@@ -0,0 +1,94 @@
+const Base64 = {
+	_keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
+	encode: function (e: any) {
+		var t = "";
+		var n, r, i, s, o, u, a;
+		var f = 0;
+		e = Base64._utf8_encode(e);
+		while (f < e.length) {
+			n = e.charCodeAt(f++);
+			r = e.charCodeAt(f++);
+			i = e.charCodeAt(f++);
+			s = n >> 2;
+			o = (n & 3) << 4 | r >> 4;
+			u = (r & 15) << 2 | i >> 6;
+			a = i & 63;
+			if (isNaN(r)) {
+				u = a = 64
+			} else if (isNaN(i)) {
+				a = 64
+			}
+			t = t + this._keyStr.charAt(s) + this._keyStr.charAt(o) + this._keyStr.charAt(u) + this._keyStr.charAt(a)
+		}
+		return t
+	},
+	decode: function (e: any) {
+		var t = "";
+		var n, r, i;
+		var s, o, u, a;
+		var f = 0;
+		e = e.replace(/[^A-Za-z0-9+/=]/g, "");
+		while (f < e.length) {
+			s = this._keyStr.indexOf(e.charAt(f++));
+			o = this._keyStr.indexOf(e.charAt(f++));
+			u = this._keyStr.indexOf(e.charAt(f++));
+			a = this._keyStr.indexOf(e.charAt(f++));
+			n = s << 2 | o >> 4;
+			r = (o & 15) << 4 | u >> 2;
+			i = (u & 3) << 6 | a;
+			t = t + String.fromCharCode(n);
+			if (u != 64) {
+				t = t + String.fromCharCode(r)
+			}
+			if (a != 64) {
+				t = t + String.fromCharCode(i)
+			}
+		}
+		t = Base64._utf8_decode(t);
+		return t
+	},
+	_utf8_encode: function (e: any) {
+		e = e.replace(/rn/g, "n");
+		var t = "";
+		for (var n = 0; n < e.length; n++) {
+			var r = e.charCodeAt(n);
+			if (r < 128) {
+				t += String.fromCharCode(r)
+			} else if (r > 127 && r < 2048) {
+				t += String.fromCharCode(r >> 6 | 192);
+				t += String.fromCharCode(r & 63 | 128)
+			} else {
+				t += String.fromCharCode(r >> 12 | 224);
+				t += String.fromCharCode(r >> 6 & 63 | 128);
+				t += String.fromCharCode(r & 63 | 128)
+			}
+		}
+		return t
+	},
+	_utf8_decode: function (e: any) {
+		var t = "";
+		var n = 0;
+		let c1, c2, c3;
+		var r = c1 = c2 = 0;
+		while (n < e.length) {
+			r = e.charCodeAt(n);
+			if (r < 128) {
+				t += String.fromCharCode(r);
+				n++
+			} else if (r > 191 && r < 224) {
+				c2 = e.charCodeAt(n + 1);
+				t += String.fromCharCode((r & 31) << 6 | c2 & 63);
+				n += 2
+			} else {
+				c2 = e.charCodeAt(n + 1);
+				c3 = e.charCodeAt(n + 2);
+				t += String.fromCharCode((r & 15) << 12 | (c2 & 63) << 6 | c3 & 63);
+				n += 3
+			}
+		}
+		return t
+	}
+}
+
+
+export default Base64

+ 8 - 0
uniapp/src/libs/Reg.ts

@@ -0,0 +1,8 @@
+const Reg = {
+	phone(phoneNumber: string) {
+		var pattern = /^1[3456789]\d{9}$/;
+		return pattern.test(phoneNumber);
+	}
+};
+
+export default Reg;

+ 38 - 0
uniapp/src/libs/Storage.ts

@@ -0,0 +1,38 @@
+let prifix = "";
+let randomString = (len: number) => {
+	len = len || 32;
+	let $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';    /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/
+	let maxPos = $chars.length;
+	let pwd = '';
+	for (let i = 0; i < len; i++) {
+		pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
+	}
+	return pwd;
+}
+const Storage = {
+	getPrifix(len:number=2): string {
+		if (!prifix ) {
+			prifix = uni.getStorageSync("prifix") || randomString(len) + "_";
+			uni.setStorageSync("prifix", prifix);
+		}
+		return prifix;
+	},
+	set(key: string, data: string): void {
+		uni.setStorageSync(this.getPrifix() + key, data);
+	},
+	get(key: string): any {
+		return uni.getStorageSync(this.getPrifix() + key);
+	},
+	remove(key: string): void {
+		return uni.removeStorageSync(this.getPrifix() + key);
+	},
+	clear(): void {
+		uni.getStorageInfoSync().keys.forEach((key) => {
+			if (key.indexOf(this.getPrifix()) == 0) {
+				uni.removeStorageSync(key);
+			}
+		});
+		// return uni.clearStorageSync();
+	}
+};
+export default Storage;

+ 23 - 0
uniapp/src/libs/StringUtil.ts

@@ -0,0 +1,23 @@
+const StringUtil = {
+  arrayStringVal(data: Array<any>) {
+    for (const index in data) {
+      data[index] = String(data[index]);
+    }
+    return data;
+  },
+  parseString(obj: any) {
+    if (!obj && typeof obj !== 'undefined' && obj != 0) {
+      return '';
+    }
+    if (typeof obj === 'undefined') {
+      return '';
+    }
+    if (typeof obj === 'number' && isNaN(obj)) {
+      return '0';
+    }
+    return obj.toString();
+  }
+  ,
+};
+
+export default StringUtil;

+ 203 - 0
uniapp/src/libs/UniHelper.ts

@@ -0,0 +1,203 @@
+// import MapHelper from "./map_helper";
+import to from "await-to-js";
+const UniHelper = {
+	async login() {
+		return new Promise((resolve, reject) => {
+			uni.login({
+				provider: "weixin",
+				success: (res) => {
+					console.log(res.code);
+					resolve(res);
+				},
+				fail: (res) => {
+					reject(res);
+				}
+			});
+		});
+	},
+	//扫描
+	takePhoto() {
+		return new Promise((resolve, reject) => {
+			uni.scanCode({
+				scanType: ["qrcode"],
+				success: (res) => {
+					resolve(res.result);
+				}
+			});
+		});
+	},
+	copyText(data: string) {
+		return new Promise((resolve, reject) => {
+			uni.setClipboardData({
+				data: data,
+				success: function () {
+					console.log("success");
+					resolve(true);
+				}
+			});
+		});
+	},
+	previewImage(images: Array<string>, current = 0) {
+		console.log("previewImage", images);
+		uni.previewImage({
+			urls: images,
+			current: current,
+			longPressActions: {
+				itemList: ["发送给朋友", "保存图片", "收藏"],
+				success: function (data) {
+					console.log("选中了第" + (data.tapIndex + 1) + "个按钮,第" + (data.index + 1) + "张图片");
+				},
+				fail: function (err) {
+					console.log(err.errMsg);
+				}
+			}
+		});
+	},
+	///========消息=============
+	toast(title: string, duration = 2000, icon: any = "none") {
+		return new Promise((resolve, reject) => {
+			uni.showToast({
+				title: title,
+				duration: duration,
+				icon: icon,
+				success: function () {
+					resolve(true);
+				}
+			});
+		});
+	},
+	//隐藏键盘
+	hideKeyboard(timeout: number = 200) {
+		return new Promise(() => {
+			setTimeout(() => {
+				uni.hideKeyboard();
+			}, timeout);
+		});
+	},
+	/**
+	 * 加载中
+	 * @param {*} title
+	 */
+	loading(title: string = "加载中...") {
+		uni.showLoading({
+			title: title,
+			mask: true
+		});
+	},
+	/**
+	 *  隐藏 loading 提示框
+	 */
+	hideLoading() {
+		uni.hideLoading();
+	},
+	/**
+	 * 消息提示,有确认按钮
+	 * @param {*} msg
+	 */
+	alert(msg: string) {
+		return new Promise((resolve, reject) => {
+			uni.showModal({
+				content: msg,
+				showCancel: false,
+				success: function () {
+					resolve(true);
+				}
+			});
+		});
+	},
+	/**
+	 * 消息二次确认
+	 * @param {*} title
+	 * @param {*} content
+	 * @returns
+	 */
+	async confirm(title: string, content: string) {
+		return new Promise((resolve, reject) => {
+			uni.showModal({
+				title: title,
+				content: content,
+				success: function (res) {
+					if (res.confirm) {
+						console.log("用户点击确定");
+						resolve(true);
+					} else if (res.cancel) {
+						console.log("用户点击取消");
+						resolve(false);
+					}
+				}
+			});
+		});
+	},
+	////////==========上传============//////////////////////////
+	/**
+	 * 选1张图片
+	 * @returns
+	 */
+	async simpleChooseImage() {
+		let [err, res]: [any, any] = await to(this.chooseImage(1));
+		console.log("simpleChooseImage", err, res);
+		return res.tempFilePaths[0];
+	},
+	/**
+	 * 选图片,改promise
+	 * @param {*} count
+	 * @param {*} sizeType
+	 * @param {*} sourceType
+	 * @returns
+	 */
+	chooseImage(count: number = 9, sizeType = ["compressed"], sourceType = ["album", "camera "]) {
+		return new Promise((resolve, reject) => {
+			uni.chooseImage({
+				count, //默认9
+				sizeType, //: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
+				sourceType: ["album"], //从相册选择
+				success: function (res) {
+					console.log(JSON.stringify(res.tempFilePaths));
+					resolve(res);
+				}
+			});
+		});
+	},
+	async scanCode(onlyFromCamera: boolean = false, scanType: string[] = ["qrCode", "barCode"]) {
+		return new Promise((resolve, reject) => {
+			uni.scanCode({
+				onlyFromCamera,
+				scanType,
+				success: function (res) {
+					resolve({ code: 0, ...res });
+				},
+				fail: function (res) {
+					reject({ code: 999, msg: res.errMsg, ...res });
+				}
+			});
+		});
+	}
+	/* getLocation(type = "gcj02") {
+        return new Promise((resolve, reject) => {
+            uni.getLocation({
+                geocode: true,
+                success: async function (res) {
+ 
+                    console.log("当前位置: res", res);
+                    console.log("当前位置的经度:" + res.longitude);
+                    console.log("当前位置的纬度:" + res.latitude);
+                    let res1 = MapHelper.wgs84togcj02(res.latitude, res.longitude);
+                    res.latitude = res1.lat;
+                    res.longitude = res1.lon;
+                    res.lat = res1.lat;
+                    res.lng = res1.lon;
+                    resolve(res);
+                    // uni.showModal({
+                    //     content: "当前位置的经度:" + res.longitude + "当前位置的纬度:" + res.latitude + "," + JSON.stringify(res1)
+                    // })
+ 
+                },
+                fail: function (res) {
+                    resolve(false);
+                }
+            });
+        });
+    } */
+};
+
+export default UniHelper;

+ 21 - 0
uniapp/src/libs/Yc.ts

@@ -0,0 +1,21 @@
+
+const Yc = {
+    getVersion() {
+        return "@ycxxkj/uniapp v1.0.7";
+        
+    },
+    /**
+     * X毫秒后执行
+     * @param milliseconds 
+     * @returns 
+     */
+    delay (milliseconds: number): Promise<boolean> {
+		return new Promise((resolve, reject) => {
+			setTimeout(function (e: any) {
+				e = true;
+				resolve(e);
+			}, milliseconds);
+		});
+	},
+};
+export default Yc;

+ 19 - 0
uniapp/tsconfig.json

@@ -0,0 +1,19 @@
+{
+  "compilerOptions": {
+    /* Visit https://aka.ms/tsconfig to read more about this file */
+    "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
+    /* Modules */
+    "module": "commonjs", /* Specify what module code is generated. */
+    "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
+    // "preserveSymlinks": true,                         /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
+    "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
+    /* Type Checking */
+    "strict": true, /* Enable all strict type-checking options. */
+    "declaration": true, // 生成 `.d.ts` 文件
+    "outDir": "./dist", // 编译后生成的文件目录
+    "skipLibCheck": true, /* Skip type checking all .d.ts files. */
+    "types": [
+      "@dcloudio/types"
+    ]
+  }
+}

+ 130 - 0
uniapp/发布教程.md

@@ -0,0 +1,130 @@
+# 发布教程
+Step 1 
+```
+npm init  # 或者使用, npm init -y 跳过所有提问
+```
+Step 2  根据提示,填写相应信息,得到 package.json文件
+```
+# package.json
+
+{
+  "name": "ts-hi",
+  "version": "0.0.1",
+  "description": "create npm package with typescript",
+  "main": "index.js",
+  "scripts": {
+    "test": "echo \"Error: no test specified\" && exit 1"
+  },
+  "repository": {
+    "type": "git",
+    "url": "git+https://github.com/youthcity/ts-hi.git"
+  },
+  "keywords": [
+    "typescript"
+  ],
+  "author": "youthcity",
+  "license": "ISC",
+  "bugs": {
+    "url": "https://github.com/youthcity/ts-hi/issues"
+  },
+  "homepage": "https://github.com/youthcity/ts-hi#readme"
+}
+```
+Step 3 安装依赖
+安装 Typescript
+```
+# 使用 npm 安装
+npm i typescript -D
+
+# 或使用 yarn 进行安装
+yarn add typescript -D
+```
+
+配置 tsconfig.json 文件
+手动创建配置文件,文件如下
+
+```
+{
+  "compilerOptions": {
+    "target": "es5",
+    "module": "commonjs",
+    "declaration": true,
+    "outDir": "./dist",
+    "strict": true
+  }
+}
+```
+使用命令行创建。
+```
+# 需要全局安装 typescript包
+yarn add i typescript -D
+npm i typescript -D
+tsc --init 
+
+# 使用当前项目中的 typescript
+./node_modules/.bin/tsc --init
+```
+
+Step 6 编写测试
+1)安装测试框架和断言库
+```
+npm i mocha -D
+npm i chai -D
+yarn add  mocha -D
+yarn add chai -D
+```
+2)创建测试文件目录和文件
+
+根目录下
+```
+mkdir test && touch test/test.js
+test.js
+```
+```
+'use strict';
+const expect = require('chai').expect;
+const add = require('../dist/index').add;
+
+describe('ts-hi function test', () => {
+  it('should return 2', () => {
+    const result = add(1, 1);
+    expect(result).to.equal(2);
+  });
+});
+```
+
+Step 7 运行测试
+添加测试脚本
+```
+  "scripts": {
+    "build": "tsc",
+    "test": "mocha --reporter spec"
+  },
+```
+运行测试脚本
+```
+npm run test
+```
+
+# 版本管理
+## 版本升级 
+```
+# From 1.0.0 -> 1.0.1
+npm version patch 
+
+# From 1.0.1 -> 1.1.0
+npm version minor
+
+# From 1.1.0 -> 2.0.0
+npm version major
+```
+## 版本发布
+```
+npm publish --access public 
+```
+
+## 版本删除 
+```
+npm unpublish @ycxxkj/uniapp@1.0.0 --force
+```
+