Răsfoiți Sursa

fix: bug fix

0xJacky 2 ani în urmă
părinte
comite
5e89860068

+ 25 - 21
frontend/src/components/StdDataDisplay/StdCurd.vue

@@ -51,6 +51,10 @@ const props = defineProps({
     exportCsv: {
         type: Boolean,
         default: false
+    },
+    modalWidth: {
+        type: Number,
+        default: 600
     }
 })
 
@@ -131,13 +135,13 @@ function edit(id: any) {
             </template>
 
             <std-table
-                ref="table"
-                v-bind="props"
-                @clickEdit="edit"
-                @selected="onSelect"
-                :key="update"
-                :get_params="get_params"
-                :exportCsv="exportCsv"
+                    ref="table"
+                    v-bind="props"
+                    @clickEdit="edit"
+                    @selected="onSelect"
+                    :key="update"
+                    :get_params="get_params"
+                    :exportCsv="exportCsv"
             >
                 <template v-slot:actions="slotProps">
                     <slot name="actions" :actions="slotProps.record"/>
@@ -146,22 +150,22 @@ function edit(id: any) {
         </a-card>
 
         <a-modal
-            class="std-curd-edit-modal"
-            :mask="false"
-            :title="data.id ? $gettext('Modify') : $gettext('Add')"
-            :visible="visible"
-            :cancel-text="$gettext('Cancel')"
-            :ok-text="$gettext('OK')"
-            @cancel="cancel"
-            @ok="ok"
-            :width="600"
-            destroyOnClose
+                class="std-curd-edit-modal"
+                :mask="false"
+                :title="data.id ? $gettext('Modify') : $gettext('Add')"
+                :visible="visible"
+                :cancel-text="$gettext('Cancel')"
+                :ok-text="$gettext('OK')"
+                @cancel="cancel"
+                @ok="ok"
+                :width="modalWidth"
+                destroyOnClose
         >
             <std-data-entry
-                ref="std_data_entry"
-                :data-list="editableColumns()"
-                v-model:data-source="data"
-                :error="error"
+                    ref="std_data_entry"
+                    :data-list="editableColumns()"
+                    v-model:data-source="data"
+                    :error="error"
             />
             <slot name="edit" :data="data"/>
         </a-modal>

+ 5 - 6
frontend/src/components/StdDataDisplay/StdPagination.vue

@@ -11,13 +11,12 @@ function changePage(num: number) {
 </script>
 
 <template>
-    <div v-if="pagination.total>pagination.per_page">
+    <div class="pagination-container" v-if="pagination.total>pagination.per_page">
         <a-pagination
                 :current="pagination.current_page"
                 :pageSize="pagination.per_page"
                 :size="size"
                 :total="pagination.total"
-                class="pagination"
                 @change="changePage"
         />
     </div>
@@ -32,12 +31,12 @@ function changePage(num: number) {
 </style>
 
 <style lang="less" scoped>
-.pagination {
+.pagination-container {
     padding: 10px 0 0 0;
-    float: right;
+    display: flex;
+    justify-content: right;
     @media (max-width: 450px) {
-        float: unset;
-        text-align: center;
+        justify-content: center;
     }
 }
 </style>

+ 34 - 14
frontend/src/components/StdDataDisplay/StdTable.vue

@@ -6,10 +6,11 @@ import {computed, onMounted, reactive, ref, watch} from 'vue'
 import {useRoute, useRouter} from 'vue-router'
 import {message} from 'ant-design-vue'
 import {downloadCsv} from '@/lib/helper'
+import dayjs from 'dayjs'
 
 const {$gettext, interpolate} = gettext
 
-const emit = defineEmits(['onSelected', 'onSelectedRecord', 'clickEdit'])
+const emit = defineEmits(['onSelected', 'onSelectedRecord', 'clickEdit', 'update:selectedRowKeys'])
 
 const props = defineProps({
     api: Object,
@@ -66,6 +67,11 @@ const props = defineProps({
     exportCsv: {
         type: Boolean,
         default: false
+    },
+    size: String,
+    selectedRowKeys: {
+        type: Array,
+        default: []
     }
 })
 
@@ -83,7 +89,14 @@ const params = reactive({
     ...props.get_params
 })
 
-const selectedRowKeys = ref([])
+const selectedRowKeysBuffer = computed({
+    get() {
+        return props?.selectedRowKeys ?? []
+    },
+    set(v) {
+        emit('update:selectedRowKeys', v)
+    }
+})
 
 const searchColumns = getSearchColumns()
 const pithyColumns = getPithyColumns()
@@ -170,8 +183,13 @@ function checked(c: any) {
 }
 
 function onSelectChange(_selectedRowKeys: any) {
-    selectedRowKeys.value = _selectedRowKeys
-    emit('onSelected', selectedRowKeys.value)
+    const n: any = [..._selectedRowKeys]
+    const t = [...selectedRowKeysBuffer.value].concat(n)
+
+    const set = new Set(t)
+    selectedRowKeysBuffer.value = Array.from(set)
+
+    emit('onSelected', selectedRowKeysBuffer.value)
 }
 
 function onSelect(record: any) {
@@ -201,7 +219,7 @@ watch(params, () => {
 const rowSelection = computed(() => {
     if (props.selectionType) {
         return {
-            selectedRowKeys: selectedRowKeys, onChange: onSelectChange,
+            selectedRowKeys: selectedRowKeysBuffer, onChange: onSelectChange,
             onSelect: onSelect, type: props.selectionType
         }
     } else {
@@ -263,7 +281,9 @@ async function export_csv() {
                 dataSource = dataSource.concat(...response[props.data_key])
             }
         }).catch((e: any) => {
-            message.error(e.message ?? '系统错误')
+            message.error(e.message ?? $gettext('Server error'))
+            hasMore = false
+            return
         })
         page += 1
     }
@@ -271,17 +291,16 @@ async function export_csv() {
     dataSource.forEach((row: Object) => {
         let obj: any = {}
         headerKeys.forEach(key => {
-            console.log(row, key)
             let data = fn(row, key)
             const c = showColumnsMap[key]
-            console.log(c)
             data = c?.customRender?.({text: data}) ?? data
             obj[c.dataIndex] = data
         })
         data.push(obj)
     })
-    console.log(header, data)
-    downloadCsv(header, data, '测试.csv')
+
+    downloadCsv(header, data,
+            `${$gettext('Export')}-${dayjs().format('YYYYMMDDHHmmss')}.csv`)
 }
 </script>
 
@@ -295,11 +314,11 @@ async function export_csv() {
         >
             <template #action>
                 <a-space class="reset-btn">
-                    <a-button @click="export_csv" type="primary" ghost>
-                        <translate>Export</translate>
+                    <a-button v-if="exportCsv" @click="export_csv" type="primary" ghost>
+                        {{ $gettext('Export') }}
                     </a-button>
                     <a-button @click="reset_search">
-                        <translate>Reset</translate>
+                        {{ $gettext('Reset') }}
                     </a-button>
                 </a-space>
             </template>
@@ -313,6 +332,7 @@ async function export_csv() {
                 :rowSelection="rowSelection"
                 @change="stdChange"
                 :scroll="{ x: scrollX }"
+                :size="size"
         >
             <template
                     v-slot:bodyCell="{text, record, index, column}"
@@ -335,7 +355,7 @@ async function export_csv() {
                 </template>
             </template>
         </a-table>
-        <std-pagination :pagination="pagination" @changePage="get_list"/>
+        <std-pagination :size="size" :pagination="pagination" @changePage="get_list"/>
     </div>
 </template>
 

+ 5 - 3
frontend/src/components/StdDataEntry/compontents/StdSelector.vue

@@ -1,7 +1,9 @@
 <script setup lang="ts">
 import {onMounted, reactive, ref, watch} from 'vue'
 import StdTable from '@/components/StdDataDisplay/StdTable.vue'
+import gettext from '@/gettext'
 
+const {$gettext} = gettext
 const props = defineProps(['selectedKey', 'value', 'recordValueIndex',
     'selectionType', 'api', 'columns', 'data_key',
     'disable_search', 'get_params', 'description'])
@@ -70,9 +72,9 @@ watch(props, () => {
             <a-modal
                     :mask="false"
                     :visible="visible"
-                    cancel-text="取消"
-                    ok-text="选择"
-                    title="选择器"
+                    :cancel-text="$gettext('Cancel')"
+                    :ok-text="$gettext('Ok')"
+                    :title="$gettext('Selector')"
                     @cancel="visible=false"
                     @ok="ok()"
                     :width="800"

+ 1 - 1
frontend/src/version.json

@@ -1 +1 @@
-{"version":"1.6.0","build_id":47,"total_build":117}
+{"version":"1.6.0","build_id":49,"total_build":119}

+ 1 - 1
frontend/version.json

@@ -1 +1 @@
-{"version":"1.6.0","build_id":47,"total_build":117}
+{"version":"1.6.0","build_id":49,"total_build":119}