(global["webpackJsonp"] = global["webpackJsonp"] || []).push([["pkgUpload/common/vendor"],{

/***/ 255:
/*!****************************************************!*\
  !*** D:/project/zhizhu/service/selectBookImage.js ***!
  \****************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

"use strict";
/* WEBPACK VAR INJECTION */(function(uni) {

var _interopRequireDefault = __webpack_require__(/*! @babel/runtime/helpers/interopRequireDefault */ 4);
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.fetchOnSaleProducts = void 0;
var _regenerator = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/regenerator */ 36));
var _defineProperty2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/defineProperty */ 11));
var _slicedToArray2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/slicedToArray */ 5));
var _asyncToGenerator2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/asyncToGenerator */ 38));
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
/**
 * 获取在售商品信息
 * @param {String} keyword - 搜索关键词（ISBN或书名）
 * @param {String} sortType - 排序类型
 * @param {String} conditionValue - 品相条件
 * @param {String} cookies - 用户cookies
 * @param {Object} options - 可选参数对象
 * @param {String} options.publisher - 出版社（版权页比价时使用）
 * @param {String} options.author - 作者（版权页比价时使用）
 * @param {Boolean} options.autoSwitchAccount - 是否自动切换账号（默认为true）
 * @param {Number} options.retryCount - 重试次数（内部使用）
 * @returns {Promise<Array>} - 返回在售商品信息数组
 */
