PrinterConfiguration.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. <template>
  2. <Navbar title="设备管理" :is-go-back="false" />
  3. <main>
  4. <a-button @click="editPrinter(true)">添加打印机</a-button>
  5. <CommonTable
  6. id="printTable"
  7. :have-page="false"
  8. :y-scroll="yScroll"
  9. :columns="printerColumns"
  10. :data-source="printerDatas"
  11. >
  12. <template #bodyCell="{ record, column }">
  13. <template v-if="column.key === 'operation'">
  14. <span>
  15. <a @click="editPrinter(false, record)">编辑</a>
  16. <a-divider type="vertical" />
  17. <a @click="deletePrinter(record.id)">删除</a>
  18. </span>
  19. </template>
  20. </template>
  21. </CommonTable>
  22. <a-modal
  23. v-model:visible="editVisible"
  24. :title="editTitle"
  25. width="800px"
  26. ok-text="保存配置"
  27. cancel-text="取消"
  28. @ok="saveOrUpdateSetting"
  29. >
  30. <a-form :model="printerState">
  31. <a-row :gutter="24">
  32. <a-col :span="11">
  33. <a-form-item
  34. label="打印机名称"
  35. :label-col="{ span: 8 }"
  36. :wrapper-col="{ span: 16 }"
  37. >
  38. <a-select
  39. v-model:value="printerState.printerName"
  40. style="width: 220px"
  41. :options="printerNames"
  42. />
  43. </a-form-item>
  44. </a-col>
  45. <a-col :span="11">
  46. <a-form-item
  47. label="打印机类型"
  48. :label-col="{ span: 10 }"
  49. :wrapper-col="{ span: 16 }"
  50. >
  51. <a-select
  52. v-model:value="printerState.printerType"
  53. style="width: 220px"
  54. >
  55. <a-select-option value="GK888">GK888</a-select-option>
  56. <a-select-option value="Zebra">Zebra</a-select-option>
  57. <a-select-option value="TOSHIBA">TOSHIBA</a-select-option>
  58. <a-select-option value="蓝牙打印机">蓝牙打印机</a-select-option>
  59. </a-select>
  60. </a-form-item>
  61. </a-col>
  62. </a-row>
  63. <a-row :gutter="24">
  64. <a-col :span="11">
  65. <a-form-item
  66. label="旋转角度"
  67. :label-col="{ span: 8 }"
  68. :wrapper-col="{ span: 16 }"
  69. >
  70. <a-select v-model:value="printerState.rotateAngel">
  71. <a-select-option value="0">0</a-select-option>
  72. <a-select-option value="90">90</a-select-option>
  73. <a-select-option value="180">180</a-select-option>
  74. <a-select-option value="270">270</a-select-option>
  75. </a-select>
  76. </a-form-item>
  77. </a-col>
  78. <a-col :span="11">
  79. <a-form-item
  80. label="支持RFID功能"
  81. :label-col="{ span: 10 }"
  82. :wrapper-col="{ span: 16 }"
  83. >
  84. <a-checkbox v-model:checked="printerState.supportRfid" />
  85. <a-checkbox
  86. v-if="printerState.supportRfid"
  87. v-model:checked="printerState.enableWritePassword"
  88. style="margin-left: 40px"
  89. >
  90. 写入密码
  91. </a-checkbox>
  92. </a-form-item>
  93. </a-col>
  94. </a-row>
  95. <a-row v-if="printerState.enableWritePassword" :gutter="24">
  96. <a-col :span="11">
  97. <a-form-item
  98. label="访问密码"
  99. :label-col="{ span: 8 }"
  100. :wrapper-col="{ span: 16 }"
  101. >
  102. <a-input
  103. v-model:value="printerState.accessPassword"
  104. style="width: 220px"
  105. />
  106. </a-form-item>
  107. </a-col>
  108. <a-col :span="11">
  109. <a-form-item
  110. label="杀死密码"
  111. :label-col="{ span: 10 }"
  112. :wrapper-col="{ span: 16 }"
  113. >
  114. <a-input
  115. v-model:value="printerState.killPassword"
  116. style="width: 220px"
  117. />
  118. </a-form-item>
  119. </a-col>
  120. </a-row>
  121. <a-row :gutter="24">
  122. <a-col :span="11">
  123. <a-form-item
  124. label="打印深度"
  125. :label-col="{ span: 8 }"
  126. :wrapper-col="{ span: 16 }"
  127. >
  128. <a-input-number
  129. v-model:value="printerState.darkness"
  130. style="width: 220px"
  131. />
  132. </a-form-item>
  133. </a-col>
  134. <a-col :span="11">
  135. <a-form-item
  136. label="进纸方向偏移(mm)"
  137. :label-col="{ span: 10 }"
  138. :wrapper-col="{ span: 16 }"
  139. >
  140. <a-input-number
  141. v-model:value="printerState.offsetHeight"
  142. style="width: 220px"
  143. />
  144. </a-form-item>
  145. </a-col>
  146. </a-row>
  147. <a-row :gutter="24">
  148. <a-col :span="11">
  149. <a-form-item
  150. label="标签后退距离"
  151. :label-col="{ span: 8 }"
  152. :wrapper-col="{ span: 16 }"
  153. >
  154. <a-input-number
  155. v-model:value="printerState.backLength"
  156. style="width: 220px"
  157. />
  158. </a-form-item>
  159. </a-col>
  160. <a-col :span="11">
  161. <a-form-item
  162. label="水平方向偏移(mm)"
  163. :label-col="{ span: 10 }"
  164. :wrapper-col="{ span: 16 }"
  165. >
  166. <a-input-number
  167. v-model:value="printerState.offsetWidth"
  168. style="width: 220px"
  169. />
  170. </a-form-item>
  171. </a-col>
  172. </a-row>
  173. </a-form>
  174. </a-modal>
  175. </main>
  176. </template>
  177. <script setup>
  178. import Common from '../common/Common';
  179. import { message } from 'ant-design-vue';
  180. import { tableColumns } from './configData.js';
  181. import { ref, reactive, onMounted } from 'vue';
  182. import CommonTable from '../common/CommonTable.vue';
  183. import { getTableScroll } from '../common/tableScroll.js';
  184. import PrintUtil from '../api/printer/printerWebsocket.js';
  185. import {
  186. deleteById,
  187. saveOrUpdate,
  188. queryAllPrinters,
  189. } from '../api/printer/printerConfiguration.js';
  190. const yScroll = ref();
  191. const editTitle = ref('');
  192. const printerDatas = ref([]);
  193. const printerNames = ref([]);
  194. const editVisible = ref(false);
  195. const printerColumns = ref(tableColumns);
  196. const printerState = ref({
  197. printerName: '',
  198. printerType: undefined,
  199. supportRfid: false,
  200. enableWritePassword: false,
  201. accessPassword: '',
  202. killPassword: '',
  203. rotateAngel: 0,
  204. backLength: 0,
  205. offsetHeight: 0,
  206. offsetWidth: 0,
  207. darkness: 15,
  208. });
  209. const base = reactive({
  210. clientId: '',
  211. macAddress: '',
  212. });
  213. const createState = ref({});
  214. // 编辑打印机配置
  215. const editPrinter = (flag, record) => {
  216. editVisible.value = true;
  217. if (flag) {
  218. editTitle.value = '添加打印机';
  219. printerState.value = JSON.parse(JSON.stringify(createState.value));
  220. } else {
  221. editTitle.value = '编辑打印机';
  222. printerState.value = record;
  223. }
  224. getPrinterNames();
  225. };
  226. onMounted(() => {
  227. base.clientId = JSON.parse(localStorage.getItem('#LoginInfo')).loginClientId;
  228. createState.value = JSON.parse(JSON.stringify(printerState.value));
  229. yScroll.value = getTableScroll({ id: 'printTable' });
  230. getMacAddress();
  231. queryPrinters();
  232. });
  233. // 获取mac地址
  234. const getMacAddress = () => {
  235. PrintUtil.getMacAddress().then(
  236. success => {
  237. base.macAddress = success.data;
  238. },
  239. err => {
  240. console.log(err);
  241. },
  242. );
  243. };
  244. // 获取所有打印机名称
  245. const getPrinterNames = () => {
  246. PrintUtil.getPrinters().then(
  247. success => {
  248. if (success.errorCode === 0) {
  249. if (success.data && success.data.length > 0) {
  250. printerNames.value = success.data.map(item => {
  251. return (item = {
  252. value: item,
  253. label: item,
  254. });
  255. });
  256. }
  257. } else {
  258. message.warning(success.errorMessage);
  259. }
  260. },
  261. error => {
  262. console.log(error);
  263. },
  264. );
  265. };
  266. // 获取所有打印配置
  267. const queryPrinters = () => {
  268. queryAllPrinters().then(
  269. success => {
  270. if (success.errorCode === 0) {
  271. if (success.datas && success.datas.length > 0) {
  272. printerDatas.value = success.datas;
  273. }
  274. } else {
  275. message.warning(success.errorMessage);
  276. }
  277. },
  278. err => {
  279. Common.processException(err);
  280. },
  281. );
  282. };
  283. //新增或更新打印配置
  284. const saveOrUpdateSetting = () => {
  285. const printerInfo = JSON.parse(JSON.stringify(printerState.value));
  286. const params = { ...printerInfo, ...base };
  287. saveOrUpdate(params).then(
  288. success => {
  289. if (success.errorCode === 0) {
  290. if (editTitle.value === '添加打印机') {
  291. message.success('添加打印机配置成功。');
  292. } else {
  293. message.success('更新打印机配置成功。');
  294. }
  295. editVisible.value = false;
  296. queryPrinters();
  297. } else {
  298. message.warning(success.errorMessage);
  299. }
  300. },
  301. err => {
  302. Common.processException(err);
  303. },
  304. );
  305. };
  306. // 删除打印机配置
  307. const deletePrinter = id => {
  308. deleteById(id).then(
  309. success => {
  310. if (success.errorCode === 0) {
  311. message.success('删除打印机配置成功。');
  312. queryPrinters();
  313. } else {
  314. message.warning(success.errorMessage);
  315. }
  316. },
  317. err => {
  318. Common.processException(err);
  319. },
  320. );
  321. };
  322. </script>
  323. <style scoped>
  324. </style>