vue3-django 0.1.10 → 0.1.13

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,37 @@
1
+ # 自动发布 npm
2
+
3
+ 推送 `v*` 标签会触发 `.github/workflows/publish.yml`,依次校验版本、安装依赖、运行测试、构建、预览打包内容并发布到 npm 的 `latest` 标签。任一步失败都会停止发布。仅支持正式版本,例如 `v0.1.12`;预发布版本会被拒绝。
4
+
5
+ ## 一次性配置
6
+
7
+ 将 workflow 提交并推送到 `szuprefix/vue3-django`,确保仓库启用了 GitHub Actions。
8
+
9
+ 以包维护者身份打开 npm 的 `vue3-django` 包设置,添加 GitHub Actions Trusted Publisher:
10
+
11
+ | 字段 | 值 |
12
+ | -------------------- | ---------------------- |
13
+ | Organization or user | `szuprefix` |
14
+ | Repository | `vue3-django` |
15
+ | Workflow filename | `publish.yml` |
16
+ | Environment name | 留空 |
17
+ | Allowed actions | 允许直接 `npm publish` |
18
+
19
+ 使用 GitHub 托管 runner 和 Node.js 24,通过 OIDC 获取发布身份,无需添加 `NPM_TOKEN`。npm CLI 必须至少为 11.5.1。包必须已经存在;如果尚未创建,先由维护者手动完成首次发布,再配置 Trusted Publisher。
20
+
21
+ 参考:[npm Trusted Publishing 文档](https://docs.npmjs.com/trusted-publishers/)。
22
+
23
+ ## 发布新版
24
+
25
+ 先将本次发布的代码提交到 `main`,确认工作区干净,再执行:
26
+
27
+ ```sh
28
+ git switch main
29
+ git pull --ff-only
30
+ npm version patch
31
+ git push origin main
32
+ git push origin "v$(node -p 'require("./package.json").version')"
33
+ ```
34
+
35
+ `npm version patch` 同步更新 `package.json` 和 `package-lock.json`,创建版本提交与 `v版本号` 标签。也可以使用 `npm version minor` 或 `npm version major`。最后一条命令只推送本次版本标签。
36
+
37
+ 在 GitHub Actions 的 **Publish to npm** 查看结果。npm 不允许覆盖已发布版本;已经成功发布后,需递增版本号再次发布。失败且该版本尚未发布时,可在 Actions 中重新运行失败的任务。
package/package.json CHANGED
@@ -1,7 +1,11 @@
1
1
  {
2
2
  "name": "vue3-django",
3
- "version": "0.1.10",
3
+ "version": "0.1.13",
4
4
  "description": "DRF metadata-driven Vue 3 framework",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/szuprefix/vue3-django.git"
8
+ },
5
9
  "keywords": [
6
10
  "vue3",
7
11
  "element-plus",
@@ -1,6 +1,6 @@
1
1
  <script setup>
2
2
  import { computed, ref, watch } from 'vue'
3
- import { ElSelect, ElOption } from 'element-plus'
3
+ import { ElSelect, ElOption, ElMessage } from 'element-plus'
4
4
  import Actions from './Actions.vue'
5
5
 
6
6
  const props = defineProps({
@@ -11,6 +11,12 @@ const props = defineProps({
11
11
  execute: Function,
12
12
  })
13
13
  const emit = defineEmits(['done', 'error'])
14
+ function onDone(result, action) {
15
+ const rows = result?.rows ?? result?.data?.rows
16
+ const countInfo = rows >= 0 ? `${rows}条记录` : ''
17
+ ElMessage.success(`操作成功${countInfo}.`)
18
+ emit('done', result, action)
19
+ }
14
20
  const scope = ref('select')
15
21
  const scopes = computed(() => {
16
22
  const selected = props.context.selection?.length ?? 0
@@ -73,7 +79,7 @@ watch(
73
79
  :permission-function="permissionFunction"
74
80
  :execute="execute"
75
81
  compact
76
- @done="(result, action) => emit('done', result, action)"
82
+ @done="onDone"
77
83
  @error="emit('error', $event)"
78
84
  />
79
85
  </div>
@@ -60,9 +60,11 @@ async function load() {
60
60
  if (current !== generation) return
61
61
  const view = (isEdit.value ? views.update : views.create) ?? views.form ?? {}
62
62
  fields.value = normalizeItems(props.items ?? view.items ?? 'all', metadata).filter(
63
- (field) => !field.read_only || field.widget === 'readonly',
63
+ (field) =>
64
+ !Object.hasOwn(props.defaults, field.name) &&
65
+ (!field.read_only || field.widget === 'readonly'),
64
66
  )
65
- changed({ ...emptyData(metadata, props.defaults), ...object, ...props.modelValue })
67
+ changed({ ...emptyData(metadata), ...object, ...props.modelValue, ...props.defaults })
66
68
  updateTabTitle(object)
67
69
  emit('loaded', model)
68
70
  } catch (error) {
@@ -75,7 +77,9 @@ async function load() {
75
77
  }
76
78
  }
77
79
  function save({ formValue }) {
78
- return registry.get(props.appModel).save(formValue, props.id, props.defaults)
80
+ return registry
81
+ .get(props.appModel)
82
+ .save({ ...formValue, ...props.defaults }, props.id, props.defaults)
79
83
  }
80
84
  function posted(result) {
81
85
  changed({ ...data.value, ...result })
@@ -1,8 +1,7 @@
1
1
  <script setup>
2
- import { ref, shallowRef, watch, markRaw, nextTick } from 'vue'
2
+ import { computed, ref, shallowRef, watch, markRaw, nextTick } from 'vue'
3
3
  import { ElTabs, ElTabPane, ElAlert, ElButton, ElDialog, ElDrawer } from 'element-plus'
4
4
  import ModelTable from './Table.vue'
5
- import ModelSelect from './Select.vue'
6
5
  import ModelForm from './Form.vue'
7
6
  import { useDjango } from '../../composables/context.js'
8
7
  import { resolveRelation, relationIds } from '../../core/relations.js'
@@ -20,6 +19,8 @@ const adding = shallowRef(),
20
19
  creating = shallowRef(),
21
20
  selection = ref([]),
22
21
  saving = ref(false)
22
+ // Keep query identity stable when selection/loading events re-render the dialog.
23
+ const selectionQueries = computed(() => adding.value?.selectionQueries ?? {})
23
24
  let generation = 0
24
25
  async function load() {
25
26
  const current = ++generation
@@ -97,11 +98,37 @@ function beginAdd(item) {
97
98
  selection.value = []
98
99
  adding.value = item
99
100
  }
100
- function addSelected() {
101
+ async function addSelected({ table, scope }) {
101
102
  const item = adding.value
102
- return updateMembership(item, [
103
- ...new Set([...relationIds(props.parent.data[item.multipleField.name]), ...selection.value]),
104
- ])
103
+ saving.value = true
104
+ error.value = ''
105
+ try {
106
+ const rows = await table.resolveSelection(scope)
107
+ const idField = item.model.config.idField || 'id'
108
+ const ids = rows.map((row) => row[idField])
109
+ saving.value = false
110
+ return await updateMembership(item, [
111
+ ...new Set([...relationIds(props.parent.data[item.multipleField.name]), ...ids]),
112
+ ])
113
+ } catch (cause) {
114
+ error.value = cause.message
115
+ emit('error', cause)
116
+ } finally {
117
+ saving.value = false
118
+ }
119
+ }
120
+ const selectionActions = computed(() => [
121
+ {
122
+ name: 'add-relation',
123
+ label: '添加关联',
124
+ type: 'primary',
125
+ disabled: saving.value,
126
+ do: addSelected,
127
+ },
128
+ ])
129
+ function selectRows(rows) {
130
+ const idField = adding.value?.model.config.idField || 'id'
131
+ selection.value = rows.map((row) => row[idField])
105
132
  }
106
133
  function remove(item, row) {
107
134
  const id = row[item.model.config.idField || 'id']
@@ -182,11 +209,15 @@ defineExpose({ refresh: load, relations })
182
209
  :row-actions="
183
210
  item.multipleField
184
211
  ? [
185
- {
186
- name: 'remove-relation',
187
- label: '移出关联',
188
- do: ({ row }) => remove(item, row),
189
- },
212
+ 'edit',
213
+ [
214
+ {
215
+ name: 'remove-relation',
216
+ label: '移除',
217
+ icon: 'trash',
218
+ do: ({ row }) => remove(item, row),
219
+ },
220
+ ],
190
221
  ]
191
222
  : undefined
192
223
  "
@@ -198,22 +229,46 @@ defineExpose({ refresh: load, relations })
198
229
  </ElTabs>
199
230
  <ElDialog
200
231
  :model-value="Boolean(adding)"
201
- title="添加已有记录"
232
+ :title="`添加已有${adding?.label || '记录'}`"
233
+ width="90%"
234
+ destroy-on-close
235
+ :close-on-click-modal="!saving"
236
+ :close-on-press-escape="!saving"
237
+ :show-close="!saving"
202
238
  @close="adding = undefined"
203
239
  >
204
- <ModelSelect
240
+ <p>
241
+ 勾选记录后,可选择“选中”“全部”或“其余”。全部和其余以当前搜索条件为范围,已有关联会自动合并。
242
+ </p>
243
+ <ElAlert
244
+ v-if="error"
245
+ :title="error"
246
+ type="error"
247
+ :closable="false"
248
+ />
249
+ <ModelTable
205
250
  v-if="adding"
206
- v-model="selection"
251
+ :key="adding.key"
207
252
  :app-model="adding.name"
208
- :field="{ multiple: true, label: adding.label }"
253
+ :items="adding.items"
254
+ :search-items="adding.searchItems"
255
+ :base-queries="selectionQueries"
256
+ :top-actions="['refresh']"
257
+ :row-actions="[]"
258
+ :batch-actions="selectionActions"
259
+ dbl-click-action=""
260
+ selection
261
+ @selection-change="selectRows"
262
+ @loaded="selection = []"
263
+ @error="error = $event.message"
209
264
  />
210
265
  <template #footer>
266
+ <span>已选 {{ selection.length }} 条(当前页)</span>
211
267
  <ElButton
212
- :loading="saving"
213
- :disabled="!selection.length"
214
- @click="addSelected"
268
+ :disabled="saving"
269
+ @click="adding = undefined"
215
270
  >
216
- 添加关联
271
+ 取消
217
272
  </ElButton>
218
273
  </template>
219
274
  </ElDialog>
@@ -5,6 +5,7 @@ import { useDrawer } from '../../composables/drawer.js'
5
5
  import { ElAlert } from 'element-plus'
6
6
  import { useDjango } from '../../composables/context.js'
7
7
  import { normalizeItems } from '../../core/metadata.js'
8
+ import { resolveSelection } from '../../core/selection.js'
8
9
  import Actions from '../layout/Actions.vue'
9
10
  import BatchActions from '../layout/BatchActions.vue'
10
11
  import ModelSearch from './Search.vue'
@@ -219,7 +220,7 @@ async function executeBatchAction(action, context) {
219
220
  : {}),
220
221
  scope: context.scope,
221
222
  },
222
- { params: { ...views.value.list?.baseQueries, ...props.baseQueries, ...queries.value } },
223
+ { params: { ...queries.value, ...views.value.list?.baseQueries, ...props.baseQueries } },
223
224
  )
224
225
  await load()
225
226
  return result.data
@@ -302,6 +303,14 @@ function selectionChanged(rows) {
302
303
  const tableApi = {
303
304
  refresh: load,
304
305
  load,
306
+ resolveSelection: (scope = 'select') =>
307
+ resolveSelection({
308
+ scope,
309
+ selection: selectedRows.value,
310
+ model: registry.get(props.appModel),
311
+ queries: { ...queries.value, ...views.value.list?.baseQueries, ...props.baseQueries },
312
+ pageSize: props.maxPageSize,
313
+ }),
305
314
  get parent() {
306
315
  return props.parent
307
316
  },
@@ -322,7 +331,7 @@ watch(
322
331
  remote.value?.search({})
323
332
  },
324
333
  )
325
- defineExpose({ refresh: load, load })
334
+ defineExpose({ refresh: load, load, resolveSelection: tableApi.resolveSelection })
326
335
  </script>
327
336
  <template>
328
337
  <section :aria-busy="remote?.loading">
@@ -0,0 +1,18 @@
1
+ import { fetchExcelRows } from './excel.js'
2
+
3
+ // Resolve all/exclude against the current filtered result, never just the visible page.
4
+ export async function resolveSelection({
5
+ scope = 'select',
6
+ selection,
7
+ model,
8
+ queries,
9
+ pageSize = 1000,
10
+ }) {
11
+ const selected = [...selection]
12
+ if (scope === 'select') return selected
13
+ if (!['all', 'exclude'].includes(scope)) throw new Error(`未知选择范围:${scope}`)
14
+ const idField = model.config.idField ?? 'id'
15
+ const excluded = new Set(selected.map((row) => String(row[idField])))
16
+ const rows = await fetchExcelRows((params) => model.query(params), queries, { pageSize })
17
+ return scope === 'exclude' ? rows.filter((row) => !excluded.has(String(row[idField]))) : rows
18
+ }
@@ -1,6 +1,6 @@
1
1
  // Small compatibility helpers used by migrated media config files.
2
2
  export function duration(value) {
3
- if (value == null || value === '' || !Number.isFinite(Number(value))) return ''
3
+ if (value == null || value === '' || !Number.isFinite(Number(value))) return '—'
4
4
  const seconds = Math.max(0, Number(value))
5
5
  return `${Math.floor(seconds / 60)}'${Math.floor(seconds % 60)}''`
6
6
  }