@taole/dev-helper 0.0.4 → 0.0.6

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.
package/Tdiv/index.svelte CHANGED
@@ -12,7 +12,7 @@
12
12
  * @type {boolean}
13
13
  * 默认false, 传入true表示直接使用px单位,一般使用场景比如pc
14
14
  */
15
- export let usePx = false;
15
+ export let usePx = null;
16
16
 
17
17
  /**
18
18
  * @type {string}
@@ -140,12 +140,16 @@
140
140
  if(viewportUnit){
141
141
  vUnit = viewportUnit;
142
142
  }
143
+ let localUsePx = setting.usePx;
144
+ if(typeof usePx === 'boolean'){
145
+ localUsePx = usePx;
146
+ }
143
147
  // @ts-ignore
144
148
  if (typeof value === "string" && !isNaN(value)) {
145
149
  value = Number(value);
146
150
  }
147
151
  if (typeof value === "number") {
148
- if (usePx) {
152
+ if (localUsePx) {
149
153
  return value + "px";
150
154
  }
151
155
  let val = ((value / vWidth) * 100).toFixed(4); // 4?
package/Tdiv/index.vue CHANGED
@@ -11,7 +11,7 @@ export default {
11
11
  name: 'Tdiv',
12
12
  props: {
13
13
  _class: { type: String, default: '' },
14
- usePx: { type: Boolean, default: false },
14
+ usePx: { type: Boolean, default: null },
15
15
  style: { type: String, default: '' },
16
16
  src: { type: String, default: '' },
17
17
  width: { type: [Number, String], default: null },
@@ -44,11 +44,15 @@ export default {
44
44
  if (this.viewportUnit) {
45
45
  vUnit = this.viewportUnit;
46
46
  }
47
+ let localUsePx = setting.usePx;
48
+ if(typeof this.usePx === 'boolean'){
49
+ localUsePx = this.usePx;
50
+ }
47
51
  const calc = (value) => {
48
52
 
49
53
  if (typeof value === 'string' && !isNaN(value)) value = Number(value);
50
54
  if (typeof value === 'number') {
51
- if (this.usePx) return value + 'px';
55
+ if (localUsePx) return value + 'px';
52
56
  let val = ((value / vWidth) * 100).toFixed(4);
53
57
  return `${val}${vUnit}`;
54
58
  }
package/Tdiv/setting.js CHANGED
@@ -1,14 +1,31 @@
1
1
  const config = {
2
2
  viewportWidth: 750,
3
3
  viewportUnit: "vw",
4
+ usePx: false,
4
5
  }
5
6
 
7
+ /**
8
+ * 设置视口宽度
9
+ * @param {number} width
10
+ */
6
11
  export function setViewportWidth(width) {
7
12
  config.viewportWidth = width;
8
13
  }
9
14
 
15
+ /**
16
+ * 设置视口单位
17
+ * @param {string} unit
18
+ */
10
19
  export function setViewportUnit(unit) {
11
20
  config.viewportUnit = unit;
12
21
  }
13
22
 
23
+ /**
24
+ * 设置是否使用px
25
+ * @param {boolean} use
26
+ */
27
+ export function setUsePx(use) {
28
+ config.usePx = use;
29
+ }
30
+
14
31
  export default config;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taole/dev-helper",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"