var fetchOnSaleProducts = /*#__PURE__*/function () {
  var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(keyword, sortType, conditionValue, cookies) {
    var options,
      autoSwitchAccount,
      retryCount,
      MAX_RETRY,
      searchParams,
      queryString,
      apiUrl,
      _yield$uni$request,
      _yield$uni$request2,
      err,
      res,
      newCookie,
      responseData,
      errorMsg,
      isLoginExpired,
      _newCookie,
      products,
      list,
      limit,
      i,
      item,
      shippingFee,
      shippingFeeText,
      shipping,
      priceText,
      cleanPrice,
      totalPrice,
      _args = arguments;
    return _regenerator.default.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            options = _args.length > 4 && _args[4] !== undefined ? _args[4] : {};
            _context.prev = 1;
            // 设置默认值
            autoSwitchAccount = options.autoSwitchAccount !== false; // 默认为true
            retryCount = options.retryCount || 0;
            MAX_RETRY = 3; // 最大重试次数
            // 首先检查cookies是否存在，不存在则尝试从本地获取最新的
            if (!cookies) {
              cookies = uni.getStorageSync('UserInfoCookies');
              console.log('从本地存储获取cookies:', cookies);
            }

            // 如果还是没有cookies，提示用户登录
            if (cookies) {
              _context.next = 9;
              break;
            }
            uni.showToast({
              title: '请先在设置页面登录孔网账号',
              icon: 'none',
              duration: 2000
            });
            return _context.abrupt("return", []);
          case 9:
            // 构建直接调用孔夫子API的参数
            searchParams = {
              searchType: 'category',
              dataType: '0',
              page: '1',
              keyword: keyword,
              sortType: sortType,
              quality: conditionValue,
              actionPath: 'sortType,quality',
              quaSelect: '2',
              userArea: '13003000000'
            }; // 如果是版权页比价，添加出版社和作者参数
            if (options.publisher) {
              searchParams.press = options.publisher;
            }
            if (options.author) {
              searchParams.author = options.author;
            }

            // 构建URL查询字符串
            queryString = Object.entries(searchParams).map(function (_ref2) {
              var _ref3 = (0, _slicedToArray2.default)(_ref2, 2),
                key = _ref3[0],
                value = _ref3[1];
              return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(value));
            }).join('&'); // 孔夫子API的URL
            apiUrl = "https://search.kongfz.com/pc-gw/search-web/client/pc/product/keyword/list?".concat(queryString); // 调用孔夫子API
            _context.next = 16;
            return uni.request({
              url: apiUrl,
              method: 'GET',
              header: {
                'Cookie': "PHPSESSID=".concat(cookies)
              }
            });
          case 16:
            _yield$uni$request = _context.sent;
            _yield$uni$request2 = (0, _slicedToArray2.default)(_yield$uni$request, 2);
            err = _yield$uni$request2[0];
            res = _yield$uni$request2[1];
            if (!err) {
              _context.next = 31;
              break;
            }
            console.error('请求失败:', err);

            // 如果允许自动切换账号且未超过最大重试次数
            if (!(autoSwitchAccount && retryCount < MAX_RETRY)) {
              _context.next = 29;
              break;
            }
            console.log("\u5C1D\u8BD5\u5207\u6362\u8D26\u53F7\u5E76\u91CD\u8BD5(".concat(retryCount + 1, "/").concat(MAX_RETRY, ")..."));
            _context.next = 26;
            return tryNextAccount();
          case 26:
            newCookie = _context.sent;
            if (!newCookie) {
              _context.next = 29;
              break;
            }
            return _context.abrupt("return", fetchOnSaleProducts(keyword, sortType, conditionValue, newCookie, _objectSpread(_objectSpread({}, options), {}, {
              retryCount: retryCount + 1
            })));
          case 29:
            uni.showToast({
              title: '网络请求失败',
              icon: 'none'
            });
            return _context.abrupt("return", []);
          case 31:
            // 处理接口返回的数据
            console.log("res", res);
            responseData = res.data || {}; // 避免 res.data 为 undefined
            console.log("在售商品原始数据", responseData);

            // 检查孔夫子API返回的状态
            if (!(!responseData || responseData.status !== 1)) {
              _context.next = 52;
              break;
            }
            errorMsg = responseData.message || '请求出错';
            console.error('孔夫子API错误:', errorMsg);

            // 检查是否是登录失效
            isLoginExpired = errorMsg.includes('登录') || errorMsg.includes('cookie') || responseData.errCode && ["102", "1000", "1001", "1002", "1003", "1004", "1005", "1006", "1007", "1008", "1009"].includes(responseData.errCode) || responseData.errType && ["102", "1000", "1001", "1002", "1003", "1004", "1005", "1006", "1007", "1008", "1009"].includes(responseData.errType);
            console.log("isLoginExpired", isLoginExpired);
            if (!isLoginExpired) {
              _context.next = 50;
              break;
            }
            if (!(autoSwitchAccount && retryCount < MAX_RETRY)) {
              _context.next = 47;
              break;
            }
            console.log("\u767B\u5F55\u5DF2\u8FC7\u671F\uFF0C\u5C1D\u8BD5\u5207\u6362\u8D26\u53F7\u5E76\u91CD\u8BD5(".concat(retryCount + 1, "/").concat(MAX_RETRY, ")..."));
            _context.next = 44;
            return tryNextAccount();
          case 44:
            _newCookie = _context.sent;
            if (!_newCookie) {
              _context.next = 47;
              break;
            }
            return _context.abrupt("return", fetchOnSaleProducts(keyword, sortType, conditionValue, _newCookie, _objectSpread(_objectSpread({}, options), {}, {
              retryCount: retryCount + 1
            })));
          case 47:
            uni.showToast({
              title: '登录已过期，请重新登录',
              icon: 'none',
              duration: 2000
            });
            _context.next = 51;
            break;
          case 50:
            uni.showToast({
              title: errorMsg,
              icon: 'none',
              duration: 2000
            });
          case 51:
            return _context.abrupt("return", []);
          case 52:
            // 解析孔夫子API的响应数据
            products = [];
            if (responseData.data && responseData.data.itemResponse && responseData.data.itemResponse.list) {
              list = responseData.data.itemResponse.list; // 只取前12条记录
              limit = Math.min(12, list.length);
              for (i = 0; i < limit; i++) {
                item = list[i]; // 解析运费信息
                shippingFee = 0;
                shippingFeeText = '0';
                if (item.postage && item.postage.shippingList && item.postage.shippingList.length > 0) {
                  shipping = item.postage.shippingList[0];
                  shippingFee = parseFloat(shipping.shippingFee || 0);
                  shippingFeeText = shipping.shippingFeeText || '0';
                }

                // 处理价格，去除非数字字符
                priceText = item.priceText || '0';
                cleanPrice = parseFloat(priceText.replace(/[^\d.]/g, ''));
                totalPrice = Number((cleanPrice + shippingFee).toFixed(2));
                products.push({
                  id: item.id || null,
                  bookName: item.title || '未知书名',
                  imageUrl: item.imgBigUrl ? item.imgBigUrl.trim() : null,
                  totalPrice: totalPrice,
                  bookPrice: cleanPrice,
                  shopName: item.shopName,
                  shippingFee: shippingFee,
                  shippingFeeText: shippingFeeText,
                  author: item.author || '未知作者',
                  publisher: item.press || '未知出版社',
                  qualityText: item.qualityText || '未知品相'
                });
              }
            }
            console.log('获取在售商品信息成功:', products);
            return _context.abrupt("return", products);
          case 58:
            _context.prev = 58;
            _context.t0 = _context["catch"](1);
            console.error('获取在售商品信息失败:', _context.t0);
            uni.showToast({
              title: '获取在售商品信息失败',
              icon: 'none'
            });
            return _context.abrupt("return", []);
          case 63:
          case "end":
            return _context.stop();
        }
      }
    }, _callee, null, [[1, 58]]);
  }));
  return function fetchOnSaleProducts(_x, _x2, _x3, _x4) {
    return _ref.apply(this, arguments);
  };
}();

