Browse Source

feat: basic in with autoCompleteByISBN

ryanemax 7 months ago
parent
commit
9acc3fada2

+ 7 - 4
projects/textbook/src/modules/nav-author/components/basic-in/basic-in.component.html

@@ -27,10 +27,10 @@
     </nz-form-item>
     <nz-form-item style="margin-bottom: 16px">
       <nz-form-label [nzSm]="8" [nzNoColon]="true" [nzXs]="8" nzRequired
-        >国际标准书号</nz-form-label
+        >国际标准书号(ISBN)</nz-form-label
       >
       <nz-form-control nzErrorTip="请输入国际标准书号" [nzSm]="12" [nzXs]="12">
-        <nz-input-group>
+        <nz-input-group [nzAddOnAfter]="autoButton">
           <input
             type="text"
             nz-input
@@ -38,6 +38,9 @@
             placeholder="请输入国际标准书号"
           />
         </nz-input-group>
+        <ng-template #autoButton>
+          <button (click)="autoCompleteByISBN()" nz-button nzType="primary">自动补全</button>
+        </ng-template>
       </nz-form-control>
     </nz-form-item>
     <nz-form-item style="margin-bottom: 16px">
@@ -140,7 +143,7 @@
             @for(major of selectList; track major.code;let index = $index){
             <nz-option
               nzCustomContent
-              [nzValue]="major.code"
+              [nzValue]="major.name"
               [nzLabel]="major.name"
               >{{ major.name }}</nz-option
             >
@@ -272,7 +275,7 @@
             @for(item of carrierOptions; track item.code;let index = $index){
             <nz-option
               nzCustomContent
-              [nzValue]="item.code"
+              [nzValue]="item.name"
               [nzLabel]="item.name"
               >{{ item.name }}</nz-option
             >

+ 35 - 3
projects/textbook/src/modules/nav-author/components/basic-in/basic-in.component.ts

@@ -18,6 +18,7 @@ import {
   Validators,
 } from '@angular/forms';
 import { CompUploadComponent } from '../../../../app/comp-upload/comp-upload.component';
+import { NzInputModule } from 'ng-zorro-antd/input';
 @Component({
   selector: 'app-basic',
   imports: [
@@ -26,6 +27,7 @@ import { CompUploadComponent } from '../../../../app/comp-upload/comp-upload.com
     NzSelectModule,
     NzRadioModule,
     NzUploadModule,
+    NzInputModule,
     NzTagModule,
     CompUploadComponent
   ],
@@ -39,6 +41,32 @@ export class BasicInComponent implements OnInit {
   @Output() state: EventEmitter<any> = new EventEmitter<any>();
   @Output() save: EventEmitter<any> = new EventEmitter<any>();
 
+  /**
+   * 书号自动补全函数
+   * @param isbn 书号
+   */
+  async autoCompleteByISBN(){
+    let isbn = this.validateForm.value?.ISBN;
+    let result = await Parse.Cloud.run("tbookISBN",{
+      isbn:isbn
+    })
+    if(!result?.isbn){
+      this.msg.warning('未找到该书号的图书信息,请手动填写')
+    }
+
+    // 其他字段,需补充接口与数据库对应关系
+    this.validateForm.get("title")?.setValue(result?.book_name)
+    this.validateForm.get("author")?.setValue(result?.author_name)
+    this.validateForm.get("authors")?.setValue(result?.author)
+    this.validateForm.get("majorPoniter")?.setValue(result?.major)
+    this.validateForm.get("lang")?.setValue(languages.options?.[result?.languages]?.name)
+    this.validateForm.get("editionUnit")?.setValue(result?.publisher)
+    this.validateForm.get("editionDate")?.setValue(new Date(result?.publish_time))
+    this.validateForm.get("carrierShape")?.setValue(result?.publication_class)
+    
+    console.log(result)
+  }
+
   validateForm: FormGroup<{
     title: FormControl<string>; //申报教材名称
     ISBN: FormControl<string>; //国际标准书号
@@ -111,21 +139,25 @@ export class BasicInComponent implements OnInit {
       name: '生物工程学',
       code: 'M003',
     },
+    {
+      name: '工商管理',
+      code: 'M004',
+    },
   ];
   //语言选择
   selectLang: Array<any> = languages.options;
   //载体形式
   carrierOptions: Array<any> = [
     {
-      name: '载体一',
+      name: '纸质教材',
       code: 'Z001',
     },
     {
-      name: '载体二',
+      name: '电子教材',
       code: 'Z002',
     },
     {
-      name: '载体三',
+      name: '其他教材',
       code: 'Z003',
     },
   ];

+ 5 - 2
server/cloud/tbook/func-tbook-isbn.js

@@ -3,7 +3,7 @@
 
 /**
  * Cloud Code test
- curl -X POST -H "Content-Type: application/json" -H 'X-Parse-Application-Id: edu-textbook' -d '{ "isbn": "9787111312383" }' http://127.0.0.1:61337/parse/functions/tbookISBN
+ curl -X POST -H "Content-Type: application/json" -H 'X-Parse-Application-Id: edu-textbook' -d '{ "isbn": "9787302609865" }' http://127.0.0.1:61337/parse/functions/tbookISBN
  */
 
 
@@ -24,7 +24,10 @@ export function defineTbookISBN(){
                 let text = await response?.text()
                 try{
                     let result = JSON.parse(text)
-                    return result?.data?.[0];
+                    // console.log(result)
+                    if(result?.data?.[0]){
+                        return result?.data?.[0];
+                    }
                 }catch(err){}
             }catch(err){
                 console.error(err)