ol-base-components 3.3.3 → 3.3.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ol-base-components",
3
- "version": "3.3.3",
3
+ "version": "3.3.5",
4
4
  "private": false,
5
5
  "main": "src/package/index.js",
6
6
  "bin": {
@@ -7,6 +7,7 @@
7
7
  :data="menuTreeData"
8
8
  :props="treeProps"
9
9
  node-key="id"
10
+ :current-node-key="currentMenuId"
10
11
  default-expand-all
11
12
  :expand-on-click-node="false"
12
13
  highlight-current
@@ -17,29 +18,16 @@
17
18
  <div class="right-panel">
18
19
  <div class="panel-header">
19
20
  <span class="panel-title">{{ currentMenuName }} - 打印模板</span>
20
- <el-button
21
- type="primary"
22
- size="small"
23
- icon="el-icon-plus"
24
- @click="handleAdd"
25
- >
21
+ <el-button type="primary" size="small" icon="el-icon-plus" @click="handleAdd">
26
22
  新增模板
27
23
  </el-button>
28
24
  </div>
29
25
  <div class="template-list">
30
- <div
31
- v-if="templateList.length === 0"
32
- class="empty-card"
33
- @click="handleAdd"
34
- >
26
+ <div v-if="templateList.length === 0" class="empty-card" @click="handleAdd">
35
27
  <i class="el-icon-plus add-icon"></i>
36
28
  <span class="add-text">点击添加模板</span>
37
29
  </div>
38
- <div
39
- v-for="template in templateList"
40
- :key="template.id"
41
- class="template-card"
42
- >
30
+ <div v-for="template in templateList" :key="template.id" class="template-card">
43
31
  <div class="card-header">
44
32
  <i class="el-icon-document card-icon"></i>
45
33
  <span class="card-title">{{ template.templeteName }}</span>
@@ -51,12 +39,7 @@
51
39
  </div>
52
40
  </div>
53
41
  <div class="card-footer">
54
- <el-button
55
- type="text"
56
- size="small"
57
- icon="el-icon-edit"
58
- @click="handleEdit(template)"
59
- >
42
+ <el-button type="text" size="small" icon="el-icon-edit" @click="handleEdit(template)">
60
43
  编辑
61
44
  </el-button>
62
45
  <el-button
@@ -81,10 +64,7 @@
81
64
  >
82
65
  <el-form :model="form" :rules="rules" ref="formRef" label-width="100px">
83
66
  <el-form-item label="模板名称" prop="templeteName">
84
- <el-input
85
- v-model="form.templeteName"
86
- placeholder="请输入模板名称"
87
- ></el-input>
67
+ <el-input v-model="form.templeteName" placeholder="请输入模板名称"></el-input>
88
68
  </el-form-item>
89
69
  <el-form-item label="备注">
90
70
  <el-input
@@ -95,12 +75,8 @@
95
75
  ></el-input>
96
76
  </el-form-item>
97
77
  <el-form-item label="创建模板">
98
- <span style="margin-right: 10px">{{
99
- form.templeteJson ? "已创建" : "未创建"
100
- }}</span>
101
- <el-button type="primary" @click="handleCreateTemplate"
102
- >创建模板</el-button
103
- >
78
+ <span style="margin-right: 10px">{{ form.templeteJson ? "已创建" : "未创建" }}</span>
79
+ <el-button type="primary" @click="handleCreateTemplate">创建模板</el-button>
104
80
  </el-form-item>
105
81
  </el-form>
106
82
  <span slot="footer" class="dialog-footer">
@@ -113,7 +89,6 @@
113
89
  </template>
114
90
 
115
91
  <script>
116
-
117
92
  export default {
118
93
  name: "print-model",
119
94
  data() {
@@ -136,24 +111,39 @@ export default {
136
111
  templeteJson: "",
137
112
  },
138
113
  rules: {
139
- templeteName: [
140
- { required: true, message: "请输入模板名称", trigger: "blur" },
141
- ],
114
+ templeteName: [{ required: true, message: "请输入模板名称", trigger: "blur" }],
142
115
  },
143
116
  };
144
117
  },
145
118
  mounted() {
146
119
  this.initMenuTree();
147
- this.initTemplateList();
148
120
  },
149
121
  methods: {
150
122
  initMenuTree() {
151
123
  const wms = JSON.parse(localStorage.getItem("wms") || "{}");
152
124
  const menus = wms.SET_MENUS || [];
153
125
  this.menuTreeData = this.buildTreeData(menus);
126
+ const firstNode = this.findFirstMenuNode(this.menuTreeData);
127
+ if (firstNode) {
128
+ this.currentMenuId = firstNode.id;
129
+ this.currentMenuName = firstNode.title;
130
+ this.currentItem = firstNode;
131
+ this.loadTemplates(firstNode.id);
132
+ }
133
+ },
134
+ findFirstMenuNode(menus) {
135
+ if (!menus || menus.length === 0) return null;
136
+ for (const menu of menus) {
137
+ if (menu.child && menu.child.length > 0) {
138
+ const found = this.findFirstMenuNode(menu.child);
139
+ if (found) return found;
140
+ }
141
+ return menu;
142
+ }
143
+ return null;
154
144
  },
155
145
  buildTreeData(menus) {
156
- return menus.filter((menu) => {
146
+ return menus.filter(menu => {
157
147
  if (menu.child && menu.child.length > 0) {
158
148
  menu.child = this.buildTreeData(menu.child);
159
149
  }
@@ -176,21 +166,7 @@ export default {
176
166
  MaxResultCount: 1000,
177
167
  },
178
168
  });
179
- if (res.code != 200) return;
180
- this.templateList = res.result?.items || [];
181
- } catch (error) {
182
- console.error("加载模板列表失败:", error);
183
- }
184
- },
185
- async initTemplateList() {
186
- try {
187
- const res = await this.get({
188
- url: "/api/app/print-templete/page-list",
189
- data: {
190
- page: 1,
191
- MaxResultCount: 1000,
192
- },
193
- });
169
+ if (res.code !== 200) return;
194
170
  this.templateList = res.result?.items || [];
195
171
  } catch (error) {
196
172
  console.error("加载模板列表失败:", error);
@@ -239,7 +215,7 @@ export default {
239
215
  .catch(() => {});
240
216
  },
241
217
  async handleSubmit() {
242
- this.$refs.formRef.validate(async (valid) => {
218
+ this.$refs.formRef.validate(async valid => {
243
219
  if (valid) {
244
220
  try {
245
221
  if (this.form.id) {
@@ -282,7 +258,7 @@ export default {
282
258
  }
283
259
  this.$hiprint({
284
260
  defaultTemplate: templateData,
285
- onSubmit: (res) => {
261
+ onSubmit: res => {
286
262
  this.form.templeteJson = JSON.stringify(res);
287
263
  console.log("保存的结果", this.form);
288
264
  this.$message.success("模板创建成功!");
@@ -1,22 +1,28 @@
1
1
  <template>
2
- <el-dropdown @command="handleCommand" trigger="click">
3
- <i class="el-icon-printer" />
4
- <el-dropdown-menu slot="dropdown">
5
- <el-dropdown-item
6
- v-for="(item, index) in templateList"
7
- :key="index"
8
- :command="item.id"
9
- :disabled="item.disabled"
10
- >
11
- {{ item.templeteName || "-" }}
12
- </el-dropdown-item>
13
- </el-dropdown-menu>
14
- </el-dropdown>
2
+ <el-dropdown @command="handleCommand" trigger="click">
3
+ <i class="el-icon-printer" />
4
+ <el-dropdown-menu slot="dropdown">
5
+ <el-dropdown-item
6
+ v-for="(item, index) in templateList"
7
+ :key="index"
8
+ :command="item.id"
9
+ :disabled="item.disabled"
10
+ >
11
+ {{ item.templeteName || "-" }}
12
+ </el-dropdown-item>
13
+ </el-dropdown-menu>
14
+ </el-dropdown>
15
15
  </template>
16
16
 
17
17
  <script>
18
18
  export default {
19
19
  name: "dropdown-print",
20
+ props: {
21
+ menuId: {
22
+ type: String,
23
+ default: "",
24
+ },
25
+ },
20
26
  data() {
21
27
  return {
22
28
  templateList: [{ id: 1, templeteName: "暂无数据", disabled: true }],
@@ -56,9 +62,11 @@ export default {
56
62
  MaxResultCount: 1000,
57
63
  },
58
64
  });
59
- this.printTemplateList = res.result?.items || [
60
- { id: 1, templeteName: "暂无数据", disabled: true },
61
- ];
65
+ if (Array.isArray(res.result?.items) && res.result.items.length > 0) {
66
+ this.templateList = res.result.items;
67
+ } else {
68
+ this.templateList = [{ id: 1, templeteName: "暂无数据", disabled: true }];
69
+ }
62
70
  } catch (error) {
63
71
  console.error("加载模板列表失败:", error);
64
72
  }
@@ -66,6 +74,7 @@ export default {
66
74
  handleCommand(command) {
67
75
  if (!Array.isArray(this.templateList)) return;
68
76
  const tempItem = this.templateList.find(item => item.id === command);
77
+ if (!tempItem) return this.$message.error("未找到打印模板");
69
78
  this.$hiprint.print({
70
79
  printData: this.tableData?.printData || {},
71
80
  defaultTemplate: tempItem.templeteJson ? JSON.parse(tempItem.templeteJson) : {},
@@ -65,7 +65,7 @@
65
65
  >
66
66
  <div class="avatar-wrapper">
67
67
  <div class="layui-table-tool-self">
68
- <print-template-selector />
68
+ <print-template-selector :menuId="menuId" />
69
69
  </div>
70
70
  </div>
71
71
  </div>