/**
 * 刷新cookies
 * @param {String} username - 孔网账号
 * @param {String} password - 孔网密码
 * @returns {Promise<Object>} - 返回登录结果，包含cookies
 */
exports.fetchOnSaleProducts = fetchOnSaleProducts;
var refreshCookies = /*#__PURE__*/function () {
  var _ref4 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(username, password) {
    var initResponse, initCookies, loginData, loginResponse, loginCookies, allCookies;
    return _regenerator.default.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            _context2.prev = 0;
            _context2.next = 3;
            return uniRequestPromise({
              url: 'https://login.kongfz.com/Pc/Login/account',
              method: 'GET'
            });
          case 3:
            initResponse = _context2.sent;
            // 提取初始响应中的Cookie
            initCookies = extractCookiesFromHeaders(initResponse.header); // 第二步：发送登录请求，携带用户名和密码
            loginData = {
              loginName: username,
              loginPass: password
            };
            _context2.next = 8;
            return uniRequestPromise({
              url: 'https://login.kongfz.com/Pc/Login/account',
              method: 'POST',
              data: loginData,
              header: {
                'Content-Type': 'application/x-www-form-urlencoded',
                'Cookie': formatCookieHeader(initCookies)
              }
            });
          case 8:
            loginResponse = _context2.sent;
            // 提取登录响应中的Cookie
            loginCookies = extractCookiesFromHeaders(loginResponse.header); // 合并所有Cookie
            allCookies = _objectSpread(_objectSpread({}, initCookies), loginCookies);
            return _context2.abrupt("return", {
              success: true,
              cookies: allCookies,
              responseData: loginResponse.data
            });
          case 14:
            _context2.prev = 14;
            _context2.t0 = _context2["catch"](0);
            console.error('刷新cookies失败:', _context2.t0);
            return _context2.abrupt("return", {
              success: false,
              error: _context2.t0.message || '登录请求发生错误'
            });
          case 18:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2, null, [[0, 14]]);
  }));
  return function refreshCookies(_x5, _x6) {
    return _ref4.apply(this, arguments);
  };
}();

/**
 * 尝试切换到下一个可用账号并获取新cookie
 * @returns {Promise<String|null>} 返回新的cookie或null（如果无法切换账号）
 */
