index.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. <template>
  2. <view class="setting-wrap">
  3. <div class="header">
  4. <div class="name">智能实验终端</div>
  5. <div class="activation-btn" @click="confirm">激活终端</div>
  6. </div>
  7. <view class="lab-input-wrap">
  8. <view class="input-col">
  9. <view class="title">服务器IP:</view>
  10. <view class="input-box">
  11. <input class="lab-input" v-model="ip" type="text" placeholder="请输入服务器IP" />
  12. </view>
  13. </view>
  14. <view class="input-col">
  15. <view class="title required">终端编号:</view>
  16. <view class="input-box">
  17. <input class="lab-input" v-model="no" type="text" placeholder="请输入终端编号" />
  18. </view>
  19. </view>
  20. <view class="input-col">
  21. <view class="title">终端租户码:</view>
  22. <view class="input-box">
  23. <input class="lab-input" v-model="tenant" type="text" placeholder="请输入终端租户码" />
  24. </view>
  25. </view>
  26. <view class="input-col">
  27. <view class="title">秘钥:</view>
  28. <view class="input-box">
  29. <input class="lab-input" v-model="token" type="text" placeholder="请输入秘钥" />
  30. </view>
  31. </view>
  32. <view class="input-col">
  33. <view class="title">微服务:</view>
  34. <view class="input-box">
  35. <input class="lab-input" v-model="service_path" type="text" placeholder="请输入微服务路径" />
  36. </view>
  37. </view>
  38. <view class="input-col">
  39. <view class="title">sdk:</view>
  40. <view class="input-box flex">
  41. <input class="lab-input" v-model="sdkKey" type="text" placeholder="请输入sdk"
  42. style="flex: 1;padding-right: 20px;" />
  43. <u-button type="primary" style="width: 120px;" @click="getSdk">获取SDK</u-button>
  44. </view>
  45. </view>
  46. <view class="input-col">
  47. <view class="title">logo:</view>
  48. <view class="input-box">
  49. <input class="lab-input" v-model="headerImg" type="text" placeholder="请输入sdk" />
  50. </view>
  51. </view>
  52. <view class="input-col">
  53. <view class="title">文件路径:</view>
  54. <view class="input-box">
  55. <input class="lab-input" v-model="filePath" type="text" placeholder="请输入文件路径" />
  56. </view>
  57. </view>
  58. </view>
  59. </view>
  60. </template>
  61. <script>
  62. import instApi from "../../api/inst";
  63. import to from "await-to-js";
  64. const module = uni.requireNativePlugin("leven-arcFace-ArcFaceModule");
  65. export default {
  66. data() {
  67. return {
  68. ip: "",
  69. no: "",
  70. tenant: "",
  71. token: "",
  72. service_path: "",
  73. sdkKey: "91RPJZf6Xz158bBuHHDmX2BoEHWCKYyL2gnMvbuCADKD",
  74. headerImg: "static/images/header.png",
  75. filePath: "",
  76. };
  77. },
  78. onMounted() {
  79. this.ip =
  80. uni.getStorageSync("labsop_ip") ||
  81. process.uniEnv.VUE_APP_MicroSrvProxy_API;
  82. this.no = uni.getStorageSync("labsop_no") || "";
  83. this.tenant =
  84. uni.getStorageSync("labsop_tenant") || process.uniEnv.VUE_APP_TENANT;
  85. this.token =
  86. uni.getStorageSync("labsop_android_token") ||
  87. process.uniEnv.VUE_APP_TOKEN;
  88. this.service_path = uni.getStorageSync("labsop_service_path") || "";
  89. this.sdkKey =
  90. uni.getStorageSync("labsop_sdkKey") ||
  91. "91RPJZf6Xz158bBuHHDmX2BoEHWCKYyL2gnMvbuCADKD";
  92. this.headerImg =
  93. uni.getStorageSync("labsop_headerImg") || "static/images/header.png";
  94. this.filePath = uni.getStorageSync("labsop_filePath") || "";
  95. },
  96. onShow() {
  97. this.ip =
  98. uni.getStorageSync("labsop_ip") ||
  99. process.uniEnv.VUE_APP_MicroSrvProxy_API;
  100. this.no = uni.getStorageSync("labsop_no") || "";
  101. this.tenant =
  102. uni.getStorageSync("labsop_tenant") || process.uniEnv.VUE_APP_TENANT;
  103. this.token =
  104. uni.getStorageSync("labsop_android_token") ||
  105. process.uniEnv.VUE_APP_TOKEN;
  106. this.service_path = uni.getStorageSync("labsop_service_path") || "";
  107. this.sdkKey =
  108. uni.getStorageSync("labsop_sdkKey") ||
  109. "91RPJZf6Xz158bBuHHDmX2BoEHWCKYyL2gnMvbuCADKD";
  110. this.headerImg =
  111. uni.getStorageSync("labsop_headerImg") || "static/images/header.png";
  112. this.filePath = uni.getStorageSync("labsop_filePath") || "";
  113. },
  114. onLoad() { },
  115. methods: {
  116. // 重新获取系统Sdk
  117. async getSdk() {
  118. const [err, res] = await to(instApi.getEntityByKey({ configKey: 'hongruanSdk' }))
  119. if (err) {
  120. uni.showToast({
  121. title: "获取SDK失败",
  122. icon: "none",
  123. duration: 1000,
  124. });
  125. return;
  126. }
  127. this.sdkKey = res.data.configValue|| ''
  128. },
  129. testSave() {
  130. // 测试用的方法
  131. uni.setStorageSync("labsop_ip", this.ip || "");
  132. uni.setStorageSync("labsop_no", "66400376");
  133. uni.setStorageSync("labsop_tenant", this.tenant || "");
  134. uni.setStorageSync("labsop_android_token", this.token || "");
  135. uni.setStorageSync("labsop_service_path", this.service_path || "");
  136. uni.setStorageSync(
  137. "labsop_sdkKey",
  138. this.sdkKey || "91RPJZf6Xz158bBuHHDmX2BoEHWCKYyL2gnMvbuCADKD"
  139. );
  140. uni.setStorageSync(
  141. "labsop_headerImg",
  142. "weed1/5,124d5a8af276"
  143. );
  144. uni.setStorageSync("labsop_filePath", this.filePath || "");
  145. },
  146. // 激活引擎
  147. confirm() {
  148. // this.testSave();
  149. // return;
  150. if (!this.no) {
  151. uni.showToast({
  152. title: "终端编号不能为空",
  153. icon: "none",
  154. duration: 1000,
  155. });
  156. return;
  157. }
  158. module.activeEngine(
  159. {
  160. appId: "9hEJzpvjHowhWTwrcAd47fSg42YRjx3RhvmpuHFAVLyy",
  161. sdkKey: this.sdkKey,
  162. },
  163. (res) => {
  164. console.log(res);
  165. if (res.code == 0 || res.code == 90114) {
  166. uni.showModal({
  167. title: "提示",
  168. content: "确认设置" + this.no + "为当前系统的终端编号?",
  169. success: (res) => {
  170. if (res.confirm) {
  171. this.clearFace();
  172. uni.setStorageSync("labsop_ip", this.ip || "");
  173. uni.setStorageSync("labsop_no", this.no || "");
  174. uni.setStorageSync("labsop_tenant", this.tenant || "");
  175. uni.setStorageSync(
  176. "labsop_android_token",
  177. this.token || ""
  178. );
  179. uni.setStorageSync(
  180. "labsop_service_path",
  181. this.service_path || ""
  182. );
  183. uni.setStorageSync(
  184. "labsop_sdkKey",
  185. this.sdkKey ||
  186. "91RPJZf6Xz158bBuHHDmX2BoEHWCKYyL2gnMvbuCADKD"
  187. );
  188. uni.setStorageSync(
  189. "labsop_headerImg",
  190. this.headerImg || "static/images/header.png"
  191. );
  192. uni.setStorageSync("labsop_filePath", this.filePath || "");
  193. uni.showToast({
  194. title: "保存成功",
  195. duration: 1000,
  196. });
  197. setTimeout(() => {
  198. plus.runtime.restart();
  199. }, 1000);
  200. }
  201. },
  202. });
  203. } else {
  204. uni.showToast({
  205. title: "激活失败,请重新确认激活",
  206. icon: "none",
  207. duration: 1000,
  208. });
  209. }
  210. }
  211. );
  212. },
  213. // 清空人脸库
  214. clearFace() {
  215. module.clearFace((res) => {
  216. console.log("清空人脸库结果", res);
  217. });
  218. },
  219. backHome() {
  220. uni.redirectTo({
  221. url: "/pages/home/index",
  222. });
  223. },
  224. },
  225. };
  226. </script>
  227. <style lang="scss" scoped>
  228. .setting-wrap {
  229. width: 100%;
  230. height: 100vh;
  231. background: #fff;
  232. .header {
  233. background: skyblue;
  234. width: 100%;
  235. height: 12.6vh;
  236. box-sizing: border-box;
  237. display: flex;
  238. .name {
  239. flex: 1;
  240. display: flex;
  241. align-items: center;
  242. justify-content: center;
  243. font-size: 1.6vw;
  244. color: #fff;
  245. }
  246. .activation-btn {
  247. font-size: 1.6vw;
  248. letter-spacing: 2px;
  249. color: #fff;
  250. width: 15vw;
  251. height: 100%;
  252. background: #395294;
  253. display: flex;
  254. align-items: center;
  255. justify-content: center;
  256. }
  257. }
  258. .lab-input-wrap {
  259. padding: 8vh 6vw 0 6vw;
  260. display: flex;
  261. flex-wrap: wrap;
  262. .input-col {
  263. width: 50%;
  264. display: flex;
  265. margin-bottom: 40px;
  266. padding-right: 40px;
  267. .title {
  268. width: 9vw;
  269. font-size: 1.4vw;
  270. margin-right: 20px;
  271. text-align: right;
  272. }
  273. .input-box {
  274. flex: 1;
  275. border-bottom: 1px solid #ccc;
  276. .lab-input {
  277. padding-left: 4px;
  278. padding-bottom: 10px;
  279. }
  280. }
  281. }
  282. }
  283. .flex {
  284. display: flex;
  285. }
  286. .required::before {
  287. margin-right: 4px;
  288. color: red;
  289. content: "*";
  290. font-size: 20px;
  291. }
  292. }
  293. </style>