qy-better-lib 0.0.1

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.
Files changed (185) hide show
  1. package/.vscode/extensions.json +3 -0
  2. package/LICENSE +24 -0
  3. package/README.md +2 -0
  4. package/index.html +13 -0
  5. package/package.json +37 -0
  6. package/packages/core/DOCUMENTATION.md +2681 -0
  7. package/packages/core/LICENSE +24 -0
  8. package/packages/core/package.json +67 -0
  9. package/packages/core/types/index.d.ts +39 -0
  10. package/packages/core/types/json.d.ts +4 -0
  11. package/packages/core/types/vue.shim.d.ts +5 -0
  12. package/packages/core/vitest.config.ts +15 -0
  13. package/packages/core/yarn.lock +1233 -0
  14. package/packages/hooks/DOCUMENTATION.md +634 -0
  15. package/packages/hooks/LICENSE +24 -0
  16. package/packages/hooks/__tests__/use-chart/index.test.ts +287 -0
  17. package/packages/hooks/__tests__/use-emit/index.test.ts +248 -0
  18. package/packages/hooks/__tests__/use-fullscreen/index.test.ts +162 -0
  19. package/packages/hooks/__tests__/use-image/index.test.ts +230 -0
  20. package/packages/hooks/__tests__/use-layout-flow/index.test.ts +382 -0
  21. package/packages/hooks/__tests__/use-mqtt/index.test.ts +392 -0
  22. package/packages/hooks/__tests__/use-print/index.test.ts +378 -0
  23. package/packages/hooks/__tests__/use-watermark/index.test.ts +277 -0
  24. package/packages/hooks/__tests__/use-websocket/index.test.ts +402 -0
  25. package/packages/hooks/package.json +104 -0
  26. package/packages/hooks/types/index.d.ts +1 -0
  27. package/packages/hooks/types/json.d.ts +4 -0
  28. package/packages/hooks/types/vue.shim.d.ts +5 -0
  29. package/packages/hooks/yarn.lock +1832 -0
  30. package/packages/lowcode/core/package.json +60 -0
  31. package/packages/lowcode/core/types/index.d.ts +1 -0
  32. package/packages/lowcode/core/types/json.d.ts +4 -0
  33. package/packages/lowcode/core/types/vue.shim.d.ts +5 -0
  34. package/packages/lowcode/core/vite.dist.min.config.js +40 -0
  35. package/packages/lowcode/core/vite.dist.min.config.js.map +1 -0
  36. package/packages/lowcode/core/vite.lib.config.js +74 -0
  37. package/packages/lowcode/core/vite.lib.config.js.map +1 -0
  38. package/packages/lowcode/core/yarn.lock +1132 -0
  39. package/packages/lowcode/mobile/package.json +63 -0
  40. package/packages/lowcode/mobile/types/index.d.ts +1 -0
  41. package/packages/lowcode/mobile/types/json.d.ts +4 -0
  42. package/packages/lowcode/mobile/types/vue.shim.d.ts +77 -0
  43. package/packages/lowcode/mobile/vite.config.js +11 -0
  44. package/packages/lowcode/mobile/vite.config.js.map +1 -0
  45. package/packages/lowcode/mobile/vite.dist.min.config.js +71 -0
  46. package/packages/lowcode/mobile/vite.dist.min.config.js.map +1 -0
  47. package/packages/lowcode/mobile/vite.lib.config.js +137 -0
  48. package/packages/lowcode/mobile/vite.lib.config.js.map +1 -0
  49. package/packages/lowcode/mobile/yarn.lock +3888 -0
  50. package/packages/lowcode/pc/package.json +64 -0
  51. package/packages/lowcode/pc/vite.config.js +11 -0
  52. package/packages/lowcode/pc/vite.config.js.map +1 -0
  53. package/packages/lowcode/pc/vite.dist.min.config.js +71 -0
  54. package/packages/lowcode/pc/vite.dist.min.config.js.map +1 -0
  55. package/packages/lowcode/pc/vite.lib.config.js +137 -0
  56. package/packages/lowcode/pc/vite.lib.config.js.map +1 -0
  57. package/packages/lowcode/pc/yarn.lock +4026 -0
  58. package/packages/pc_components/DOCUMENTATION.md +566 -0
  59. package/packages/pc_components/LICENSE +24 -0
  60. package/packages/pc_components/lib/commDialog/index.d.ts +3 -0
  61. package/packages/pc_components/lib/commDialog/index.js +8 -0
  62. package/packages/pc_components/lib/commDialog/src/index.vue.d.ts +102 -0
  63. package/packages/pc_components/lib/commDialog/src/index.vue.js +43 -0
  64. package/packages/pc_components/lib/commDialog/src/index.vue2.js +4 -0
  65. package/packages/pc_components/lib/commDialog/src/props.d.ts +49 -0
  66. package/packages/pc_components/lib/commDialog/src/props.js +48 -0
  67. package/packages/pc_components/lib/commDialog/src/type.d.ts +39 -0
  68. package/packages/pc_components/lib/commForm/index.d.ts +3 -0
  69. package/packages/pc_components/lib/commForm/index.js +8 -0
  70. package/packages/pc_components/lib/commForm/src/index.vue.d.ts +95 -0
  71. package/packages/pc_components/lib/commForm/src/index.vue.js +50 -0
  72. package/packages/pc_components/lib/commForm/src/index.vue2.js +4 -0
  73. package/packages/pc_components/lib/commForm/src/props.d.ts +49 -0
  74. package/packages/pc_components/lib/commForm/src/props.js +47 -0
  75. package/packages/pc_components/lib/commForm/src/type.d.ts +8 -0
  76. package/packages/pc_components/lib/contextMenu/index.d.ts +5 -0
  77. package/packages/pc_components/lib/contextMenu/index.js +8 -0
  78. package/packages/pc_components/lib/contextMenu/src/index.vue.d.ts +91 -0
  79. package/packages/pc_components/lib/contextMenu/src/index.vue.js +153 -0
  80. package/packages/pc_components/lib/contextMenu/src/index.vue2.js +4 -0
  81. package/packages/pc_components/lib/contextMenu/src/props.d.ts +32 -0
  82. package/packages/pc_components/lib/contextMenu/src/props.js +27 -0
  83. package/packages/pc_components/lib/contextMenu/src/type.d.ts +11 -0
  84. package/packages/pc_components/lib/describeView/index.d.ts +2 -0
  85. package/packages/pc_components/lib/describeView/index.js +7 -0
  86. package/packages/pc_components/lib/describeView/src/index.vue.d.ts +61 -0
  87. package/packages/pc_components/lib/describeView/src/index.vue.js +84 -0
  88. package/packages/pc_components/lib/describeView/src/index.vue2.js +4 -0
  89. package/packages/pc_components/lib/describeView/src/props.d.ts +35 -0
  90. package/packages/pc_components/lib/describeView/src/props.js +33 -0
  91. package/packages/pc_components/lib/describeView/src/type.d.ts +10 -0
  92. package/packages/pc_components/lib/index.d.ts +18 -0
  93. package/packages/pc_components/lib/index.js +40 -0
  94. package/packages/pc_components/lib/simpleVirtualList/index.d.ts +2 -0
  95. package/packages/pc_components/lib/simpleVirtualList/index.js +7 -0
  96. package/packages/pc_components/lib/simpleVirtualList/src/index.vue.d.ts +28 -0
  97. package/packages/pc_components/lib/simpleVirtualList/src/index.vue.js +101 -0
  98. package/packages/pc_components/lib/simpleVirtualList/src/index.vue2.js +4 -0
  99. package/packages/pc_components/lib/simpleVirtualList/src/type.d.ts +12 -0
  100. package/packages/pc_components/lib/styles/comm-form.scss +4 -0
  101. package/packages/pc_components/lib/styles/context-menu.scss +47 -0
  102. package/packages/pc_components/lib/styles/describe-view.scss +25 -0
  103. package/packages/pc_components/lib/styles/index.scss +6 -0
  104. package/packages/pc_components/lib/styles/simple-virtual-list.scss +25 -0
  105. package/packages/pc_components/lib/styles/table-extend.scss +100 -0
  106. package/packages/pc_components/lib/styles/text-button.scss +71 -0
  107. package/packages/pc_components/lib/tableExtend/index.d.ts +3 -0
  108. package/packages/pc_components/lib/tableExtend/index.js +7 -0
  109. package/packages/pc_components/lib/tableExtend/props.d.ts +130 -0
  110. package/packages/pc_components/lib/tableExtend/props.js +128 -0
  111. package/packages/pc_components/lib/tableExtend/src/colVisible.vue.d.ts +3 -0
  112. package/packages/pc_components/lib/tableExtend/src/colVisible.vue.js +128 -0
  113. package/packages/pc_components/lib/tableExtend/src/colVisible.vue2.js +4 -0
  114. package/packages/pc_components/lib/tableExtend/src/index.vue.d.ts +186 -0
  115. package/packages/pc_components/lib/tableExtend/src/index.vue.js +234 -0
  116. package/packages/pc_components/lib/tableExtend/src/index.vue2.js +4 -0
  117. package/packages/pc_components/lib/tableExtend/src/valueCol.vue.d.ts +24 -0
  118. package/packages/pc_components/lib/tableExtend/src/valueCol.vue.js +29 -0
  119. package/packages/pc_components/lib/tableExtend/src/valueCol.vue2.js +4 -0
  120. package/packages/pc_components/lib/tableExtend/type.d.ts +165 -0
  121. package/packages/pc_components/lib/tableExtend/type.js +9 -0
  122. package/packages/pc_components/lib/tableExtend/useTable.d.ts +27 -0
  123. package/packages/pc_components/lib/tableExtend/useTable.js +115 -0
  124. package/packages/pc_components/lib/textButton/index.d.ts +2 -0
  125. package/packages/pc_components/lib/textButton/index.js +7 -0
  126. package/packages/pc_components/lib/textButton/src/index.vue.d.ts +42 -0
  127. package/packages/pc_components/lib/textButton/src/index.vue.js +44 -0
  128. package/packages/pc_components/lib/textButton/src/index.vue2.js +4 -0
  129. package/packages/pc_components/lib/textButton/src/props.d.ts +23 -0
  130. package/packages/pc_components/lib/textButton/src/props.js +30 -0
  131. package/packages/pc_components/lib/textButton/src/type.d.ts +30 -0
  132. package/packages/pc_components/lib/utils/index.d.ts +77 -0
  133. package/packages/pc_components/lib/utils/index.js +124 -0
  134. package/packages/pc_components/package.json +73 -0
  135. package/packages/pc_components/types/index.d.ts +9 -0
  136. package/packages/pc_components/types/json.d.ts +4 -0
  137. package/packages/pc_components/types/vue.shim.d.ts +5 -0
  138. package/packages/pc_components/yarn.lock +1641 -0
  139. package/postcss.config.js +19 -0
  140. package/public/vite.svg +1 -0
  141. package/src/App.vue +37 -0
  142. package/src/api/index.ts +42 -0
  143. package/src/assets/vue.svg +1 -0
  144. package/src/document/core.md +2680 -0
  145. package/src/document/hooks.md +632 -0
  146. package/src/document/pc_components.md +566 -0
  147. package/src/locales/en.json +1 -0
  148. package/src/locales/zh-cn.json +1 -0
  149. package/src/main.ts +13 -0
  150. package/src/plugins/element-plus.ts +16 -0
  151. package/src/plugins/i18n.ts +17 -0
  152. package/src/plugins/index.ts +13 -0
  153. package/src/plugins/store.ts +12 -0
  154. package/src/router/index.ts +20 -0
  155. package/src/shared/chartType.ts +279 -0
  156. package/src/shared/const.ts +160 -0
  157. package/src/shared/lib.ts +129 -0
  158. package/src/shared/request.ts +255 -0
  159. package/src/shared/type.ts +48 -0
  160. package/src/shared/utils/date.ts +83 -0
  161. package/src/shared/utils/utils.ts +85 -0
  162. package/src/store/index.ts +22 -0
  163. package/src/store/modules/app.ts +17 -0
  164. package/src/store/modules/shared.ts +21 -0
  165. package/src/styles/index.scss +169 -0
  166. package/src/types/app.d.ts +23 -0
  167. package/src/types/echarts.d.ts +5 -0
  168. package/src/types/index.d.ts +1 -0
  169. package/src/types/json.d.ts +4 -0
  170. package/src/types/scss.d.ts +9 -0
  171. package/src/types/vue.shim.d.ts +5 -0
  172. package/src/views/docs/docs-content.vue +379 -0
  173. package/src/views/docs/docs-header.vue +130 -0
  174. package/src/views/docs/docs-sidebar.vue +76 -0
  175. package/src/views/docs/hooks.ts +600 -0
  176. package/src/views/docs/index.vue +30 -0
  177. package/src/views/docs/styles/docs-content.scss +106 -0
  178. package/src/views/docs/styles/docs-header.scss +20 -0
  179. package/src/views/docs/styles/docs-sidebar.scss +182 -0
  180. package/src/views/docs/styles/index.scss +14 -0
  181. package/src/views/docs/type.ts +101 -0
  182. package/src/views/index.vue +34 -0
  183. package/tsconfig.json +37 -0
  184. package/tsconfig.node.json +8 -0
  185. package/vite.config.ts +54 -0