var tryNextAccount = /*#__PURE__*/function () {
  var _ref5 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3() {
    var accountsStr, accounts, currentIndex, nextIndex, nextAccount, result, newCookie;
    return _regenerator.default.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            _context3.prev = 0;
            // 获取账号列表
            accountsStr = uni.getStorageSync('accounts');
            if (accountsStr) {
              _context3.next = 5;
              break;
            }
            console.log('没有可用的备用账号');
            return _context3.abrupt("return", null);
          case 5:
            accounts = JSON.parse(accountsStr);
            if (!(!accounts || accounts.length === 0)) {
              _context3.next = 9;
              break;
            }
            console.log('账号列表为空');
            return _context3.abrupt("return", null);
          case 9:
            // 获取当前活跃账号索引
            currentIndex = uni.getStorageSync('currentAccountIndex');
            currentIndex = currentIndex !== '' ? parseInt(currentIndex) : 0;

            // 计算下一个账号索引
            nextIndex = (currentIndex + 1) % accounts.length; // 如果循环回到了当前账号，说明只有一个账号或已经尝试了所有账号
            if (!(nextIndex === currentIndex)) {
              _context3.next = 15;
              break;
            }
            console.log('已尝试所有账号，无法继续切换');
            return _context3.abrupt("return", null);
          case 15:
            // 获取下一个账号信息
            nextAccount = accounts[nextIndex]; // 清除原有cookie
            uni.removeStorageSync('cookies');
            uni.removeStorageSync('UserInfoCookies');

            // 使用下一个账号登录
            _context3.next = 20;
            return refreshCookies(nextAccount.username, nextAccount.password);
          case 20:
            result = _context3.sent;
            if (!(result.success && result.cookies && result.cookies.PHPSESSID)) {
              _context3.next = 35;
              break;
            }
            // 更新账号状态
            accounts.forEach(function (acc) {
              return acc.isActive = false;
            });
            accounts[nextIndex].isActive = true;

            // 保存cookie
            newCookie = result.cookies.PHPSESSID;
            uni.setStorageSync('cookies', newCookie);
            uni.setStorageSync('UserInfoCookies', newCookie);
            uni.setStorageSync('KongfzUserName', nextAccount.username);

            // 保存更新后的账号列表和当前索引
            uni.setStorageSync('accounts', JSON.stringify(accounts));
            uni.setStorageSync('currentAccountIndex', nextIndex);

            // 发送自定义事件通知页面更新账号状态
            uni.$emit('accountSwitched', {
              index: nextIndex,
              username: nextAccount.username
            });
            console.log("\u6210\u529F\u5207\u6362\u5230\u8D26\u53F7: ".concat(nextAccount.username));
            return _context3.abrupt("return", newCookie);
          case 35:
            console.log('切换账号失败，尝试下一个账号');
            // 递归尝试下一个账号
            accounts[nextIndex].isActive = false;
            uni.setStorageSync('accounts', JSON.stringify(accounts));
            uni.setStorageSync('currentAccountIndex', nextIndex);
            return _context3.abrupt("return", tryNextAccount());
          case 40:
            _context3.next = 46;
            break;
          case 42:
            _context3.prev = 42;
            _context3.t0 = _context3["catch"](0);
            console.error('切换账号出错:', _context3.t0);
            return _context3.abrupt("return", null);
          case 46:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3, null, [[0, 42]]);
  }));
  return function tryNextAccount() {
    return _ref5.apply(this, arguments);
  };
}();

/**
 * 将 uni.request 转换为 Promise 形式
 */
var uniRequestPromise = function uniRequestPromise(options) {
  return new Promise(function (resolve, reject) {
    uni.request(_objectSpread(_objectSpread({}, options), {}, {
      success: function success(res) {
        return resolve(res);
      },
      fail: function fail(err) {
        return reject(err);
      }
    }));
  });
};

/**
 * 从响应头中提取 Cookies
 */
var extractCookiesFromHeaders = function extractCookiesFromHeaders(headers) {
  var cookies = {};
  var cookieHeaders = headers['Set-Cookie'] || headers['set-cookie'];
  if (!cookieHeaders) return cookies;

  // 处理可能是数组或字符串的 Cookie 头
  var cookieList = Array.isArray(cookieHeaders) ? cookieHeaders : [cookieHeaders];
  cookieList.forEach(function (cookieStr) {
    // 提取 cookie 名值对（忽略路径、过期时间等属性）
    var cookieParts = cookieStr.split(';')[0].split('=');
    if (cookieParts.length >= 2) {
      cookies[cookieParts[0].trim()] = cookieParts[1].trim();
    }
  });
  return cookies;
};

/**
 * 将 Cookie 对象格式化为请求头字符串
 */
var formatCookieHeader = function formatCookieHeader(cookies) {
  return Object.entries(cookies).map(function (_ref6) {
    var _ref7 = (0, _slicedToArray2.default)(_ref6, 2),
      key = _ref7[0],
      value = _ref7[1];
    return "".concat(key, "=").concat(value);
  }).join('; ');
};
/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./node_modules/@dcloudio/uni-mp-weixin/dist/index.js */ 2)["default"]))

/***/ }),

