{"id":2089,"date":"2025-08-02T09:58:04","date_gmt":"2025-08-02T01:58:04","guid":{"rendered":"https:\/\/note.ui11.cc\/?p=2089"},"modified":"2025-08-02T09:58:04","modified_gmt":"2025-08-02T01:58:04","slug":"%e8%84%9a%e6%9c%ac","status":"publish","type":"post","link":"https:\/\/note.ui11.cc\/index.php\/2025\/08\/02\/%e8%84%9a%e6%9c%ac\/","title":{"rendered":"\u811a\u672c"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>\/\/ \u62bd\u53d6\u516c\u5171\u63a5\u53e3\u8bf7\u6c42\u51fd\u6570\uff08\u5f02\u6b65\u5904\u7406\uff09\nfunction requestApi(url, params) {\n  return new Promise((resolve, reject) => {\n    const proxy = viewModel.setProxy({\n      tempApi: { \/\/ \u4f7f\u7528\u4e34\u65f6key\u907f\u514d\u8986\u76d6\u5df2\u6709proxy\n        url: url,\n        method: 'post',\n        options: { \"domainKey\": 'xlx001' }\n      }\n    });\n    try {\n      \/\/ \u4f18\u5148\u4f7f\u7528\u5f02\u6b65\u65b9\u6cd5\uff0c\u907f\u514d\u963b\u585eUI\n      proxy.tempApi(params, (err, result) => {\n        if (err) {\n          console.error('\u63a5\u53e3\u8bf7\u6c42\u5931\u8d25:', err);\n          reject(err);\n          return;\n        }\n        resolve(result);\n      });\n    } catch (e) {\n      console.error('\u8bf7\u6c42\u5904\u7406\u5f02\u5e38:', e);\n      reject(e);\n    }\n  });\n}\n\n\/\/ \u6570\u636e\u52a0\u8f7d\u540e\u4e8b\u4ef6\nviewModel.on('afterLoadData', async function (data) {\n  const mode = viewModel.getParams().mode;\n  if (mode !== \"browse\") {\n    const staffName = viewModel.get(\"staff_name\").getValue();\n    if (!staffName) {\n      try {\n        \/\/ \u8c03\u7528\u5458\u5de5\u4fe1\u606f\u67e5\u8be2\u63a5\u53e3\n        const retResult = await requestApi(\n          window.location.origin + \"\/xlx001-be\/xlxhr\/qry-staffinfo\",\n          {}\n        );\n        const retDatas = retResult.result || {};\n        if (retDatas.staffId) {\n          \/\/ \u89e6\u53d1\u53c2\u7167\u9009\u62e9\n          cb.utils.triggerReferBrowse(\n            viewModel.get(\"staff_name\"),\n            &#91;{ field: \"id\", op: 'eq', value1: retDatas.staffId }]\n          );\n        } else {\n          console.warn('\u672a\u83b7\u53d6\u5230\u6709\u6548\u7684\u5458\u5de5ID');\n        }\n      } catch (e) {\n        console.error('\u81ea\u52a8\u586b\u5145\u5458\u5de5\u4fe1\u606f\u5931\u8d25:', e);\n        \/\/ \u53ef\u6dfb\u52a0\u7528\u6237\u63d0\u793a\uff0c\u5982\uff1acb.utils.alert('\u5458\u5de5\u4fe1\u606f\u52a0\u8f7d\u5931\u8d25\uff0c\u8bf7\u624b\u52a8\u9009\u62e9');\n      }\n    }\n  }\n});\n\n\/\/ \u5458\u5de5\u59d3\u540d\u53d8\u5316\u4e8b\u4ef6\nviewModel.get(\"staff_name\") &amp;&amp; viewModel.get(\"staff_name\").on(\"afterValueChange\", async function (event) {\n  const staffId = event.value?.id; \/\/ \u53ef\u9009\u94fe\u907f\u514devent.value\u4e3aundefined\u65f6\u62a5\u9519\n  if (!staffId) return; \/\/ \u65e0\u5458\u5de5ID\u65f6\u4e0d\u6267\u884c\u540e\u7eed\u903b\u8f91\n\n  try {\n    \/\/ \u8c03\u7528\u5458\u5de5\u8be6\u60c5\u63a5\u53e3\n    const retResult = await requestApi(\n      window.location.origin + \"\/xlx001-be\/xlxhr\/qry-staff-detail-info\",\n      { staffId: staffId }\n    );\n    const { staffJobData = &#91;] } = retResult.result || {}; \/\/ \u89e3\u6784\u8d4b\u503c\u5e76\u9ed8\u8ba4\u7a7a\u6570\u7ec4\n    const firstJobData = staffJobData&#91;0] || {}; \/\/ \u907f\u514d\u8bbf\u95eeundefined&#91;0]\n\n    \/\/ \u586b\u5145\u90e8\u95e8\u4fe1\u606f\n    if (firstJobData.deptId) {\n      cb.utils.triggerReferBrowse(\n        viewModel.get(\"staffDept_name\"),\n        &#91;{ field: \"id\", op: 'eq', value1: firstJobData.deptId }]\n      );\n    }\n\n    \/\/ \u586b\u5145\u7ec4\u7ec7\u4fe1\u606f\n    if (firstJobData.orgId) {\n      cb.utils.triggerReferBrowse(\n        viewModel.get(\"staffOrganize_name\"),\n        &#91;{ field: \"id\", op: 'eq', value1: firstJobData.orgId }]\n      );\n    }\n\n    \/\/ \u586b\u5145\u804c\u4f4d\u4fe1\u606f\uff08\u4fee\u6b63postId\u4e3apsnclId\uff09\n    if (firstJobData.psnclId) {\n      cb.utils.triggerReferBrowse(\n        viewModel.get(\"staffPosition_name\"),\n        &#91;{ field: \"id\", op: 'eq', value1: firstJobData.psnclId }]\n      );\n    }\n  } catch (e) {\n    console.error('\u586b\u5145\u5458\u5de5\u5173\u8054\u4fe1\u606f\u5931\u8d25:', e);\n    \/\/ \u53ef\u6dfb\u52a0\u7528\u6237\u63d0\u793a\uff0c\u5982\uff1acb.utils.alert('\u5458\u5de5\u8be6\u60c5\u52a0\u8f7d\u5931\u8d25\uff0c\u8bf7\u624b\u52a8\u586b\u5199\u5173\u8054\u4fe1\u606f');\n  }\n});<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2089","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/posts\/2089","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/comments?post=2089"}],"version-history":[{"count":1,"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/posts\/2089\/revisions"}],"predecessor-version":[{"id":2098,"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/posts\/2089\/revisions\/2098"}],"wp:attachment":[{"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/media?parent=2089"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/categories?post=2089"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/tags?post=2089"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}