@@ -0,0 +1,279 @@
1
+ /**
2
+ * 图表结构
3
+ */
4
+ export type TypeDesignChart = {
5
+ /**组件类型 */
6
+ type: string;
7
+ /**是否坐标系图表 */
8
+ isAxis?: boolean;
9
+ /**
10
+ * 图表ID
11
+ */
12
+ chartId?: string | number;
13
+ /**
14
+ * 自定义配置
15
+ */
16
+ __config__: ChartConfig;
17
+ /**
18
+ * 标题
19
+ */
20
+ title?: string;
21
+ /**
22
+ * 提示框
23
+ */
24
+ tooltip?: ToolTip;
25
+ /**
26
+ * 图例
27
+ */
28
+ legend?: Legend;
29
+ /**
30
+ * X轴配置
31
+ */
32
+ xAxis?: Aris;
33
+ /**
34
+ * y轴配置
35
+ */
36
+ yAxis?: Aris;
37
+ /**
38
+ * 数据
39
+ */
40
+ series: Serie[];
41
+
42
+ radar?: object;
43
+ /**
44
+ * 网格大小
45
+ */
46
+ grid?: Grid;
47
+
48
+ //批量选中
49
+ batchDelete?: boolean;
50
+ // 是否分页
51
+ paging?: boolean;
52
+ // 数据源(多图表同源)
53
+ tableData?: any;
54
+ // 列配置
55
+ tableColums?: any;
56
+ };
57
+
58
+ export type ChartConfig = {
59
+ /**
60
+ * 图表名称
61
+ */
62
+ label: string;
63
+ /**
64
+ * 默认图表类型
65
+ */
66
+ type: string;
67
+ /**
68
+ * 图标名称
69
+ */
70
+ icon: string;
71
+ /**
72
+ * 数据类型
73
+ */
74
+ dataType: DataSourceType[];
75
+
76
+ /**
77
+ * X轴数据类型
78
+ */
79
+ xAxisDataType?: string;
80
+ /**
81
+ * X轴数据绑定字段
82
+ */
83
+ xAxisDataAttr?: string;
84
+ /**
85
+ * Y轴数据类型
86
+ */
87
+ yAxisDataType?: string;
88
+ /**
89
+ * Y轴数据绑定字段
90
+ */
91
+ yAxisDataAttr?: string;
92
+ /**
93
+ * 数据源绑定字段
94
+ */
95
+ dataSourceAttr: string[];
96
+ /**
97
+ * 深色模式,rgba(16,12,42,1)
98
+ */
99
+ isDark: boolean;
100
+ /**
101
+ * 跨行
102
+ */
103
+ colSpan?: number;
104
+ /**
105
+ * 跨列
106
+ */
107
+ rowSpan?: number;
108
+ /**是否具有详情跳转 */
109
+ isDetail: false;
110
+ /**
111
+ * 数据源配置
112
+ */
113
+ dataSource?: any;
114
+ dataOrg: string[];
115
+ tableName?: string;
116
+ fkey?: string;
117
+ fTableName?: string;
118
+ fTableId?: string;
119
+ fKeyValue?: string;
120
+ };
121
+
122
+ export type ToolTip = {
123
+ /**
124
+ * 是否显示
125
+ */
126
+ show?: boolean;
127
+ /**
128
+ * 触发类型
129
+ */
130
+ trigger?: string;
131
+ /**
132
+ * 触发条件
133
+ */
134
+ triggerOn?: string;
135
+ };
136
+
137
+ export type Aris = {
138
+ axisLine?: any;
139
+ axisLabel?: any;
140
+ /**
141
+ * 是否显示
142
+ */
143
+ show?: boolean;
144
+ /**
145
+ * 坐标轴类型
146
+ */
147
+ type?: AxisType;
148
+ /**
149
+ * 坐标轴名字旋转角度
150
+ */
151
+ nameRotate?: number;
152
+ /**
153
+ * 坐标轴刻度最小值
154
+ */
155
+ min?: number;
156
+ /**
157
+ * 坐标轴刻度最大值
158
+ */
159
+ max?: number;
160
+
161
+ data?: any[];
162
+ };
163
+
164
+ export type Serie = {
165
+ id?: string;
166
+ name?: string;
167
+ type: string;
168
+ radius?: number;
169
+ stack?: string;
170
+ cursor?: string;
171
+ data: Data[];
172
+ annular?: boolean;
173
+ /**显示占比(饼状图) */
174
+ ratio?: boolean;
175
+ };
176
+
177
+ export type Data = string | number | boolean | any;
178
+
179
+ export type Grid = {
180
+ top?: number;
181
+ left?: number;
182
+ right?: number;
183
+ bottom?: number;
184
+ containLabel: boolean;
185
+ };
186
+
187
+ export type ChartPanel = {
188
+ /**
189
+ * 行数
190
+ */
191
+ rows?: number;
192
+ /**
193
+ * 列数
194
+ */
195
+ columns?: number;
196
+ /**
197
+ * 单元格宽
198
+ */
199
+ cellWidth?: number;
200
+ /**
201
+ * 单元格高
202
+ */
203
+ cellHeight?: number;
204
+ /**
205
+ * 单元格间距
206
+ */
207
+ gap?: number;
208
+
209
+ searchConfig?: SearchConfig[];
210
+ };
211
+
212
+ export type Legend = {
213
+ show: boolean;
214
+ position?: string;
215
+ data?: string[];
216
+ };
217
+
218
+ /**查询配置 */
219
+ type SearchConfig = {
220
+ /**KEY */
221
+ key: string;
222
+ /**字段列表名称 */
223
+ fieldText: string;
224
+ /**字段列表 应用-模块-表-字段 */
225
+ fieldList: Array<string | number>;
226
+ /**字段属性 */
227
+ field?: string;
228
+ /**字段描述 */
229
+ fieldDes?: string;
230
+ /**搜索组件类型 */
231
+ fieldType?: SearchFieldType;
232
+ /**搜索组件查询类型 */
233
+ filterType?: FilterType;
234
+ };
235
+ /**
236
+ * 搜索组件类型
237
+ */
238
+ enum SearchFieldType {
239
+ /**文本框 */
240
+ TEXT = 1,
241
+ /**下拉框 */
242
+ SELECT = 2,
243
+ /**日期 */
244
+ DATE = 3,
245
+ /**日期时间 */
246
+ DATETIME = 4,
247
+ /**时间 */
248
+ TIME = 5,
249
+ }
250
+
251
+ /**值判断类型 */
252
+ enum FilterType {
253
+ /**等于 */
254
+ Equal = 1,
255
+ /**区间 */
256
+ Extent = 2,
257
+ }
258
+ /**
259
+ * 坐标轴类型
260
+ */
261
+ export enum AxisType {
262
+ /**值坐标轴 */
263
+ VALUE = "value",
264
+ /**类目轴 */
265
+ CATEGORY = "category",
266
+ /**时间轴 */
267
+ TIME = "time",
268
+ /**对数轴 */
269
+ LOG = "log",
270
+ }
271
+ /**
272
+ * 数据源类型,SQL/API
273
+ */
274
+ export enum DataSourceType {
275
+ /**SQL语句 */
276
+ SQL = "0",
277
+ /**API接口 */
278
+ API = "1",
279
+ }
@@ -0,0 +1,160 @@
1
+ export const APIEnrty = {
2
+ DEFAULT: import.meta.env.VITE_DEFAULT_API, // "/api"
3
+ };
4
+
5
+ declare type labelValue = {
6
+ /**文本字段 */
7
+ label: string;
8
+ /**
9
+ * 值字段
10
+ */
11
+ value: string;
12
+ };
13
+
14
+ export enum dateTimeFormat {
15
+ /** 日期 */
16
+ date = "YYYY-MM-DD",
17
+ /** 周 */
18
+ week = "gggg第ww周",
19
+ /** 年月 */
20
+ month = "YYYY-MM",
21
+ /** 年 */
22
+ year = "YYYY",
23
+ /** 日期时间 */
24
+ datetime = "YYYY-MM-DD HH:mm:ss",
25
+ /** 多个日期 */
26
+ dates = "YYYY-MM-DD",
27
+ /** 时间 */
28
+ time = "HH:mm:ss",
29
+ }
30
+
31
+ /**
32
+ * 单位类型
33
+ * @enum {number}
34
+ */
35
+ export enum ResultUnit {
36
+ /** 天 */
37
+ DAY = 1,
38
+ /** 小时 */
39
+ HOUR = 2,
40
+ /** 分钟 */
41
+ MINUTE = 3,
42
+ /** 秒 */
43
+ SECOND = 4,
44
+ }
45
+
46
+ export const justifyOptions: Array<labelValue> = [
47
+ {
48
+ label: "start",
49
+ value: "start",
50
+ },
51
+ {
52
+ label: "end",
53
+ value: "end",
54
+ },
55
+ {
56
+ label: "center",
57
+ value: "center",
58
+ },
59
+ {
60
+ label: "space-around",
61
+ value: "space-around",
62
+ },
63
+ {
64
+ label: "space-between",
65
+ value: "space-between",
66
+ },
67
+ ];
68
+
69
+ export const dateTypeOptions: Array<labelValue> = [
70
+ {
71
+ label: "日(date)",
72
+ value: "date",
73
+ },
74
+ {
75
+ label: "周(week)",
76
+ value: "week",
77
+ },
78
+ {
79
+ label: "月(month)",
80
+ value: "month",
81
+ },
82
+ {
83
+ label: "年(year)",
84
+ value: "year",
85
+ },
86
+ {
87
+ label: "日期时间(datetime)",
88
+ value: "datetime",
89
+ },
90
+ // {
91
+ // label: '多个日期(dates)',
92
+ // value: 'dates',
93
+ // },
94
+ ];
95
+
96
+ export const dateRangeTypeOptions: Array<labelValue> = [
97
+ {
98
+ label: "日期范围(daterange)",
99
+ value: "daterange",
100
+ },
101
+ {
102
+ label: "月范围(monthrange)",
103
+ value: "monthrange",
104
+ },
105
+ {
106
+ label: "日期时间范围(datetimerange)",
107
+ value: "datetimerange",
108
+ },
109
+ ];
110
+
111
+ export const colorFormatOptions: Array<labelValue> = [
112
+ {
113
+ label: "hex",
114
+ value: "hex",
115
+ },
116
+ {
117
+ label: "rgb",
118
+ value: "rgb",
119
+ },
120
+ {
121
+ label: "rgba",
122
+ value: "rgba",
123
+ },
124
+ {
125
+ label: "hsv",
126
+ value: "hsv",
127
+ },
128
+ {
129
+ label: "hsl",
130
+ value: "hsl",
131
+ },
132
+ ];
133
+
134
+ export const AxisType: labelValue[] = [
135
+ {
136
+ label: "数值轴",
137
+ value: "value",
138
+ },
139
+ {
140
+ label: "类目轴",
141
+ value: "category",
142
+ },
143
+ {
144
+ label: "时间轴",
145
+ value: "time",
146
+ },
147
+ {
148
+ label: "对数轴",
149
+ value: "log",
150
+ },
151
+ ];
152
+
153
+ export const chartType: labelValue[] = [
154
+ { label: "折线图", value: "line" },
155
+ { label: "柱状图", value: "bar" },
156
+ { label: "饼图", value: "pie" },
157
+ { label: "散点图", value: "scatter" },
158
+ { label: "雷达图", value: "radar" },
159
+ { label: "仪表盘", value: "gauge" },
160
+ ];
@@ -0,0 +1,129 @@
1
+ ;
2
+ (function(win, lib) {
3
+ var doc = win.document;
4
+ var docEl = doc.documentElement;
5
+ var metaEl = doc.querySelector('meta[name="viewport"]');
6
+ var flexibleEl = doc.querySelector('meta[name="flexible"]');
7
+ var dpr = 0;
8
+ var scale = 0;
9
+ var tid;
10
+ var flexible = lib.flexible || (lib.flexible = {});
11
+
12
+ if (metaEl) {
13
+ console.warn('将根据已有的meta标签来设置缩放比例');
14
+ var match = metaEl.getAttribute('content').match(/initial\-scale=([\d\.]+)/);
15
+ if (match) {
16
+ scale = parseFloat(match[1]);
17
+ dpr = parseInt(1 / scale);
18
+ }
19
+ } else if (flexibleEl) {
20
+ var content = flexibleEl.getAttribute('content');
21
+ if (content) {
22
+ var initialDpr = content.match(/initial\-dpr=([\d\.]+)/);
23
+ var maximumDpr = content.match(/maximum\-dpr=([\d\.]+)/);
24
+ if (initialDpr) {
25
+ dpr = parseFloat(initialDpr[1]);
26
+ scale = parseFloat((1 / dpr).toFixed(2));
27
+ }
28
+ if (maximumDpr) {
29
+ dpr = parseFloat(maximumDpr[1]);
30
+ scale = parseFloat((1 / dpr).toFixed(2));
31
+ }
32
+ }
33
+ }
34
+
35
+ if (!dpr && !scale) {
36
+ var isAndroid = win.navigator.appVersion.match(/android/gi);
37
+ var isIPhone = win.navigator.appVersion.match(/iphone/gi);
38
+ var devicePixelRatio = win.devicePixelRatio;
39
+ if (isIPhone) {
40
+ // iOS下,对于2和3的屏,用2倍的方案,其余的用1倍方案
41
+ if (devicePixelRatio >= 3 && (!dpr || dpr >= 3)) {
42
+ dpr = 3;
43
+ } else if (devicePixelRatio >= 2 && (!dpr || dpr >= 2)) {
44
+ dpr = 2;
45
+ } else {
46
+ dpr = 1;
47
+ }
48
+ } else {
49
+ // 其他设备下,仍旧使用1倍的方案
50
+ dpr = 1;
51
+ }
52
+ scale = 1 / dpr;
53
+ }
54
+
55
+ docEl.setAttribute('data-dpr', dpr);
56
+ if (!metaEl) {
57
+ metaEl = doc.createElement('meta');
58
+ metaEl.setAttribute('name', 'viewport');
59
+ metaEl.setAttribute('content', 'initial-scale=' + scale + ', maximum-scale=' + scale + ', minimum-scale=' + scale + ', user-scalable=no');
60
+ if (docEl.firstElementChild) {
61
+ docEl.firstElementChild.appendChild(metaEl);
62
+ } else {
63
+ var wrap = doc.createElement('div');
64
+ wrap.appendChild(metaEl);
65
+ doc.write(wrap.innerHTML);
66
+ }
67
+ }
68
+
69
+ // function refreshRem(){
70
+ // var width = docEl.getBoundingClientRect().width;
71
+ // if (width / dpr > 540) {
72
+ // width = 540 * dpr;
73
+ // }
74
+ // var rem = width / 10;
75
+ // docEl.style.fontSize = rem + 'px';
76
+ // flexible.rem = win.rem = rem;
77
+ // }
78
+ function refreshRem() {
79
+ var width = docEl.getBoundingClientRect().width;
80
+ if (width / dpr < 540) {
81
+ width = 540 * dpr;
82
+ } else if (width / dpr > 1980) {
83
+ width = 1980 * dpr
84
+ }
85
+ var rem = width / 10;
86
+ docEl.style.fontSize = rem + 'px';
87
+ flexible.rem = win.rem = rem;
88
+ }
89
+
90
+ win.addEventListener('resize', function() {
91
+ clearTimeout(tid);
92
+ tid = setTimeout(refreshRem, 300);
93
+ }, false);
94
+ win.addEventListener('pageshow', function(e) {
95
+ if (e.persisted) {
96
+ clearTimeout(tid);
97
+ tid = setTimeout(refreshRem, 300);
98
+ }
99
+ }, false);
100
+
101
+ if (doc.readyState === 'complete') {
102
+ doc.body.style.fontSize = 12 * dpr + 'px';
103
+ } else {
104
+ doc.addEventListener('DOMContentLoaded', function(e) {
105
+ doc.body.style.fontSize = 12 * dpr + 'px';
106
+ }, false);
107
+ }
108
+
109
+
110
+ refreshRem();
111
+
112
+ flexible.dpr = win.dpr = dpr;
113
+ flexible.refreshRem = refreshRem;
114
+ flexible.rem2px = function(d) {
115
+ var val = parseFloat(d) * this.rem;
116
+ if (typeof d === 'string' && d.match(/rem$/)) {
117
+ val += 'px';
118
+ }
119
+ return val;
120
+ }
121
+ flexible.px2rem = function(d) {
122
+ var val = parseFloat(d) / this.rem;
123
+ if (typeof d === 'string' && d.match(/px$/)) {
124
+ val += 'rem';
125
+ }
126
+ return val;
127
+ }
128
+
129
+ })(window, window['lib'] || (window['lib'] = {}));