/***/ 256:
/*!*****************************************!*\
  !*** D:/project/zhizhu/utils/upload.js ***!
  \*****************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

"use strict";
/* WEBPACK VAR INJECTION */(function(uni) {

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.uploadFile = void 0;
// File upload utility

/**
 * Upload a file to the server
 * @param {Object} options - Upload options
 * @param {string} options.url - Upload URL
 * @param {string} options.filePath - Local file path
 * @param {Object} options.formData - Additional form data
 * @returns {Promise} Upload result
 */
var uploadFile = function uploadFile(options) {
  return new Promise(function (resolve, reject) {
    uni.uploadFile({
      url: options.url,
      filePath: options.filePath,
      name: options.name || 'file',
      formData: options.formData || {},
      success: function success(res) {
        if (res.statusCode === 200) {
          try {
            var data = JSON.parse(res.data);
            resolve(data);
          } catch (e) {
            resolve(res.data);
          }
        } else {
          reject(new Error("Upload failed with status ".concat(res.statusCode)));
        }
      },
      fail: function fail(err) {
        reject(err);
      }
    });
  });
};
exports.uploadFile = uploadFile;
/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./node_modules/@dcloudio/uni-mp-weixin/dist/index.js */ 2)["default"]))

/***/ }),

/***/ 273:
/*!**********************************************************!*\
  !*** D:/project/zhizhu/service/getAuthorAndPublisher.js ***!
  \**********************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

"use strict";
/* WEBPACK VAR INJECTION */(function(uni) {

var _interopRequireDefault = __webpack_require__(/*! @babel/runtime/helpers/interopRequireDefault */ 4);
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getAuthorAndPublisher = exports.default = void 0;
var _regenerator = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/regenerator */ 36));
var _asyncToGenerator2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/asyncToGenerator */ 38));
/**
 * 根据关键词获取作者和出版社数据
 * @param {string} keyword - 搜索关键词
 * @param {string} cookies - 用户cookies
 * @returns {Promise<{authors: string[], publishers: string[]}>} 返回作者和出版社数据
 */
var getAuthorAndPublisher = /*#__PURE__*/function () {
  var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(keyword, cookies) {
    var response, data, authors, publishers, authorArray, publisherArray;
    return _regenerator.default.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            _context.prev = 0;
            _context.next = 3;
            return new Promise(function (resolve, reject) {
              uni.request({
                url: 'https://api.buzhiyushu.cn/zhishu/shopGoods/getAuthorAndPublisher',
                method: 'GET',
                data: {
                  keyword: keyword,
                  cookies: cookies
                },
                success: function success(res) {
                  console.log('API原始响应:', JSON.stringify(res, null, 2));
                  resolve(res);
                },
                fail: function fail(err) {
                  console.error('API请求失败:', err);
                  reject(new Error(err.errMsg || '网络请求失败'));
                }
              });
            });
          case 3:
            response = _context.sent;
            if (!(!response.data || response.data.code !== 200)) {
              _context.next = 7;
              break;
            }
            console.log('API返回数据无效或请求失败');
            return _context.abrupt("return", {
              authors: [],
              publishers: []
            });
          case 7:
            data = response.data.data || []; // 提取作者和出版社数据
            authors = new Set();
            publishers = new Set();
            data.forEach(function (item) {
              // 处理作者数据
              if (item.author) {
                var author = item.author.trim();
                if (author) {
                  authors.add(author);
                }
              }

              // 处理出版社数据
              if (item.press) {
                var press = item.press.trim();
                if (press) {
                  publishers.add(press);
                }
              }
            });

            // 转换为数组并过滤掉空值
            authorArray = Array.from(authors).filter(Boolean).slice(0, 10);
            publisherArray = Array.from(publishers).filter(Boolean).slice(0, 10);
            console.log('提取的作者列表(前10条):', authorArray);
            console.log('提取的出版社列表(前10条):', publisherArray);
            return _context.abrupt("return", {
              authors: authorArray,
              publishers: publisherArray
            });
          case 18:
            _context.prev = 18;
            _context.t0 = _context["catch"](0);
            console.error('获取作者和出版社数据出错:', _context.t0);
            return _context.abrupt("return", {
              authors: [],
              publishers: []
            });
          case 22:
          case "end":
            return _context.stop();
        }
      }
    }, _callee, null, [[0, 18]]);
  }));
  return function getAuthorAndPublisher(_x, _x2) {
    return _ref.apply(this, arguments);
  };
}();

/**
 * 导出所有函数
 */
exports.getAuthorAndPublisher = getAuthorAndPublisher;
var _default = {
  getAuthorAndPublisher: getAuthorAndPublisher
};
exports.default = _default;
/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./node_modules/@dcloudio/uni-mp-weixin/dist/index.js */ 2)["default"]))

/***/ })

}]);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pkgUpload/common/vendor.js.map