| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859 |
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
- <title>秒过加资料信息维护</title>
- <script src="https://kylx365-1253256735.file.myqcloud.com/js/jquery-1.10.2.min.js"></script>
- <script src="https://kylx365-1253256735.file.myqcloud.com/js/vue.min.js"></script>
- <style>
- .main00 {
- width: 100%;
- height: 100vh;
- min-height: 600px;
- background: white;
- display: flex;
- flex-direction: column;
- overflow: hidden;
- }
- .ListTop {
- width: 100%;
- height: 60px;
- background: white;
- border-bottom: 1px solid #EEEEEE;
- justify-content: flex-start;
- flex-shrink: 0;
- }
- .ListTop3 {
- margin-left: 40px;
- height: 50px;
- align-items: center;
- }
- .title {
- font-size: 24px;
- color: #333333;
- font-weight: bold;
- }
- .main0 {
- width: 100%;
- background: white;
- flex: 1;
- min-height: 0;
- overflow: hidden;
- display: flex;
- position: relative;
- align-items: flex-start;
- }
- .search-panel {
- width: 400px;
- border-right: 1px solid #EEEEEE;
- background: #F9F9F9;
- display: flex;
- flex-direction: column;
- height: 100%;
- position: relative;
- flex-shrink: 0;
- }
- .search-box {
- padding: 15px;
- border-bottom: 1px solid #EEEEEE;
- background: white;
- width: 100%;
- justify-content: center;
- }
- .search-input {
- width: 200px;
- height: 32px;
- padding: 0 32px 0 12px;
- border: 1px solid #DDDDDD;
- border-radius: 4px;
- font-size: 14px;
- color: #333333;
- }
- .search-input:focus {
- border-color: #4A90E2;
- outline: none;
- }
- .btn33 {
- width: 32px;
- height: 32px;
- margin-left: 8px;
- border-radius: 4px;
- background: #F5F5F5;
- cursor: pointer;
- justify-content: center;
- align-items: center;
- }
- .btn33:hover {
- background: #EEEEEE;
- }
- .json-editor {
- width: calc(100% - 400px);
- padding: 20px;
- overflow-y: auto;
- height: calc(100% - 60px);
- }
- .json-node {
- margin: 5px 0;
- padding: 5px;
- font-family: monospace;
- }
- .json-key {
- color: #881391;
- margin-right: 5px;
- }
- .json-string {
- color: #268BD2;
- }
- .json-number {
- color: #859900;
- }
- .json-boolean {
- color: #CB4B16;
- }
- .json-null {
- color: #93A1A1;
- }
- .editable {
- cursor: pointer;
- }
- .editable:hover {
- background-color: #f0f0f0;
- }
- .json-editor-input {
- width: 100%;
- padding: 4px;
- font-family: monospace;
- border: 1px solid #4A90E2;
- border-radius: 4px;
- }
- .btn-group {
- position: fixed;
- bottom: 20px;
- right: 20px;
- text-align: right;
- padding: 20px;
- background: white;
- box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
- border-radius: 4px;
- }
- .btn {
- min-width: 30px;
- height: 36px;
- padding: 0 16px;
- margin-left: 12px;
- border: none;
- border-radius: 4px;
- cursor: pointer;
- font-size: 14px;
- transition: all 0.3s;
- }
- .btn-primary {
- background: #4A90E2;
- color: white;
- }
- .btn-primary:hover {
- background: #357ABD;
- }
- .btn-default {
- background: white;
- border: 1px solid #DDDDDD;
- color: #666666;
- }
- .btn-default:hover {
- background: #F5F5F5;
- border-color: #CCCCCC;
- }
- .toast {
- position: fixed;
- top: 20px;
- left: 50%;
- transform: translateX(-50%);
- padding: 12px 24px;
- background: rgba(0, 0, 0, 0.7);
- color: white;
- border-radius: 4px;
- z-index: 9999;
- opacity: 0;
- transition: opacity 0.3s;
- }
- .toast.show {
- opacity: 1;
- }
- .toast.success {
- background: #4CAF50;
- }
- .toast.error {
- background: #F44336;
- }
- .toast.info {
- background: #2196F3;
- }
- /* Loading样式 */
- .loading-overlay {
- position: absolute;
- top: 0;
- left: 0;
- width: 100%;
- height: 100%;
- background-color: rgba(255, 255, 255, 0.7);
- display: flex;
- justify-content: center;
- align-items: center;
- z-index: 100;
- }
- .loading-spinner {
- width: 50px;
- height: 50px;
- border: 5px solid #f3f3f3;
- border-top: 5px solid #4A90E2;
- border-radius: 50%;
- animation: spin 1s linear infinite;
- }
- @keyframes spin {
- 0% { transform: rotate(0deg); }
- 100% { transform: rotate(360deg); }
- }
- .clear-btn {
- position: absolute;
- right: 12px;
- top: 50%;
- transform: translateY(-50%);
- width: 16px;
- height: 16px;
- background-color: #999;
- border-radius: 50%;
- display: flex;
- align-items: center;
- justify-content: center;
- cursor: pointer;
- transition: background-color 0.2s;
- }
- .clear-btn:hover {
- background-color: #666;
- }
- .clear-x {
- position: relative;
- width: 8px;
- height: 8px;
- }
- .clear-x:before,
- .clear-x:after {
- content: '';
- position: absolute;
- width: 8px;
- height: 2px;
- background-color: white;
- top: 3px;
- left: 0;
- }
- .clear-x:before {
- transform: rotate(45deg);
- }
- .clear-x:after {
- transform: rotate(-45deg);
- }
- .FlexRow {
- display: flex;
- flex-direction: row;
- }
- .FlexColumn {
- display: flex;
- flex-direction: column;
- }
- </style>
- </head>
- <body class="container FlexRow">
- <div id="app" class="main00 FlexColumn">
- <div class="ListTop FlexRow">
- <div class="ListTop3 FlexRow">
- <div class="title">秒过加资料信息维护</div>
- </div>
- </div>
- <div class="main0 FlexRow">
- <!-- 左侧搜索面板 -->
- <div class="search-panel" style="position: relative;">
- <div v-if="isSearchLoading" class="loading-overlay">
- <div class="loading-spinner"></div>
- </div>
- <div class="search-box FlexRow">
- <div style="position: relative;">
- <input type="text" class="search-input" v-model="searchText" @keyup.enter="searchKeyword"
- placeholder="输入关键词搜索...">
- <div class="clear-btn" v-show="searchText" @click="clearSearch">
- <span class="clear-x"></span>
- </div>
- </div>
- <div class="btn33 FlexRow" @click="searchKeyword">
- <img title="搜索" alt="搜索"
- src="https://kylx365-1253256735.file.myqcloud.com/web/universalpic_search_gray_30x30.png"
- style="width: 20px; height: 20px;" />
- </div>
- </div>
- <!-- 搜索结果列表 -->
- <div class="search-results" style="flex: 1; overflow-y: auto; padding: 10px;">
- <div v-if="searchResults && searchResults.length > 0"
- v-for="(item, index) in searchResults"
- :key="index"
- @click="selectItem(item)"
- style="padding: 10px; margin: 5px 0; background: white; border-radius: 4px; cursor: pointer; transition: background-color 0.2s;"
- :style="{ backgroundColor: selectedItem === item ? '#e6f3ff' : 'white' }"
- class="search-result-item">
- <div v-if="typeof item === 'object'">
- <div style="font-weight: bold;">{{ item.Word || item }}</div>
- <div v-if="item.Author" style="font-size: 12px; color: #666; margin-top: 4px;">
- 作者: {{ item.Author }}
- </div>
- <div v-if="item.SearchType" style="font-size: 12px; color: #666;">
- 类型: {{ item.SearchType }}
- </div>
- <div v-if="item.ShiciUrl" style="font-size: 12px; color: #0066cc; text-decoration: underline;">
- {{ item.ShiciUrl }}
- </div>
- </div>
- <div v-else>{{ item }}</div>
- </div>
- <div v-else-if="searchResults && searchResults.length === 0"
- style="text-align: center; color: #999; padding: 20px;">
- 未找到相关结果
- </div>
- </div>
- </div>
- <!-- 右侧JSON编辑器 -->
- <div class="json-editor" v-if="jsonData" style="position: relative;">
- <div v-if="isDetailLoading" class="loading-overlay">
- <div class="loading-spinner"></div>
- </div>
- <div class="json-node" v-for="(value, key) in jsonData" :key="key">
- <span class="json-key">"{{ key }}":</span>
- <div v-if="typeof value === 'object' && value !== null" style="margin-left: 20px;">
- <div v-for="(subValue, subKey) in value" :key="subKey">
- <span class="json-key">"{{ subKey }}":</span>
- <!-- 处理第二层对象 -->
- <div v-if="typeof subValue === 'object' && subValue !== null && !Array.isArray(subValue)" style="margin-left: 20px;">
- <div v-for="(subSubValue, subSubKey) in subValue" :key="subSubKey">
- <span class="json-key">"{{ subSubKey }}":</span>
- <span v-if="typeof subSubValue === 'string'" class="json-string editable"
- @dblclick="editValue(subValue, subSubKey, key + '.' + subKey + '.' + subSubKey)">
- <template v-if="editingKey === key + '.' + subKey + '.' + subSubKey">
- <input type="text" class="json-editor-input" v-model="subValue[subSubKey]"
- @blur="finishEdit" @keyup.enter="finishEdit" v-focus>
- </template>
- <template v-else>
- "{{ subSubValue }}"
- </template>
- </span>
- <span v-else-if="typeof subSubValue === 'number'" class="json-number editable"
- @dblclick="editValue(subValue, subSubKey, key + '.' + subKey + '.' + subSubKey)">
- <template v-if="editingKey === key + '.' + subKey + '.' + subSubKey">
- <input type="number" class="json-editor-input" v-model.number="subValue[subSubKey]"
- @blur="finishEdit" @keyup.enter="finishEdit" v-focus>
- </template>
- <template v-else>
- {{ subSubValue }}
- </template>
- </span>
- <span v-else-if="typeof subSubValue === 'boolean'" class="json-boolean editable"
- @dblclick="editValue(subValue, subSubKey, key + '.' + subKey + '.' + subSubKey)">
- <template v-if="editingKey === key + '.' + subKey + '.' + subSubKey">
- <select class="json-editor-input" v-model="subValue[subSubKey]" @blur="finishEdit"
- @change="finishEdit" v-focus>
- <option :value="true">true</option>
- <option :value="false">false</option>
- </select>
- </template>
- <template v-else>
- {{ subSubValue }}
- </template>
- </span>
- <span v-else-if="subSubValue === null" class="json-null">null</span>
- <span v-else-if="typeof subSubValue === 'object'" class="json-string">
- [复杂对象]
- </span>
- </div>
- </div>
- <!-- 处理数组 -->
- <div v-else-if="Array.isArray(subValue)" style="margin-left: 20px;">
- <div v-for="(item, index) in subValue" :key="index">
- <span class="json-key">[{{ index }}]:</span>
- <span v-if="typeof item === 'string'" class="json-string editable"
- @dblclick="editValue(subValue, index, key + '.' + subKey + '.' + index)">
- <template v-if="editingKey === key + '.' + subKey + '.' + index">
- <input type="text" class="json-editor-input" v-model="subValue[index]"
- @blur="finishEdit" @keyup.enter="finishEdit" v-focus>
- </template>
- <template v-else>
- <template v-if="['BiShunArr', 'BiShunArr2', 'KaitiArr'].includes(subKey)">
- <img :src="item"
- style="max-width: 100px; max-height: 100px; margin: 5px 0;"
- @error="handleImageError($event)"
- :alt="item" />
- <div class="json-string" style="font-size: 12px; color: #666;">"{{ item }}"</div>
- </template>
- <template v-else>
- "{{ item }}"
- </template>
- </template>
- </span>
- <span v-else-if="typeof item === 'number'" class="json-number editable"
- @dblclick="editValue(subValue, index, key + '.' + subKey + '.' + index)">
- <template v-if="editingKey === key + '.' + subKey + '.' + index">
- <input type="number" class="json-editor-input" v-model.number="subValue[index]"
- @blur="finishEdit" @keyup.enter="finishEdit" v-focus>
- </template>
- <template v-else>
- {{ item }}
- </template>
- </span>
- <span v-else-if="typeof item === 'boolean'" class="json-boolean editable"
- @dblclick="editValue(subValue, index, key + '.' + subKey + '.' + index)">
- <template v-if="editingKey === key + '.' + subKey + '.' + index">
- <select class="json-editor-input" v-model="subValue[index]" @blur="finishEdit"
- @change="finishEdit" v-focus>
- <option :value="true">true</option>
- <option :value="false">false</option>
- </select>
- </template>
- <template v-else>
- {{ item }}
- </template>
- </span>
- <span v-else-if="item === null" class="json-null">null</span>
- <div v-else-if="typeof item === 'object'" style="margin-left: 20px;">
- <div v-for="(itemValue, itemKey) in item" :key="itemKey">
- <span class="json-key">"{{ itemKey }}":</span>
- <span v-if="typeof itemValue === 'string'" class="json-string editable"
- @dblclick="editValue(item, itemKey, key + '.' + subKey + '.' + index + '.' + itemKey)">
- <template v-if="editingKey === key + '.' + subKey + '.' + index + '.' + itemKey">
- <input type="text" class="json-editor-input" v-model="item[itemKey]"
- @blur="finishEdit" @keyup.enter="finishEdit" v-focus>
- </template>
- <template v-else>
- "{{ itemValue }}"
- </template>
- </span>
- <span v-else-if="typeof itemValue === 'number'" class="json-number editable"
- @dblclick="editValue(item, itemKey, key + '.' + subKey + '.' + index + '.' + itemKey)">
- <template v-if="editingKey === key + '.' + subKey + '.' + index + '.' + itemKey">
- <input type="number" class="json-editor-input" v-model.number="item[itemKey]"
- @blur="finishEdit" @keyup.enter="finishEdit" v-focus>
- </template>
- <template v-else>
- {{ itemValue }}
- </template>
- </span>
- <div v-else-if="Array.isArray(itemValue)" style="margin-left: 20px;">
- <div v-for="(arrayItem, arrayIndex) in itemValue" :key="arrayIndex">
- <span class="json-key">[{{ arrayIndex }}]:</span>
- <span v-if="typeof arrayItem === 'string'" class="json-string editable"
- @dblclick="editValue(itemValue, arrayIndex, key + '.' + subKey + '.' + index + '.' + itemKey + '.' + arrayIndex)">
- <template v-if="editingKey === key + '.' + subKey + '.' + index + '.' + itemKey + '.' + arrayIndex">
- <input type="text" class="json-editor-input" v-model="itemValue[arrayIndex]"
- @blur="finishEdit" @keyup.enter="finishEdit" v-focus>
- </template>
- <template v-else>
- "{{ arrayItem }}"
- </template>
- </span>
- <span v-else-if="typeof arrayItem === 'number'" class="json-number editable"
- @dblclick="editValue(itemValue, arrayIndex, key + '.' + subKey + '.' + index + '.' + itemKey + '.' + arrayIndex)">
- <template v-if="editingKey === key + '.' + subKey + '.' + index + '.' + itemKey + '.' + arrayIndex">
- <input type="number" class="json-editor-input" v-model.number="itemValue[arrayIndex]"
- @blur="finishEdit" @keyup.enter="finishEdit" v-focus>
- </template>
- <template v-else>
- {{ arrayItem }}
- </template>
- </span>
- <span v-else-if="typeof arrayItem === 'boolean'" class="json-boolean editable"
- @dblclick="editValue(itemValue, arrayIndex, key + '.' + subKey + '.' + index + '.' + itemKey + '.' + arrayIndex)">
- <template v-if="editingKey === key + '.' + subKey + '.' + index + '.' + itemKey + '.' + arrayIndex">
- <select class="json-editor-input" v-model="itemValue[arrayIndex]" @blur="finishEdit"
- @change="finishEdit" v-focus>
- <option :value="true">true</option>
- <option :value="false">false</option>
- </select>
- </template>
- <template v-else>
- {{ arrayItem }}
- </template>
- </span>
- <span v-else-if="arrayItem === null" class="json-null">null</span>
- <span v-else-if="typeof arrayItem === 'object'" class="json-string">[复杂对象]</span>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- <!-- 处理基本类型 -->
- <span v-else-if="typeof subValue === 'string'" class="json-string editable"
- @dblclick="editValue(value, subKey, key + '.' + subKey)">
- <template v-if="editingKey === key + '.' + subKey">
- <input type="text" class="json-editor-input" v-model="value[subKey]"
- @blur="finishEdit" @keyup.enter="finishEdit" v-focus>
- </template>
- <template v-else>
- "{{ subValue }}"
- </template>
- </span>
- <span v-else-if="typeof subValue === 'number'" class="json-number editable"
- @dblclick="editValue(value, subKey, key + '.' + subKey)">
- <template v-if="editingKey === key + '.' + subKey">
- <input type="number" class="json-editor-input" v-model.number="value[subKey]"
- @blur="finishEdit" @keyup.enter="finishEdit" v-focus>
- </template>
- <template v-else>
- {{ subValue }}
- </template>
- </span>
- <span v-else-if="typeof subValue === 'boolean'" class="json-boolean editable"
- @dblclick="editValue(value, subKey, key + '.' + subKey)">
- <template v-if="editingKey === key + '.' + subKey">
- <select class="json-editor-input" v-model="value[subKey]" @blur="finishEdit"
- @change="finishEdit" v-focus>
- <option :value="true">true</option>
- <option :value="false">false</option>
- </select>
- </template>
- <template v-else>
- {{ subValue }}
- </template>
- </span>
- <span v-else-if="subValue === null" class="json-null">null</span>
- </div>
- </div>
- <span v-else-if="typeof value === 'string'" class="json-string editable"
- @dblclick="editValue(jsonData, key, key)">
- <template v-if="editingKey === key">
- <input type="text" class="json-editor-input" v-model="jsonData[key]" @blur="finishEdit"
- @keyup.enter="finishEdit" v-focus>
- </template>
- <template v-else>
- "{{ value }}"
- </template>
- </span>
- <span v-else-if="typeof value === 'number'" class="json-number editable"
- @dblclick="editValue(jsonData, key, key)">
- <template v-if="editingKey === key">
- <input type="number" class="json-editor-input" v-model.number="jsonData[key]"
- @blur="finishEdit" @keyup.enter="finishEdit" v-focus>
- </template>
- <template v-else>
- {{ value }}
- </template>
- </span>
- <span v-else-if="typeof value === 'boolean'" class="json-boolean editable"
- @dblclick="editValue(jsonData, key, key)">
- <template v-if="editingKey === key">
- <select class="json-editor-input" v-model="jsonData[key]" @blur="finishEdit"
- @change="finishEdit" v-focus>
- <option :value="true">true</option>
- <option :value="false">false</option>
- </select>
- </template>
- <template v-else>
- {{ value }}
- </template>
- </span>
- <span v-else-if="value === null" class="json-null">null</span>
- </div>
- </div>
- <div v-else class="json-editor FlexColumn" style="justify-content: center; align-items: center;">
- <div style="font-size:36px;color:#999;">请输入关键词搜索</div>
- </div>
- </div>
- <!-- 保存按钮 -->
- <div class="btn-group" v-if="jsonData">
- <button type="button" class="btn btn-default" @click="resetData">重置</button>
- <button type="button" class="btn btn-primary" @click="saveData">保存</button>
- </div>
- <!-- Toast提示 -->
- <div class="toast" :class="{ show: showToast, [toastType]: showToast }">{{ toastMessage }}</div>
- </div>
- <script>
- // 自定义指令:自动聚焦
- Vue.directive('focus', {
- inserted: function (el) {
- el.focus()
- }
- })
- new Vue({
- el: '#app',
- data: {
- searchText: '',
- jsonData: null,
- originalData: null,
- editingKey: null,
- showToast: false,
- toastMessage: '',
- toastType: 'info',
- searchResults: null,
- selectedItem: null,
- isSearchLoading: false,
- isDetailLoading: false
- },
- methods: {
- // 清空搜索
- clearSearch() {
- this.searchText = '';
- this.jsonData = null;
- this.originalData = null;
- this.searchResults = null;
- this.selectedItem = null;
- },
- // 搜索关键词
- searchKeyword() {
- if (!this.searchText.trim()) {
- this.showToastMessage('请输入搜索关键词', 'info');
- return;
- }
- this.isSearchLoading = true;
- fetch(`/api/GetMiaoguoLiteracyListByWord?Word=${encodeURIComponent(this.searchText)}`)
- .then(response => response.json())
- .then(data => {
- data = data.result;
- if (data && Array.isArray(data)) {
- // 对搜索结果进行三级排序
- data.sort((a, b) => {
- // 检查是否是对象
- const aIsObj = typeof a === 'object' && a !== null;
- const bIsObj = typeof b === 'object' && b !== null;
-
- // 获取Word值
- const aWord = aIsObj ? a.Word : a;
- const bWord = bIsObj ? b.Word : b;
-
- // 检查是否是精确匹配(Word等于关键词且其他字段为空)
- const aIsExactMatch = aIsObj &&
- aWord === this.searchText &&
- (!a.Author || a.Author === '') &&
- (!a.SearchType || a.SearchType === '') &&
- (!a.ShiciUrl || a.ShiciUrl === '');
-
- const bIsExactMatch = bIsObj &&
- bWord === this.searchText &&
- (!b.Author || b.Author === '') &&
- (!b.SearchType || b.SearchType === '') &&
- (!b.ShiciUrl || b.ShiciUrl === '');
-
- // 检查是否是Word匹配但有其他数据
- const aIsPartialMatch = aIsObj &&
- aWord === this.searchText &&
- !aIsExactMatch;
-
- const bIsPartialMatch = bIsObj &&
- bWord === this.searchText &&
- !bIsExactMatch;
-
- // 三级排序逻辑
- if (aIsExactMatch !== bIsExactMatch) {
- // 第一优先级:精确匹配(Word等于关键词且其他字段为空)
- return aIsExactMatch ? -1 : 1;
- } else if (aIsPartialMatch !== bIsPartialMatch) {
- // 第二优先级:Word等于关键词但其他字段有数据
- return aIsPartialMatch ? -1 : 1;
- } else if (aWord === this.searchText && bWord !== this.searchText) {
- // 第三优先级:Word等于关键词 vs 不等于
- return -1;
- } else if (aWord !== this.searchText && bWord === this.searchText) {
- return 1;
- }
- // 其他情况保持原有顺序
- return 0;
- });
-
- this.searchResults = data;
- this.selectedItem = null;
- this.jsonData = null; // 清空右侧详情
- this.originalData = null;
- } else {
- this.searchResults = [];
- this.showToastMessage('未找到相关结果', 'info');
- }
- this.isSearchLoading = false;
- })
- .catch(error => {
- console.error('搜索出错:', error);
- this.showToastMessage('搜索失败,请稍后重试', 'error');
- this.isSearchLoading = false;
- });
- },
-
- // 选择列表项
- selectItem(item) {
- this.selectedItem = item;
- this.isDetailLoading = true;
-
- fetch(`/api/GetMiaoguoLiteracyListByID?ID=${this.selectedItem.ID}`)
- .then(response => response.text())
- .then(text => {
- // 修复JSON格式问题,添加缺失的逗号
- const fixedText = this.fixJsonFormat(text);
- const data = JSON.parse(fixedText);
- var json = data.result;
- this.jsonData = json;
- this.originalData = JSON.parse(JSON.stringify(json)); // 深拷贝
- this.isDetailLoading = false;
- })
- .catch(error => {
- console.error('获取详情出错:', error);
- this.showToastMessage('获取详情失败,请稍后重试', 'error');
- this.isDetailLoading = false;
- });
- },
- // 编辑值
- editValue(obj, key, path) {
- this.editingKey = path || key;
- },
- // 完成编辑
- finishEdit() {
- this.editingKey = null;
- },
- // 重置数据
- resetData() {
- if (this.originalData) {
- this.jsonData = JSON.parse(JSON.stringify(this.originalData));
- }
- },
- // 保存数据
- saveData() {
- fetch('/api/UpdateMiaoguoLiteracyByWord', {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json'
- },
- body: JSON.stringify({
- ID: this.selectedItem.ID,
- JSONString: JSON.stringify(this.jsonData)
- })
- })
- .then(response => response.json())
- .then(data => {
- if (data) {
- this.showToastMessage('保存成功', 'success');
- this.originalData = JSON.parse(JSON.stringify(this.jsonData));
- } else {
- this.showToastMessage('保存失败', 'error');
- }
- })
- .catch(error => {
- console.error('保存出错:', error);
- this.showToastMessage('保存失败,请稍后重试', 'error');
- });
- },
- // 显示Toast消息
- showToastMessage(message, type = 'info') {
- this.toastMessage = message;
- this.toastType = type;
- this.showToast = true;
- setTimeout(() => {
- this.showToast = false;
- }, 3000);
- },
-
- // 修复JSON格式问题
- fixJsonFormat(jsonStr) {
- // 修复缺少逗号的问题
- // 在引号后面跟着引号的地方添加逗号
- let fixed = jsonStr.replace(/(["\d])\s*"([^"]+)":/g, '$1,"$2":');
- // 修复数字后面跟着引号的情况
- fixed = fixed.replace(/(\d+)\s*"([^"]+)":/g, '$1,"$2":');
- // 修复大括号后面跟着引号的情况
- fixed = fixed.replace(/({)\s*"([^"]+)":/g, '$1"$2":');
- // 修复方括号后面跟着引号的情况
- fixed = fixed.replace(/(\[)\s*"([^"]+)":/g, '$1"$2":');
-
- //console.log("原始JSON:", jsonStr);
- //console.log("修复后JSON:", fixed);
-
- return fixed;
- },
-
- // 处理图片加载错误
- handleImageError(event) {
- // 添加错误样式,显示边框和错误提示
- event.target.style.border = '1px dashed #ff6b6b';
- event.target.style.padding = '10px';
- event.target.style.backgroundColor = '#fff0f0';
-
- // 如果是gif图片,尝试使用代理或CORS解决方案
- if (event.target.src.endsWith('.gif')) {
- // 可以尝试使用代理服务器来解决CORS问题
- // 这里我们只添加一个提示,实际项目中可以根据需要实现代理
- const originalSrc = event.target.src;
-
- // 创建一个错误提示元素
- const errorDiv = document.createElement('div');
- errorDiv.style.color = '#ff6b6b';
- errorDiv.style.fontSize = '12px';
- errorDiv.style.marginTop = '5px';
- errorDiv.textContent = 'GIF图片加载失败,可能存在跨域问题';
-
- // 将错误提示添加到图片后面
- event.target.parentNode.insertBefore(errorDiv, event.target.nextSibling);
- }
- }
- }
- });
- </script>
- </body>
- </html>
|